Skip to content
Advertisement

psql – Mac trying to connect postgreSQL in Ubuntu system installed in a virtual machine in remote server

Apologize in front, maybe the situation here is a bit complicated. I searched everywhere online but couldn’t find a perfect solution, plus I have tried almost all the solutions mentioned in other posts.

  • Situation:

So I have a postgreSQL database installed in a Ubuntu system. The system is actually a virtual machine on the VMware workstation 12, which is installed on Windows 7 professional. Now I am trying to remotely access the postgreSQL database through my MacBook pro 2013.

In the Mac terminal, the command line I tried is:

psql -U postgres -h xxx.xxx.xxx.xx

“xxx.xxx.xxx.xx” represents the IP address of the Windows 7 machine. The result is a failure:

psql: could not connect to server: Operation timed out Is the server running on host “169.254.121.2” and accepting TCP/IP connections on port 5432?

  • What I have done:

    1. Edited the pg_hba.conf file to include

host all all 0.0.0.0/0 md5

  1. Edited the postgresql.conf to include

listen_addresses=’*’

  1. Restarted postgres service.
  2. Disabled firewall on the host.
  3. I checked by running the psql command locally and it worked. Also, on the same VMware I have other Ubuntu systems. They are all fine to connect and access the data in this Ubuntu system.
  4. Running Nmap, the output is

PORT STATE SERVICE

5432/TCP open postgresql

  • What’s next? Anything else I can try? Any advice is highly appreciated and please let me know if anything above is ambiguous. I will clarify for better diagnosis. Thank you all!

Advertisement

Answer

Somehow managed to get it working..

So when I ran “Nmap” on the other Ubuntu system towards this one, it does shows

PORT STATE SERVICE

5432/TCP open postgresql

However, when I ran “Nmap” on my Mac, it’s a different port, 3389, which is mainly used for Windows remote desktop. So what I did was to check the network configuration of this Ubuntu virtual machine from “bridged” to “NAT” and did a port forwarding to 5432. It is working fine now..

I read in some places saying that VMware favors bridged whereas VirtualBox favors NAT+port forwarding. I am quite confused as it is certain not the case in my situation. Maybe I am wrong.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement