1

I am trying to connect to a VM ubuntu from my local computer. On the VM I have created a postgresql database. Then I followed all steps that I could find on several tutorial when it comes to allow access for remote connexion to the db:

  • add host all all 0.0.0.0/0 trust to the pg_hba.conf file
  • add listen_addresses = '*' to the postgresql.conf file
  • remove the firewall by executing sudo ufw allow 5432/tcp
  • restart postresql by executing sudo systemctl restart postgresql

By using the command psql and then \c gives You are now connected to database "postgres" as user "postgres". I then create a password by executing ALTER USER postgres WITH PASSWORD 'password';

Then I use postico to connect locally. I want to connect with this same default superuser postgres for testing. I use the VM ip address as host, db name is postgres user postgres, password is password and port 5432 as mentioned above.

After trying to connect for a while with the message opening connection to server, the result is:

could not connect to server: Operation timed out
    Is the server running on host "***.**.**.***" and accepting
    TCP/IP connections on port 5432?

Any help please? I did all steps I could find on many tutorials but still failing to connect.

delalma
  • 838
  • 3
  • 12
  • 24
  • From the virtual machine, can you connect with psql if you specify `-h 127.0.0.1`? How about using the real IP address rather than 127.0.0.1? – jjanes Dec 12 '20 at 08:58
  • Where are the VM and the machine you trying to connect from in relation to each other? What is OS and version of connecting machine? I don't understand this 'Then I use postico to connect locally. ', when you also say 'I use the VM ip address ...`. – Adrian Klaver Dec 12 '20 at 14:35
  • @AdrianKlaver there are my local computer mac OS and a remote Ubuntu virtual machine. I am trying to connect form my local computer to the remote machine where the database is stored.. – delalma Dec 13 '20 at 02:52
  • @jjanes Yes I can connect with the command `psql -h 127.0.0.1` – delalma Dec 13 '20 at 02:53
  • So the firewall you created a rule for was on the remote Ubuntu machine, correct? Where is this Ubuntu machine running, AWS, Azure, Linode, somewhere else? To do `psql -h 127.0.0.1` on the virtual machine you ssh into it? To me it looks like there is another firewall between your Mac and the VM. – Adrian Klaver Dec 13 '20 at 20:13

0 Answers0