skip to Main Content

I have deployed PostgreSQL in an AWS ec2 and it is accessible within my ec2. Now I want my Postgresql to be accessed outside the ec2.
this is the command which I use to login PostgreSQL server: psql -h <host> -d <dbname> -U <username> -p <PostgreSQL_port>

2

Answers


  1. Chosen as BEST ANSWER

    you have a change in your command psql -h -d -U -p <PostgreSQL_port>

    here use server's public IP as your instead of localhost. Edit /etc/postgresql/"*"/main/postgresql.conf : find the line, #listen_addresses = 'localhost' to listen_addresses = '*' . then add the follwing line to the /etc/postgresql/"*"/main//pg_hba.conf:

    host  all  all 0.0.0.0/0 md5
    

    Then restart your postgresql using sudo service restart postgresql command. Remember to grant access to the port of postgreSQL(5432) in security group of ec2.


  2. Besides configuring your firewall to allow access to the port you also need to configure postgres to allow logging in from other hosts. This is done by adding entries to the hba-conf file.

    You also need to make sure you configure postgres to actually listen on the correct network interface(s) using the listen_addresses setting.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search