Tag: cpanel

PostgreSQL psql: could not connect to server: Connection refused

First thing to be checked is to see if postgresql service is running on the server.
# /etc/init.d/postgresql status

If it is running and you get the error, you need to add enable TCP/IP support. By default, the PostgreSQL server only allows connections to the database from the local machine or localhost. This is a security feature of PostgreSQL.

To allow remote IP addresses/servers to access postgresql server we need configure it accordingly. For this we need to edit the config file /var/lib/pgsql/data/pg_hba.conf.

# vi /var/lib/pgsql/data/pg_hba.conf

You will find

host    all         all   md5

Now add a new line as below

host    all         all      trust

where is the IP address from which you are trying to access the postgresql server.

Save and close the file.

Also you may need to enable TCP/IP communication, which can be done in the configuration file /var/lib/pgsql/data/postgresql.conf. Ensure that the setting tcpip_socket is set to true.

# vi /var/lib/pgsql/data/postgresql.conf

tcpip_socket = true

Save and close the file.

Now restart PostgreSQL server, so that the config changes are updated.

# /etc/init.d/postgresql restart

This will open default port 5432.

You may test the connectivity using 3rd party application like pgadmin or using psql client. The psql command from would be as follows.


Notes : This documentation is with regard to Centos. However same holds good for debian and also ubuntu. The configuration files paths on debian/ubuntu is as below



where 7.4 is the postgresql version installed on the server.

Secure tmp

On a cpanel server you could secure tmp using the script /scripts/securetmp

However, most of the servers would find the tmp space inadequate. So you can increase the tmp size using either the manual method or again using the securetmp script. Below are the steps to accomplish the same.

We have 3 scenarios here

1 ) Running securetmp for the first time.

2 ) Need to increase tmp size but have already run securetmp

  • Increase space again using securetmp script
  • Manually Increase the space.

Let us see how this can be done.

1 ) Running securetmp for the first time.

As of now the cpanel script /scripts/securetmp create a file of size 512 MB and /tmp is mounted on this file. But 512 MB would be inadequate for a busy server, so first we shall modify the script to create the tmp file whose size is more than 512 MB. Let us assume that our server needs 1 GB of tmp space.

The script uses kilobytes in it, so let us convert 1 GB to KB

1 gigabyte = 1 048 576 kilobytes

Now let us make the change in the securetmp script

# replace “512000” “1048576”  −− /scripts/securetmp

Now we can run the script

# /scripts/securetmp

And answer few questions it asks before it setups the new tmp partition.