0

I have an EC2 instance of timescaledb running on AWS. For security purposes, my team members and I are using OpenVPN so that we have access to it and the same IP address has been defined in the inbound rules of Security group of the EC2 instance

Type         Protocol   Port range    source
Postgreqsl      TCP        5432        <my vpn ip address>
Postgreqsl      TCP        5432       172.31.32.0/20
SSH             TCP         22         <my vpn ip address>

and there are no outbound rules.

Now, I enter into the VPN and launch the instance and do

sudo su postgresql followed by

psql -h ec2-xx-xxx-xxx-xxx.eu-central-1.compute.amazonaws.com -d mydb -U myuser

I get the following error:

psql: could not connect to server: Connection refused Is the server running on host "ec2-xx-xxx-xxx-xxx.eu-central-1.compute.amazonaws.com" (172.31.40.110) and accepting TCP/IP connections on port 5432?

I am checking the postgresql.conf file and it has the following:

# CONNECTIONS AND AUTHENTICATION
#------------------------------------------------------------------------------

# - Connection Settings -

listen_addresses = '*'          # what IP address(es) to listen on;
                                        # comma-separated list of addresses;
                                        # defaults to 'localhost'; use '*' for all
                                        # (change requires restart)
port = 5432                             # (change requires restart)
max_connections = 100                   # (change requires restart)
#superuser_reserved_connections = 3     # (change requires restart)
unix_socket_directories = '/var/run/postgresql' # comma-separated list of directories
                                        # (change requires restart)
#unix_socket_group = ''                 # (change requires restart)
#unix_socket_permissions = 0777         # begin with 0 to use octal notation
                                        # (change requires restart)
#bonjour = off                          # advertise server via Bonjour
                                        # (change requires restart)
#bonjour_name = ''                      # defaults to the computer name
                                        # (change requires restart)

and the pg_hba.conf has

# Database administrative login by Unix domain socket
local   all             postgres                                peer

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     peer
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     peer
host    replication     all             127.0.0.1/32            md5
host    replication     all             ::1/128                 md5
host    all             all             0.0.0.0/0               md5 #ipv4 range
host    all             all             ::0/0                   md5 #ipv6 range
host    all             all             all                     md5 #all ip

Can anyone please tell me what is the mistake i am commiting here and if i am missing something?

  • What does "my vpn ip address" mean? Is it the address of the VPN server, or the address of your machine on the VPN subnet? "I enter into the VPN" would also benefit from an explanation. – mustaccio May 14 at 21:16
  • If it was pg_hba problem. Error message would be something like this. no pg_hba.conf entry for host ... – AG. May 15 at 2:02
  • @mustaccio It's the IP address of the machine when the VPN is turned on – reinhardt May 15 at 5:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.