Bobcares

Fix PostgreSQL connection refused easily

by | Jun 9, 2020

An incorrect entry in the configuration file or firewall restriction generally triggers PostgreSQL connection refused error.

As a part of our PostgreSQL Management Services, we help webmasters and web hosts resolve PostgreSQL such as this every day.

postgresql connection refused

Today let’s discuss the top reasons for connection refused error in PostgreSQL and how to resolve the error.

 

What triggers PostgreSQL connection refused error?

PostgreSQL is a highly extensible and handy database management system. And thus it is one of the popular database systems.

But many times, when users try to connect to psql it ends up in connection errors. psql is the interactive terminal-based program, that enables PostgreSQL queries.

A typical error message looks like

Error: psql: could not connect to server: Connection refused Is the server running on host “xxx.xxx.xxx.xxx” and accepting TCP/IP connections on port 5432?

When the PostgreSQL’s server daemon is not running in the server, it can trigger connection refused error. At the same time, several other reasons can also trigger this error.

Let’s discuss a few reasons why the psql service fails. We will also discuss how our Support Engineers fix this error.

 

PostgreSQL service status

First parameter to cross-check during a psql connection refused error is the status of the PostgreSQL service.

We can confirm this by cross-checking if a Postgres process in running in the server. In a Linux like environment, we can use

ps -ef | grep postgres
service postgresql status

If the service is not running in the server, then we restart it using the command.

service postgresql restart

At times, this failure could be a result of a corrupted Postgresql service. A reinstall of the service with the apt-get install or yum install would be required to fix the issue.

 

Enable TCP/IP connections

If the error is not related to the failed status of the service, it is more likely to be related to TCP/IP connections disabled in the Postgresql configuration file.

To correct this, we need to edit posgresql.conf file. The file location in Ubuntu and Centos is :

In Ubuntu: vi /etc/postgresql/9.5/main/posgresql.conf

in CentOS 7: vi /usr/pgsql-10/share/postgresql.conf

 

The listen_address parameter in the configuration file determines the restrictions on TCP/IP connections. To allow TCP/IP connections, from all IP addresses it should be set to 0.0.0.0.  Alternatively, to allow connections to the specific IP address of the server, listen_address parameter need to be edited with only those IP addresses.

If this configuration is left blank or set to localhost, PostgreSQL will not allow external TCP/IP connections.

Finally, we restart the service to save the changes.

 

Allow remote host

If the users are not able to connect to psql from a remote IP, then also we get the same error.

In this case, the Support Team edits the postgresql.conf file and allow the IP from which the customer is trying to access.

Finally, we restart the service to save the changes.

 

Firewall restrictions

At times, the restrictions placed by the server firewall can also trigger connection refused error.

If the psql port 5432 is not open for connection or if there is any restriction on the IP address from which the TCP/IP connection occurs, it may trigger connection refused error.

Our Support engineers cross-check the firewall for any restrictions and then remove them to fix the issue.

[Still, having trouble connecting PostgreSQL? – We will fix it for you.]

 

Conclusion

In short, several reasons can trigger the PostgreSQL connection refused error. This includes corrupted Postgresql service, firewall restrictions, incorrect entries in the configuration file etc. We saw the top 4 reasons for this error and how our Support Engineers fix them.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF