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>
Question posted in Amazon Web Sevices
The official Amazon Web Services documentation can be found here.
The official Amazon Web Services documentation can be found here.
2
Answers
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'
tolisten_addresses = '*'
. then add the follwing line to the/etc/postgresql/"*"/main//pg_hba.conf
: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.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.