Are you stuck at database connection issues? Don't worry, we got your back.

Database connections are common and one need not worry much about them. Usually, users using Postgres faces 2 common issues when making a connection via Kloudio.

1). ECONNREFUSED - This happens when a database is configured over intranet and is unable to accept external connections. A simple solution is to open it up to accept external connections and modify the postgresql hosts file to allow specific external ip address. This is a two step solution
👉 Check and configure postgresql.conf file.
👉 Check and configure pg_hba.conf file.

 By default PostgreSQL is configured to be bound to “localhost”.

$ netstat -nlt
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN
tcp        0      0 127.0.0.1:11211         0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN
tcp        0      0 127.0.0.1:5432          0.0.0.0:*               LISTEN
tcp        0      0 127.0.0.1:3737          0.0.0.0:*               LISTEN
tcp6       0      0 :::22                   :::*                    LISTEN

As we can see above port 5432 is bound to 127.0.0.1. It means any attempt to connect to the postgresql server from outside the machine will be refused. We can try hitting the port 5432 by using telnet.

$ telnet x.x.x.x 5432
Trying x.x.x.x...
telnet: connect to address x.x.x.x: Connection refused
telnet: Unable to connect to remote host

Configuring postgresql.conf

In order to fix this issue we need to find postgresql.conf. In different systems it is located at different place. I usually search for it.

$ sudo find \ -name "postgresql.conf"
/var/lib/pgsql/9.4/data/postgresql.conf

Open postgresql.conf file and replace line

listen_addresses = 'localhost'

with

listen_addresses = '*'

Now restart postgresql server.

$ sudo systemctl restart postgresql.service
$ netstat -nlt
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 127.0.0.1:11211         0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:5432            0.0.0.0:*               LISTEN
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN
tcp        0      0 127.0.0.1:2812          0.0.0.0:*               LISTEN
tcp6       0      0 ::1:11211               :::*                    LISTEN
tcp6       0      0 :::22                   :::*                    LISTEN
tcp6       0      0 :::5432                 :::*                    LISTEN
tcp6       0      0 ::1:25                  :::*                    LISTEN

Here we can see that “Local Address” for port 5432 has changed to 0.0.0.0.

Configuring pg_hba.conf

Let’s try to connect to remote postgresql server using “psql”.

$ psql -h x.x.x.x -U postgres
psql: could not connect to server: Connection refused
Is the server running on host "x.x.x.x" and accepting
TCP/IP connections on port 5432?

In order to fix it, open pg_hba.conf and add following entry at the very end.

host    all             all              52.34.31.72/0                       md5
host    all             all              52.38.227.76/0                       md5

Restart postgresql server.

$ sudo systemctl restart postgresql.service
$ psql -h x.x.x.x -U postgres
Password for user postgres:
psql (9.4.1, server 9.4.5)
Type "help" for help.

postgres=# \l


You should be able to see list of databases.

Now we are able to connect to postgresql server remotely.

Go ahead, and try to create connection in from Kloudio.

2) ECONNTIMEDOUT -Cannot connect to the database. Please make sure you have whitelisted the Kloudio IP addresses.

This issue occurs if Kloudio cannot connect to your DB because of firewall. 

Steps to fix:

Your IT admin has to make some changes to firewall. 

  1. Open database port in the firewall for connecting from remote server.
  2. Whitelist Kloudio IP Addresses (52.34.31.72 and 52.38.227.76) in your database firewall so that Kloudio can connect to your database.
Did this answer your question?