most recent 30 from stackoverflow.com2026-03-01T07:42:37Zhttps://stackoverflow.com/feeds/question/38466190https://creativecommons.org/licenses/by-sa/4.0/rdfhttps://stackoverflow.com/q/38466190106Rodrigohttps://stackoverflow.com/users/10865112016-07-19T18:41:46Z2025-11-27T15:28:58Z
<p>I have PostgreSQL 9.3 installed on a server running Ubuntu Server 14.04.</p>
<p>If I ssh into the server via terminal, I'm able to connect with psql. But when I try to configure pgAdmin III to do the remote connection, I get:</p>
<blockquote>
<p>Server doesn't listen The server doesn't accept connections: the
connection library reports could not connect to server: Connection
refused Is the server running on host "172.24.3.147" and accepting
TCP/IP connections on port 5432?</p>
</blockquote>
<p>When I run on the server <code>service postgresql status</code> it gives me:</p>
<pre><code>9.3/main (port 5432): online
</code></pre>
<p>So of course I'm missing something important here.</p>
<p>EDIT</p>
<p>When running <code>netstat -na</code> on the server, I get (relevant portion, I guess):</p>
<pre><code>Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
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 172.24.3.147:22 172.24.3.240:61950 ESTABLISHED
tcp 0 0 172.24.3.147:22 172.24.3.240:60214 ESTABLISHED
</code></pre>
https://stackoverflow.com/questions/38466190/cant-connect-to-postgresql-on-port-5432/38466289#384662893Daniel Kravetz Malabudhttps://stackoverflow.com/users/35046812016-07-19T18:47:57Z2016-07-19T18:47:57Z<p>You probably need to either open up the port to access it in your LAN (or outside of it) or bind the network address to the port (make PostgreSQL listen on your LAN instead of just on localhost)</p>
https://stackoverflow.com/questions/38466190/cant-connect-to-postgresql-on-port-5432/38466547#38466547155Jan Marekhttps://stackoverflow.com/users/7504232016-07-19T19:02:22Z2025-11-27T15:28:58Z<p>You have to edit <strong>postgresql.conf</strong> file and change the <a href="https://www.postgresql.org/docs/current/runtime-config-connection.html#GUC-LISTEN-ADDRESSES" rel="nofollow noreferrer">listen_addresses</a> line.</p>
<p>This file you can find in the <code>/etc/postgresql/9.3/main</code> directory.</p>
<p>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:</p>
<pre><code>listen_addresses = '*'
</code></pre>
<p>Then you have edit <strong>pg_hba.conf</strong> 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:</p>
<pre><code>host all all 192.168.1.0/24 md5
</code></pre>
<p>Please, read comments in this file...</p>
<h2>EDIT:</h2>
<p>After the editing <code>postgresql.conf</code> and <code>pg_hba.conf</code> you have to restart postgresql server: <code>sudo service postgresql restart</code></p>
<p>EDIT2: Highlited configuration files.</p>
https://stackoverflow.com/questions/38466190/cant-connect-to-postgresql-on-port-5432/39904002#399040028max56https://stackoverflow.com/users/67276252016-10-06T19:16:30Z2016-10-06T19:16:30Z<p>Had same problem with psql via command line connecting and pgAdmin not connecting on RDS with AWS. I did have my RDS set to Publicly Accessible. I made sure my ACL and security groups were wide open and still problem so, I did the following:
<code>sudo find . -name *.conf</code>
then <code>sudo nano ./data/pg_hba.conf</code>
then added to top of directives in pg_hba.conf file <code>host all all 0.0.0.0/0 md5</code>
and pgAdmin automatically logged me in. </p>
<p>This also worked in pg_hba.conf file
<code>host all all md5</code> without any IP address and this also worked with my IP address <code>host all all <myip>/32 md5</code></p>
<p>As a side note, my RDS was in my default VPC. I had an identical RDS instance in my non-default VPC with identical security group, ACL and security group settings to my default VPC and I could not get it to work. Not sure why but, that's for another day. </p>
https://stackoverflow.com/questions/38466190/cant-connect-to-postgresql-on-port-5432/44847933#448479339Alexhttps://stackoverflow.com/users/38452082017-06-30T13:40:05Z2017-06-30T14:52:31Z<p>Remember to check firewall settings as well. after checking and double-checking my <code>pg_hba.conf</code> and <code>postgres.conf</code> files I finally found out that my firewall was overriding everything and therefore blocking connections</p>
https://stackoverflow.com/questions/38466190/cant-connect-to-postgresql-on-port-5432/55504327#555043272Adrian Stanicahttps://stackoverflow.com/users/113080832019-04-03T21:10:35Z2019-04-03T21:10:35Z<p>I had the same problem after a MacOS system upgrade. Solved it by upgrading the postgres with brew.
Details: it looks like the system was trying to access Postgres 11 using older Postgres 10 settings. I'm sure it was my mistake somewhere in the past, but luckily it all got sorted out with the upgrade above.</p>
https://stackoverflow.com/questions/38466190/cant-connect-to-postgresql-on-port-5432/56858810#5685881047San Emmanuel Jameshttps://stackoverflow.com/users/84134002019-07-02T19:19:07Z2021-04-20T21:23:09Z<blockquote>
<p><strong>Uncomment the listen_addresses = '*' in the postgresql.conf</strong></p>
</blockquote>
<p>This has bitten me a second time so I thought might be worth mentioning. The line listen_addresses = '*' in the postgresql.conf is by default commented. Be sure to uncomment (remove the pound sign, # at the beginning) it after updating otherwise, remote connections will continue to be blocked.</p>
<p>PS: <code>psql -U postgres -c 'SHOW config_file'</code> - to locate the postgresql.conf file path</p>
https://stackoverflow.com/questions/38466190/cant-connect-to-postgresql-on-port-5432/66179756#661797562Scott Moorehttps://stackoverflow.com/users/152006282021-02-12T22:17:24Z2021-02-12T22:17:24Z<p>I had this same issue. I originally installed version 10 because that was the default install with Ubuntu 18.04. I later upgraded to 13.2 because I wanted the latest version. I made all the config modifications, but it was still just binging to 1207.0.0.1 and then I thought - maybe it is looking at the config files for version 10. I modified those and restarted the postgres service. Bingo! It was binding to 0.0.0.0</p>
<p>I will need to completely remove 10 and ensure that I am forcing the service to run under version 13.2, so if you upgraded from another version, try updating the other config files in that older directory.</p>
https://stackoverflow.com/questions/38466190/cant-connect-to-postgresql-on-port-5432/68882538#688825380OZLEM CITCIhttps://stackoverflow.com/users/164430712021-08-22T15:02:43Z2021-08-22T15:02:43Z<p>I use home-brew to start my server.</p>
<p>1)<em>stop the server (but it is not working. it Is the problem)</em></p>
<p>brew services stop postgresql</p>
<p>2)make update if it is needed</p>
<p>brew postgresql-upgrade-database</p>
<p>3)below comment solve my problem it start the server. Thats it</p>
<p>brew services start postgresql</p>
https://stackoverflow.com/questions/38466190/cant-connect-to-postgresql-on-port-5432/70163546#701635463drosandahttps://stackoverflow.com/users/9564452021-11-30T02:19:13Z2021-11-30T02:19:13Z<p>If error occurred first thing first you have to read the log.</p>
<ul>
<li>This only applicable for postgresql installation through brew on your mac *</li>
</ul>
<p>First, you have to check the postgresql status by running</p>
<p><code>brew services</code> on your terminal</p>
<p>If its stopped, try to started it and then run the <code>brew services</code> again</p>
<p>And if the status show error, you can easily find the log location through the *.plist file.</p>
<p>Example, on my configuration</p>
<pre><code>cat /Users/drosanda/Library/LaunchAgents/homebrew.mxcl.postgresql@12.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>homebrew.mxcl.postgresql@12</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/opt/postgresql@12/bin/postgres</string>
<string>-D</string>
<string>/usr/local/var/postgresql@12</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StandardErrorPath</key>
<string>/usr/local/var/log/postgresql@12.log</string>
<key>StandardOutPath</key>
<string>/usr/local/var/log/postgresql@12.log</string>
<key>WorkingDirectory</key>
<string>/usr/local</string>
</dict>
</plist>
</code></pre>
<p>Here is the log file content:</p>
<p><code>2021-11-30 09:07:20.154 WIB [3891] FATAL: lock file "postmaster.pid" already exists</code></p>
<p><code>2021-11-30 09:07:20.154 WIB [3891] HINT: Is another postmaster (PID 422) running in data directory "/usr/local/var/postgresql@12"?</code></p>
<p>For my case, the postgresql won't start caused by the PID file is still exists.</p>
<p>It's easy to fix, by removed the <code>postmaster.pid</code> file.</p>
<p>Just add an answer that might useful for someone later.</p>
https://stackoverflow.com/questions/38466190/cant-connect-to-postgresql-on-port-5432/70181215#7018121516rtfmplizhttps://stackoverflow.com/users/50389272021-12-01T08:41:41Z2021-12-01T08:41:41Z<p>just summary from the accepted answer</p>
<p>if maybe someone like me overlook the filename that must be edit</p>
<p>in my case the conf file located at</p>
<p><code>/etc/postgresql/14/main'</code></p>
<p>if you type <code>cd /etc/postgresql/14/main</code></p>
<p>so just <code>sudo nano </code> add these 2 filenames</p>
<ol>
<li><strong>postgresql.conf</strong></li>
</ol>
<p><code>listen_addresses = '*'</code></p>
<p>uncomment this line and change localhost to *</p>
<ol start="2">
<li><strong>pg_hba.conf</strong></li>
</ol>
<p><code>host all all 0.0.0.0/0</code></p>
<p>change the 127.0.0.1/32 change to 0.0.0.0/0</p>
<p>last don't forget to restart using <code>sudo service postgresql restart</code></p>
<p>I hope this one clears the notification error</p>
https://stackoverflow.com/questions/38466190/cant-connect-to-postgresql-on-port-5432/70708972#707089721joyhttps://stackoverflow.com/users/179322392022-01-14T10:12:25Z2022-01-14T10:12:25Z<blockquote>
<p>windows === press WIN + R //open services
type - services.msc<br />
find postgres - double click on it.</p>
<p>properties box open then click on start
enjoy.</p>
</blockquote>
https://stackoverflow.com/questions/38466190/cant-connect-to-postgresql-on-port-5432/70905935#7090593510Dinesh Penugondahttps://stackoverflow.com/users/81947512022-01-29T13:34:36Z2022-01-29T13:34:36Z<p>You have to edit <code>pg_hba.conf</code> to accept all requests within the network</p>
<pre><code>#TYPE DATABASE USER ADDRESS METHOD
host all all 0.0.0.0/0 md5
host all all ::1/128 md5
</code></pre>
<p>From your application, you can connect using this IP address like below example: -</p>
<blockquote>
<p>postgresql://postgres:******@192.168.1.101:5432/app</p>
</blockquote>
https://stackoverflow.com/questions/38466190/cant-connect-to-postgresql-on-port-5432/71492057#714920572Johnny Dhttps://stackoverflow.com/users/93031512022-03-16T05:11:26Z2022-03-16T05:11:26Z<p>adding an updated answer for another possibility. running postgres 10 on AWS EC2 I had to add a custom inbound rule through Windows Defender Firewall to allow port 5432.</p>
https://stackoverflow.com/questions/38466190/cant-connect-to-postgresql-on-port-5432/71508884#715088843Swiss bobohttps://stackoverflow.com/users/147289332022-03-17T08:06:19Z2022-03-17T08:06:19Z<p>For anyone else coming from docker and other applications issues like node js or Django or anything</p>
<p>i faced this problem for 2 days or more watched videos tutorials nothing seem to work although ill say i have missed some but here is the solution that worked for me</p>
<p>instead of local host for PGHOST</p>
<p>you must specify your service name</p>
<p>e.g</p>
<pre><code> image: postgres
container_name: postgresdb
restart: always
env_file:
- ./env/.env
volumes:
</code></pre>
<p>then your host must be
PGHOST:nodeapp-db</p>
https://stackoverflow.com/questions/38466190/cant-connect-to-postgresql-on-port-5432/72940677#729406770Kmb40https://stackoverflow.com/users/13831492022-07-11T15:05:44Z2023-02-06T14:47:49Z<p>Had this same issue and searches resulted in many complex overly solutions. Ultimately this issue was that a password had not been set after Postgres was installed on Ubuntu.</p>
<p>Solution:</p>
<ol>
<li>From the Postgres terminal - reached by entering "<code>sudo -u postgres psql</code>" which should result in "<code>postgres=#</code>"...</li>
<li>Set the password using "<code>\password postgres</code>"</li>
<li>Update PG Admin with the new password and the username "<code>postgres</code>"</li>
</ol>
<p>Reference <a href="https://www.cherryservers.com/blog/how-to-install-and-setup-postgresql-server-on-ubuntu-20-04" rel="nofollow noreferrer">https://www.cherryservers.com/blog/how-to-install-and-setup-postgresql-server-on-ubuntu-20-04</a>.</p>
https://stackoverflow.com/questions/38466190/cant-connect-to-postgresql-on-port-5432/73690167#736901670Matthttps://stackoverflow.com/users/10163432022-09-12T13:31:38Z2022-09-15T07:34:04Z<p>In my case, the server wasn't listenting because it didn't start up automatically (Windows version of PostgreSQL), because the setup program didn't create a user and didn't initialize the server. The following helped me:</p>
<p>After the setup I had to run (in a non-admin cmd.exe shell):</p>
<pre><code>set PGDATA=C:\Program Files\PostgreSQL\14\data
cd C:\Program Files\PostgreSQL\14\bin
createuser.exe -s postgres
pg_ctl init
pg_ctl start
</code></pre>
<p>After that, I used the <code>pgAdmin</code> tool and selected "Add new server" in the dashboard. There, I typed in the desired server name in the "General" tab, and in the "Connection" tab I entered <code>127.0.0.1</code> because I wanted to run it locally. After confirming it with <kbd>Save</kbd> it got created properly.</p>
<p>It seems that in Windows, Postgres isn't running as a Windows Service, so it doesn't start automatically and you have to run it manually. However you could create a <code>StartPg.cmd</code> file and put in the command <code>C:\Program Files\PostgreSQL\14\bin\pg_ctl start</code>, then you can open a Windows Explorer via <kbd>Win</kbd>+<kbd>E</kbd>, enter <code>shell:Startup</code> in its path textbox (then press <kbd>Enter</kbd>) and copy the batch file (or a shortcut of it) into it.</p>
<p>Then it will start up automatically.</p>
https://stackoverflow.com/questions/38466190/cant-connect-to-postgresql-on-port-5432/74475486#744754865Namwanza Ronaldhttps://stackoverflow.com/users/92129952022-11-17T12:28:37Z2022-11-17T12:34:23Z<blockquote>
<p>If you have tried to edit <strong>pg_hba.conf</strong> and <strong>postgres.conf</strong> files
as suggested above and nothing worked, then here you go !</p>
</blockquote>
<h1>A try for the late birds: | LINUX USERS</h1>
<p>After trying all other options suggested above, none worked for me.</p>
<p>So I released that this was happening due to failed <strong>PostgreSQL Cluster 14-main</strong> when booting/starting.</p>
<p>I followed below steps,</p>
<h2>Applied Solution :</h2>
<ol>
<li><code>sudo chmod 700 -R /var/lib/postgresql/14/main</code></li>
<li><code>sudo -i -u postgres</code></li>
<li><code>/usr/lib/postgresql/14/bin/pg_ctl restart -D /var/lib/postgresql/14/main</code></li>
</ol>
<p>Note: You can replace 14 with your postgresql version number, you can check <code>/usr/lib/postgresql</code>/{mark the number you see here}</p>
<h2>After Solution status :</h2>
<blockquote>
<p>pg_ctl: PID file "/var/lib/postgresql/14/main/postmaster.pid" does not
exist Is server running? trying to start server anyway waiting for
server to start....2022-11-17 13:06:36.614 CET [5542] LOG: starting
PostgreSQL 14.5 (Ubuntu 14.5-0ubuntu0.22.04.1) on x86_64-pc-linux-gnu,
compiled by gcc (Ubuntu 11.2.0-19ubuntu1) 11.2.0, 64-bit 2022-11-17
13:06:36.614 CET [5542] LOG: listening on IPv4 address "0.0.0.0",
port 5432 2022-11-17 13:06:36.614 CET [5542] LOG: listening on IPv6
address "::", port 5432 2022-11-17 13:06:36.616 CET [5542] LOG:
listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2022-11-17 13:06:36.623 CET [5543] LOG: database system was shut down
at 2022-11-17 09:20:13 CET 2022-11-17 13:06:36.631 CET [5542] LOG:
<strong>database system is ready to accept connections done server started</strong></p>
</blockquote>
<ol start="4">
<li><code>pg_lsclusters</code></li>
</ol>
<p>Ver | Cluster | Port | Status | Owner | Data directory | Log file</p>
<p>10 main 5432 online postgres /var/lib/postgresql/10/main
/var/log/postgresql/postgresql-10-main.log</p>
<p>Finally, I was able to connect to <strong>PORT = 5432</strong> with no problem and everything worked perfectly fine.</p>
https://stackoverflow.com/questions/38466190/cant-connect-to-postgresql-on-port-5432/75356582#753565820Jenshttps://stackoverflow.com/users/3563072023-02-06T01:10:49Z2023-02-06T01:10:49Z<p>I’m using <a href="https://www.macports.org/" rel="nofollow noreferrer">MacPorts</a> and after migrating to a new machine using Apple’s <a href="https://support.apple.com/en-au/HT204350" rel="nofollow noreferrer">Migration Assistant</a> the db server was unavailable:</p>
<pre><code>psql: error: connection to server at "localhost" (127.0.0.1), port 5432 failed: Connection refused
Is the server running on that host and accepting TCP/IP connections?
connection to server at "localhost" (::1), port 5432 failed: Connection refused
Is the server running on that host and accepting TCP/IP connections?
</code></pre>
<p>I tried</p>
<pre><code>sudo port load postgresql14-server
</code></pre>
<p>but that didn’t work. Looking at the <code>/Library/LaunchDaemons/org.macports.postgresql14-server.plist</code> file, though revealed two things:</p>
<pre class="lang-xml prettyprint-override"><code><key>Disabled</key><true/>
</code></pre>
<p>and the actual start command</p>
<pre class="lang-xml prettyprint-override"><code><string>--start-cmd</string>
<string>/opt/local/etc/LaunchDaemons/org.macports.postgresql14-server/postgresql14-server.wrapper</string>
</code></pre>
<p>So, running the start command manually finally showed the issue:</p>
<pre><code>> sudo /opt/local/etc/LaunchDaemons/org.macports.postgresql14-server/postgresql14-server.wrapper start
pg_ctl: could not open PID file "/opt/local/var/db/postgresql14/defaultdb/postmaster.pid": Permission denied
</code></pre>
<p>and indeed:</p>
<pre><code>> sudo ls -la /opt/local/var/db/postgresql14/defaultdb/
total 60
drwx------ 26 postgres postgres 832 Jan 31 05:13 .
drwxr-xr-x 4 postgres postgres 128 Feb 5 12:31 ..
-rw------- 1 500 postgres 3 Nov 7 2021 PG_VERSION
drwx------ 22 500 postgres 704 Feb 4 10:37 base
drwx------ 60 500 postgres 1920 Feb 4 10:37 global
drwx------ 2 500 postgres 64 Nov 7 2021 pg_commit_ts
...
-rw------- 1 500 postgres 105 Jan 31 05:13 postmaster.pid
</code></pre>
<p>The user id was messed up. Fix:</p>
<pre><code>sudo chown -hR postgres /opt/local/var/db/postgresql14/defaultdb/
</code></pre>
<p>to set the owner of all files to <code>postgres</code>.</p>
<p>With that change, the server works:</p>
<pre><code>> sudo /opt/local/etc/LaunchDaemons/org.macports.postgresql14-server/postgresql14-server.wrapper start
pg_ctl: another server might be running; trying to start server anyway
waiting for server to start.... done
server started
> psql -U postgres -W -p 5432 -h localhost
Password:
psql (14.6)
Type "help" for help.
postgres=#
\q
</code></pre>
https://stackoverflow.com/questions/38466190/cant-connect-to-postgresql-on-port-5432/75360878#753608782Bruno Limahttps://stackoverflow.com/users/151379112023-02-06T11:43:49Z2023-02-06T11:43:49Z<p>Just give one <code>sudo service postgresql start</code></p>