PostgreSQL Connection Refused or Timeout Expired – ODK Aggregate and Amazon Ec2 instance
In the tutorial we will learn how to fix the PostgreSQL client’s access and connectivity related issues in Amazon AWS ec2 Ubuntu VM. This will also help if you have installed ODK Aggregate on ec2 instance. We will also cover some access related issues of ODK Aggregate if PstgreSQL is used as database.
Table of Contents
Technologies / platforms used in this tutorial
Window 11
Amazon aws
ec2 instance
pgAdmin
DBeaver
PuTTY
Do you have the followings questions, issues, problems, errors, etc. in mind ?
Cannot connect to PostgreSQL from client
Cannot connect to PostgreSQL using PGAdmin (a web-based GUI tool for PostgreSQL )
Cannot connect to PostgreSQL using DBeaver ( a SQL client software application )
PostgreSQL Connection refused
PostgreSQL Connection timeout expired
PostgreSQL Connection to server failed
Connection to server at “3.15.*.* “, port 5432 failed: Connection refused (0x0000274D/10061) Is the server running on that host and accepting TCP/IP connections?
PostgreSQL connection refused port 5432 windows
PostgreSQL connection refused localhost
In ODK Aggregate connection refused
In ODK Aggregate connection refused with PostgreSQL database
OR check the following screenshots of errors
1. Connect to your VM
(a) I am using PuTTY to connect to the ec2 machine. You can use any method of your choice to connect to ec2 vm.
(b) Once successfully connected your screen will look like the following. Enter the user name, password and press enter (enter ubuntu if using ubuntu machine).
(c) After successful login your screen will look like below
(d) Now go to the desire path (/etc/postgresql/10/main/ ) to perform certain actions. To go to this path ” /etc/postgresql/10/main/ ” just type the following command and press enter as shown in the following image.
cd /etc/postgresql/10/main/
(e) Now we are in the location where postgresql.conf file and pg_hba.conf file exists and we want to edit these two files
Type the following command and press enter key to open the postgresql.conf file to edit. Refer the following image
sudo vim postgresql.conf
Once the postgresql.conf is opened (as shown in the following image) just press ” i ” from keyboard to activate the insert mode.
Search for the ” listen_addresses = ‘localhost’ ” and replace it with listen_addresses = ‘*’
Press Esc key
Type :wq and press enter to save and exit
(f) Type the following command and press enter key to open the pg_hba.conf file to edit
Once the pg_hba.conf is opened (as shown in the following image) just press ” i ” from keyboard to activate the insert mode.
Enter the following line (host all all 0.0.0.0/0 md5) below the line #Database administrative login by Unix domain socket as shown in the following image.
Add this line : host all all 0.0.0.0/0 md5
Press Esc key
Type :wq and press enter to save and exit
(g) Enter the following command to restart the PostgreSQL services
sudo service postgresql restart
(h) Check and add Inbound Rules under the security group of the VM. This setting is just for testing purpose please use the setting as per your requirement.
Now test and check if you are able to connect with the server or db from client.
Leave a Reply