You have to edit postgresql.conf file and change the listen_addresses line.

This file you can find in the /etc/postgresql/9.3/main directory.

Default Ubuntu config have allowed only localhost (or 127.0.0.1) interface, which is sufficient for using, when every PostgreSQL client work on the same computer, as PostgreSQL server. If you want connect PostgreSQL server from other computers, you have change this config line in this way:

listen_addresses = '*'

Then you have edit pg_hba.conf file, too. In this file you have set, from which computers you can connect to this server and what method of authentication you can use. Usually you will need similar line:

host    all         all         192.168.1.0/24        md5

Please, read comments in this file...

EDIT:

After the editing postgresql.conf and pg_hba.conf you have to restart postgresql server: sudo service postgresql restart

EDIT2: Highlited configuration files.

Answer from Jan Marek on Stack Overflow
🌐
Pinggy
pinggy.io › know_your_port › localhost_5432
localhost:5432 - PostgreSQL Database Port Guide - Pinggy
March 7, 2026 - Localhost:5432 is the official default port for PostgreSQL, the world’s most advanced open-source relational database. “Localhost” refers to your own computer (typically mapped to IP address 127.0.0.1), and “5432” is the port number ...
🌐
PostgreSQL
postgresql.org › docs › 9.2 › ecpg-sql-connect.html
PostgreSQL: Documentation: 9.2: CONNECT
November 9, 2017 - int main(void) { EXEC SQL BEGIN DECLARE SECTION; char *dbname = "testdb"; /* database name */ char *user = "testuser"; /* connection user name */ char *connection = "tcp:postgresql://localhost:5432/testdb"; /* connection string */ char ver[256]; /* buffer to store the version string */ EXEC SQL END DECLARE SECTION; ECPGdebug(1, stderr); EXEC SQL CONNECT TO :dbname USER :user; EXEC SQL SELECT version() INTO :ver; EXEC SQL DISCONNECT; printf("version: %s\n", ver); EXEC SQL CONNECT TO :connection USER :user; EXEC SQL SELECT version() INTO :ver; EXEC SQL DISCONNECT; printf("version: %s\n", ver); return 0; } CONNECT is specified in the SQL standard, but the format of the connection parameters is implementation-specific.
🌐
PostgreSQL
postgresql.org › docs › current › runtime-config-connection.html
PostgreSQL: Documentation: 18: 19.3. Connections and Authentication
May 14, 2026 - While client authentication (Chapter ... interfaces. This parameter can only be set at server start. ... The TCP port the server listens on; 5432 by default....
Top answer
1 of 16
105

This issue comes from installing the postgres package without a version number. Although postgres will be installed and it will be the correct version, the script to setup the cluster will not run correctly; it's a packaging issue.

If you're comfortable with postgres there is a script you can run to create this cluster and get postgres running. However, there's an easier way.

First purge the old postgres install, which will remove everything of the old installation, including databases, so back up your databases first.. The issue currently lies with 9.1 so I will assume that's what you have installed

sudo apt-get remove --purge postgresql-9.1

Now simply reinstall

sudo apt-get install postgresql-9.1

Note the package name with the version number. HTH.

2 of 16
38

The error message refers to a Unix-domain socket, so you need to tweak your netstat invocation to not exclude them. So try it without the option -t:

netstat -nlp | grep 5432

I would guess that the server is actually listening on the socket /tmp/.s.PGSQL.5432 rather than the /var/run/postgresql/.s.PGSQL.5432 that your client is attempting to connect to. This is a typical problem when using hand-compiled or third-party PostgreSQL packages on Debian or Ubuntu, because the source default for the Unix-domain socket directory is /tmp but the Debian packaging changes it to /var/run/postgresql.

Possible workarounds:

  • Use the clients supplied by your third-party package (call /opt/djangostack-1.3-0/postgresql/bin/psql). Possibly uninstall the Ubuntu-supplied packages altogether (might be difficult because of other reverse dependencies).
  • Fix the socket directory of the third-party package to be compatible with Debian/Ubuntu.
  • Use -H localhost to connect via TCP/IP instead.
  • Use -h /tmp or equivalent PGHOST setting to point to the right directory.
  • Don't use third-party packages.
🌐
CBT Nuggets
cbtnuggets.com › common-ports › what-is-port-5432
What is Port 5432?
October 11, 2024 - This is because TCP, unlike User Datagram Protocol (UDP), establishes the kind of reliable connections necessary for database applications. PostgreSQL uses port 5432 to facilitate connections between PostgreSQL clients and servers.
🌐
Project-open
project-open.com › en › howto-postgresql-port-secure-remote-access
HowTo Safely Open a PostgreSQL Port for Remote Access?
#------------------------------------------------------------------------------ # CONNECTIONS AND AUTHENTICATION #------------------------------------------------------------------------------ # - Connection Settings - listen_addresses = '0.0.0.0' # 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) After that we need to restart PG to activate the changes. On recent Linux system you have to enter as user root: ... On Windows you can use Control Panel -> Administrative Tools -> Services and restart the PostgreSQL service.
Find elsewhere
🌐
Localhosts
localhosts.info › 5432
localhost:5432 - PostgreSQL Database Port
Port 5432 is the default PostgreSQL database server port. Connect to PostgreSQL, fix connection refused errors, configure pg_hba.conf, and manage Postgres databases.
🌐
DEV Community
dev.to › lightningdev123 › localhost5432-your-gateway-to-postgresql-ehb
localhost:5432 - Your Gateway to PostgreSQL - DEV Community
August 11, 2025 - Localhost → This is just your own computer, usually mapped to the IP address 127.0.0.1. 5432 → This is the default port number where PostgreSQL listens for incoming connections.
🌐
PostgreSQL
postgresql.org › message-id › CALyyT7TKt8kgBU2qOhLFvAS11YNbrSq=Vsgj-02hBa+0KNQ88g@mail.gmail.com
PostgreSQL: Re: cant connect to localhost:5432 (but unix socket ok)
February 4, 2021 - > > I could have done something ... I am not fully aware of. > > There are couple of potential issues: > 1. it might listen on different port than 5432....
🌐
Hacker News
news.ycombinator.com › item
>By default, PostgreSQL listens on a TCP port 5432. This post seems to outright ... | Hacker News
April 3, 2021 - This post seems to outright state that by default postgres is listening to everyone via TCP for connection · Unless you edit pg_ident.conf, your postgres install will not listen for connections outside of on localhost. So, while it's correct to say that it listens to TCP port 5432, there is ...
🌐
PortChecker
check-port.com › home › port info › port 5432
Port 5432 — PostgreSQL: What It Is, Uses & Security Guide
Port 5432 is the default TCP port for PostgreSQL. It is used by servers and applications that need to accept incoming connections for this service.
🌐
Stream Security
stream.security › rules › ensure-there-is-no-unrestricted-inbound-access-to-tcp-port-5432-postgresql
Security & Compliance | Ensure there is no unrestricted inbound access to TCP port 5432 (PostgreSQL)
TCP port 5432 is the default port used by PostgreSQL, an open source relational database management system. It is used for client-server communication and allows clients to connect to the PostgreSQL server.Ensuring that there is no unrestricted inbound access to TCP port 5432 is important to ...
🌐
Ask Ubuntu
askubuntu.com › questions › 1498234 › psql-connection-to-server-at-localhost-127-0-0-1-port-5432-failed-connect
postgresql - psql: connection to server at "localhost" (127.0.0.1), port 5432 failed: Connection refused - Ask Ubuntu
December 27, 2023 - I checked a lot on the Internet to fix the problem but couldn't do anything. First of all, I changed my configuration based on here. listen_addresses = '*' port= 5432 data_directory = '/var/lib/
🌐
Broadcom
knowledge.broadcom.com › external › article › 264811 › postgresql-does-not-accept-tcpip-connect.html
PostgreSQL does not accept TCP/IP connections.
June 3, 2026 - could not connect to server: Connection refused (0x0000274D/10061) Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432? ... Configuration. By default, PostgreSQL does not allow remote connections.
🌐
Oracle DBA Training
learnomate.org › home › postgresql › psql: could not connect to server: connection refused
7 Proven Fixes for PostgreSQL Connection Refused Error (Quick Solutions)
September 11, 2025 - One of the most frustrating issues for DBAs and developers is the PostgreSQL connection refused error. The full message usually looks like this: psql: could not connect to server: Connection refused Is the server running on host "localhost" and accepting TCP/IP connections on port 5432?
🌐
PostgreSQL
postgresql.org › docs › 9.6 › ssh-tunnels.html
PostgreSQL: Documentation: 9.6: Secure TCP/IP Connections with SSH Tunnels
August 12, 2021 - The name or IP address after this is the remote bind address you are connecting to, i.e., localhost, which is the default. The second number, 5432, is the remote end of the tunnel, e.g., the port number your database server is using.