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
🌐
Reddit
reddit.com › r/postgresql › connection to server at "127.0.0.1", port 5432 failed
r/PostgreSQL on Reddit: connection to server at "127.0.0.1", port 5432 failed
February 6, 2024 -

I face an error since today. Most likely as a reaction to an unexpected shut down last night (local dev.). I did not change anything regarding my setup (django <--> postgresql). Already checked out if a firewall blocked the path over night, but that seems not to be the case.

When I try to runserver:

django.db.utils.OperationalError: connection failed: could not receive data from server: Socket is not connected 

When I try to login at pgadmin:

connection to server at "127.0.0.1", port 5432 failed: Connection refused (0x0000274D/10061) Is the server running on that host and accepting TCP/IP connections?

When I try to check the db status (windows powershell):

SERVICE_NAME: postgresql-x64-14
        TYPE               : 10  WIN32_OWN_PROCESS
        STATE              : 1  STOPPED
        WIN32_EXIT_CODE    : 0  (0x0)
        SERVICE_EXIT_CODE  : 0  (0x0)
        CHECKPOINT         : 0x0
        WAIT_HINT          : 0x0

There is no postmaster.pid that could couse the problem.

Can you guys help me with suggestions? I am really bad at this type of debugging and hope to retrieve some good inputs. The problem is that I do not know where to start here.

Thanks in advance

Discussions

Problems connecting to Windows-based Postgresql - Database Administrators Stack Exchange
Question 37307346 'Is the server running on host localhost 1 and accepting tcp ip connections on port 5432?' Question 40532399 'Unable to connect to server for postgres' Database Administrators StackExchange: Problems connecting to Windows-based PostgreSQL · Question 16904997 'Connection refused ... More on dba.stackexchange.com
🌐 dba.stackexchange.com
December 15, 2012
windows - Postgresql: Connection refused on port 5432 - Stack Overflow
I'm stuck with a self-inflicted error I'm unable to solve. I made a change to PostgreSQL 13 Connections and Authentication, changing the port from 5432 to 5433. After that, I got psql error 'could ... More on stackoverflow.com
🌐 stackoverflow.com
October 12, 2021
postgresql - unable to connect to server for Postgres - Stack Overflow
I have a problem to connect server ... my windows.Before I update there is no problem to open the database. My database in Postgres also gone. When I want to create my new database it show this error: Unable to connect to server: could not connect to server: Connection refused (0x0000274D/10061) Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432... More on stackoverflow.com
🌐 stackoverflow.com
database - PostgreSQL: could not connect to server - Connection refused error - Stack Overflow
I've tried to uninstall and reinstall, postgreSQL, twice now. But when I try to launch postgreSQL I keep getting the error below: could not connect to server: Connection refused (0x0000274D/10061) Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432? More on stackoverflow.com
🌐 stackoverflow.com
🌐
Stack Overflow
stackoverflow.com › questions › 69540212 › postgresql-connection-refused-on-port-5432
windows - Postgresql: Connection refused on port 5432 - Stack Overflow
October 12, 2021 - I'm stuck with a self-inflicted error I'm unable to solve. I made a change to PostgreSQL 13 Connections and Authentication, changing the port from 5432 to 5433. After that, I got psql error 'could ...
🌐
Bobcares
bobcares.com › blog › postgressql-connection-refused
Fix PostgreSQL connection refused easily
June 9, 2020 - At times, the restrictions placed ... 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...
Find elsewhere
🌐
Sentry
sentry.io › sentry answers › postgres › psql: could not connect to server: connection refused
psql: Could not Connect to Server: Connection Refused | Sentry
July 12, 2022 - If you are trying to connect to a Postgres instance on the same host as your terminal, you can run lsof -p :5432 which will show which, if any, processes are listening on that port.
🌐
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 - Facing the PostgreSQL error “could not connect to server: PostgreSQL Connection refused”? Here are 7 proven fixes to restart services, check ports, and resolve network or configuration issues quickly.
🌐
Locallhost
locallhost.dev › postgres-connection-refused-5432
PostgreSQL Connection Refused on Port 5432 - Complete Fix Guide
💡 What "Connection Refused" Means: This error occurs when your computer actively rejects the connection attempt, usually because no service is listening on the specified port. ... sudo systemctl start mysql (MySQL) sudo systemctl start postgresql (PostgreSQL) redis-server (Redis) mongod (MongoDB)
🌐
YouTube
youtube.com › watch
Fix issues with PostgreSQL connection on port 5432 on remote host. - YouTube
Fix issues with Connection refused and Connection timeout on PostgreSQL connection on port 5432 and remote host.01:10 PSQL odbc driver download and installa...
Published   November 20, 2023
🌐
CodeGenes
codegenes.net › blog › cannot-connect-to-postgres-from-remote-host
Cannot Connect to PostgreSQL from Remote Host? Fix 'Connection Refused on Port 5432' Error — codegenes.net
Windows Firewall: Open "Windows ... the port is reachable. Failure: "Connection refused" or "timed out" indicates the firewall is still blocking traffic....
🌐
PostgreSQL
postgresql.org › message-id › CAMHKnAmiKxNK9ygWmTSF6rFCzXwg99GLtYPXzSbt4L0VGDePQw@mail.gmail.com
PostgreSQL: Re: Connection refused (0x0000274D/10061)
June 13, 2019 - > > If the above is correct then the error message: > > ": Connection refused (0x0000274D/10061) Is the server running on host > "localhost" (::1) and accepting TCP/IP connections on port 5432?" > > means either: > > 1) The server is not running. ...
🌐
YouTube
youtube.com › online study for cs
How to Fix PostgreSQL Connection to Server at Localhost (::1) Port 5432 Failed Connection Refused - YouTube
How to Fix PostgreSQL Connection to Server at Localhost (::1) Port 5432 Failed Connection RefusedIn this video I have talked about How to fix PostgreSQL Conn...
Published   August 20, 2023
Views   15K
🌐
nixCraft
cyberciti.biz › nixcraft › howto › debian linux › postgresql psql: could not connect to server: connection refused
PostgreSQL psql: could not connect to server: Connection refused - nixCraft
March 6, 2007 - Restart the PostgreSQL server with the following command # /etc/init.d/postgresql restart · This will open default port 5432.
🌐
PostgreSQL
postgresql.org › message-id › attachment › 95054 › unknown_filename
Sometimes postgres is running but in another port 5433 ...
could not connect to server: Connection refused (0x0000274D/10061) Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432? could not connect to server: Connection refused (0x0000274D/10061) Is the server running on host "localhost" (127.0.0.1) and accepting ...