pgAdmin: could not connect to server: Connection refused - postgresql

I am trying to view databases with pgAdmin. After starting pgAdmin and successfully entering my "master password". I get the following error while trying to open up the only instance, in this case: "PostgeSQL 12".
I am getting this pgAdmin error:
could not connect to server: Connection refused Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432? could not connect to server: Connection refused Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432?
Picture of: Connection refused error
After entering the correct and only password I have used for 4 or so different programs: I get the same pop-up error. None of the programs access the database any longer.
I did try right-clicking "PostgreSQL 12" and clearing the password but that did not resolve the issue.
I will say that I recently restored from a backup because I did a hardware upgrade where I swapped out a HDD to a SSD.
I am running the following:
MacOS High Sierra 10.13.6
PostgreSQL 12
pgAdmin 4
UDATE 1:
I found something: I think this is the installation full path: /Library/PostgreSQL/12/bin
I ran from bin:
./pg_ctl --help
and got the full help menu options. Would I now have to run status, start, or stop on the correct server? Which server or file might that be? Is it data, which seems to be locked?
UPDATE 2:
I ran ./pg_ctl start
and got: "pg_ctl: no database directory specified and environment variable PGDATA unset"
UPDATE 3:
I ran ./pg_ctl start -D /Library/PostgreSQL/12/data
and got: "pg_ctl: could not open PID file "/Library/PostgreSQL/12/data/postmaster.pid": Permission denied"
Picture of: Directory
UPDATE 4:
ran from the bin folder found at /Library/PostgreSQL/12/bin I ran:
sudo -u postgres ./pg_ctl start -D /Library/PostgreSQL/12/data
and after inputing password:
waiting for server to start....2020-04-22 15:57:51.766 CDT [5255] LOG: starting PostgreSQL 12.2 on x86_64-apple-darwin, compiled by Apple LLVM version 6.0 (clang-600.0.54) (based on LLVM 3.5svn), 64-bit
2020-04-22 15:57:51.766 CDT [5255] LOG: listening on IPv6 address "::", port 5432
2020-04-22 15:57:51.766 CDT [5255] LOG: listening on IPv4 address "0.0.0.0", port 5432
2020-04-22 15:57:51.768 CDT [5255] LOG: listening on Unix socket "/tmp/.s.PGSQL.5432"
2020-04-22 15:57:51.782 CDT [5255] LOG: redirecting log output to logging collector process
2020-04-22 15:57:51.782 CDT [5255] HINT: Future log output will appear in directory "log".
stopped waiting
pg_ctl: could not start server
So, to answer some questions, I could not start the server; hence, the error I am getting in pgAdmin.

If you are on windows, You need to start the Postgres in the task manager services section. That way It would connect automatically and ensure there is no firewall connection block on your port 5432. I tried it, and it worked.

Related

Postgres won't start after reboot on Linux

I am running postgres 12 and it won't start after server reboot (run manually by reboot). The attached EBS volume has not changed and I don't see any evidence of a data loss.
When I run psql, I get (this used to work before restart)
psql -h localhost -U postgres
psql: error: could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
pg_lsclusters does not help -
pg_lsclusters 12 main start
Ver Cluster Port Status Owner Data directory Log file
12 main 5432 down postgres /var/lib/postgresql/12/main /var/log/postgresql/postgresql-12-main.log
The error in /var/log/postgresql/postgresql-12-main.log is
pg_ctl: could not start server
Examine the log output.
2021-03-01 00:33:24.976 UTC [1866] FATAL: could not access file "anon": No such file or directory
2021-03-01 00:33:24.976 UTC [1866] LOG: database system is shut down
When I start postgres, I don't get any error -
sudo service postgresql start
If you don’t want to start PostgreSQL manually every time your Linux restarts, run the following command :
sudo update-rc.d postgresql enable
If it can not find LSB script then do this :
sudo systemctl enable postgresql

Postico & Postgres error - could not connect to server: Connection refused

I'm using the latest macOS Catalina.
I've looked into other threads but not sure how to solve mine because I have two errors on both Postgres and Postico.
Postgres says I have a Stale postmaster.pid file
Postico says
could not connect to server: Connection refused
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
I went on Youtube for a solution to address the stale postmaster.pid file, and deleted it using the terminal... but the error still persists..
Should I uninstall, and reinstall Postgres and Postico?
Using the terminal to delete postmaster.pid didn't do it for some reason. I had to do it via Finder manually.
Problem solved :)
I had the same error on Postico.
I just reinstalled Postgres.app and initialize again my data base on the app, and after go back on Postico.

