umbe1987
umbe1987

Reputation: 3588

Amazon EC2 and PostgreSQL: cannot connect due to time out error

I think I followed any possible guide before asking here.

I am trying to remotely connect to a PostgreSQL db installed on a EC2 Linux instance (Ubuntu server 18.04, free tier if it matters).

Here are all the steps I did before hitting a wall and begging for help.

  1. I connected to my instance via SSH
  2. I downloaded and installed postgres following this docs
  3. I created a new used (umberto)
  4. I created a new DB (wondermap)
  5. I created a new OS user with the same name as in step 3 (umberto)
  6. I connected to my new db with my new user from the server and everything woked fine
  7. I edited /etc/postgresql/10/main/pg_hba.conf adding these lines:

    host all all 0.0.0.0/0 md5

    host all all ::/0 md5

  8. I edited /etc/postgresql/10/main/postgresql.conf changing #listen_addresses = 'localhost' into listen_addresses = '*'

  9. i restarted the postgres server with sudo service postgresql restart

  10. I added a new Inbound rule in the instance security group like so:

    TCP port:5432 source:0.0.0.0/0, ::/0

After all, I am trying to connect from my local mahine (either using pgadmin3 or psql) but I still receive a timeout error (host is hidden):

psql -h <PUBLIC-IP-OF-MY-INSTANCE> -U umberto -d wondermap

or even

psql -h <PUBLIC-IP-OF-MY-INSTANCE> -U postgres

psql: could not connect to server: Connection timed out
    Is the server running on host "<PUBLIC-IP-OF-MY-INSTANCE>" and accepting

Doing SELECT version(); shows:

PostgreSQL 10.7 (Ubuntu 10.7-0ubuntu0.18.04.1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0, 64-bit

What could be the problem?

Upvotes: 1

Views: 1570

Answers (1)

umbe1987
umbe1987

Reputation: 3588

Apparently, I stil had to unblock postgres port on server's firewall.

  1. sudo ufw allow 5432/tcp

That did the trick!

Upvotes: 4

Related Questions