PostgreSQL server Connection error: could not connect to server

I am using pgAdmin4 and developing a node.js app.I had an abrupt shutdown of the computer and I can no longer connect to the postgresql server.
The error I get when trying to connect is :
psql: 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 TCP/IP connections on port 5432?
I tried to run postgres -D /usr/local/var/postgres/ as suggested in this SO answer. However it gave me the following error :
postgres: could not access directory "usr/loval/var/postgres": No such file or directory
Run initdb or pg_basebackup to initialize a PostgreSQL data directory.
So I just manually deleted the postmaster.pid file inside the PostgreSQL/.../data folder. But I still cannot connect to the database server.
I have checked the postgresql.conf file, and
the listen addresses is already set as listen_addresses = '*', and the port is set to 5432.
I also tried deleting the pgAdmin file in the AppData/Roaming folder.But it gave me an error:
The application server could not be contacted
and then afterwards the same problem of not being able to connect to the server happens.
Funny enough, it was a matter of just deleting the pdAdmin file in AppData/Roaming folder, and then restarting the computer and restarting the pgAdmin4. That solved it for me.
Meet the same challenge while settings up PostgreSQL to work with a Python/Django project.And i resolved the issue here, after reading the official PostgreSQL-9.6.16 documentation.

Postgres failing to start on Windows Server 2016 in Azure

I am having issues starting Postgres 9.6.6 on Windows Server 2016 on an Azure VM.
When I try to start Postgres it generates a log file with the following:
LOG: could not bind IPv6 socket: Permission denied
HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
LOG: could not bind IPv4 socket: Permission denied
HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
WARNING: could not create listen socket for "localhost"
FATAL: could not create any TCP/IP sockets
LOG: database system is shut down
Its a completely brand new VM, I've amended postgresql.conf and the listen_addresses to include 127.0.0.1 but I still get the same binding errors.
If I run nslookup on the VM I receive back the following;
Server: Unknown
Address: 148.43.119.15
*** UnKnown can't find localhost: Non-existent domain
So I think the fact that lookup is failing for localhost is possibly causing the problem. I've amended the hosts file on the VM to have:
127.0.0.1 localhost
:1 localhost
But the same errors are occurring, so I think its something that I've not setup in terms of networking but not sure where to look.
If my understanding is right, 148.43.119.15 is your VM's public IP. You could not listen postgresql on the IP, I get the same result if I set similar with you.
Please modify postgreqls.conf
listen_addresses = '*'
For Azure VM, if you want to access postgresql with Public IP you need open port
on Azure NSG and Windows Firewall.

postgres does not know where to find the server configuration file

I had installed PostgreSQL but when I do run command postgres in windows CMD
It gives following error:
postgres does not know where to find the server configuration file.
You must specify the --config-file or -D invocation option or set the PGDATA environment variable.
Even after running command
initdb postgres as maintained similar Issue
postgres -D C:\Program Files\PostgreSQL\data\
gave me following output:
2016-09-28 15:04:57 PDT LOG: could not bind IPv6 socket: Only one usage of each socket address (protocol/network address/port) is normally permitted.
2016-09-28 15:04:57 PDT HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2016-09-28 15:04:57 PDT LOG: could not bind IPv4 socket: Only one usage of each socket address (protocol/network address/port) is normally permitted.
2016-09-28 15:04:57 PDT HINT: Is another postmaster already running on port 5432? If not, wait a few seconds and retry.
2016-09-28 15:04:57 PDT WARNING: could not create listen socket for "*"
2016-09-28 15:04:57 PDT FATAL: could not create any TCP/IP sockets
2016-09-28 15:04:57 PDT LOG: database system is shut down
As the error says, to start a postgresql cluster you must set the path to the data folder. Probably something like:
postgres -D "C:\Program Files\PostgreSQL\data\"
but the use of pg_ctl instead postgres is recommended:
pg_ctl -D "C:\Program Files\PostgreSQL\data\" start
Don't forget to check the postgres documentation about how to start a server and how to use pg_ctl.
Usually, the postgres installlers creates a service/daemon so there is not need to launch the server by hand. So if you get an error like
Is another postmaster already running on port 5432?
It probably means that the server is already running. Try to connect to it using psql