Postgresql server is running on local machine but psql can not connect - postgresql

After doing brew install postgres:
brew install postgres
brew link --overwrite postgresql
Postgres is already running:
/~ $brew services start postgresql
Service `postgresql` already started, use `brew services restart postgresql` to restart.
But then how do we connect using psql client?
13:47:28/~ $psql
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
Updates Tried various suggestions.
Try restarting ..
$brew services start postgresql
Service `postgresql` already started, use `brew services restart postgresql` to restart.
14:37:19/fastparquet $brew services restart postgresql
Stopping `postgresql`... (might take a while)
==> Successfully stopped `postgresql` (label: homebrew.mxcl.postgresql)
==> Successfully started `postgresql` (label: homebrew.mxcl.postgresql)
14:37:39/fastparquet $psql
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
14:37:55/fastparquet $
Connect to localhost?
14:37:34/fastparquet $psql -h localhost
psql: 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?

The link from a_horse_with_no_name did the trick. Specifically:
initdb -D /usr/local/var/postgres/
(from Homebrew postgres broken )
and then
createdb
(the latter from psql: FATAL: database "<user>" does not exist )

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

connect pgadmin3 to postgres runnng on server

** new to pgadmin and postgress **
my organization uses PostgreSQL on its server with ubuntu os, I try to connect it using pgadmin 3,
these are the stapes I have taken
changed pg_hba.conf using 'sudo nano /etc/postgresql/9.3/main/pg_hba.conf'
changed listen_addresses='*' in postgresql.conf file
sudo ufw allow 5432/tcp
but still, I am unable to connect I get this error from pg admin:
Server doesn't listen
The server doesn't accept connections: the connection library reports could not connect to server: Connection timed out Is the server running on host "103.72.131.155" and accepting TCP/IP connections on port 5432?
how can I fix it,
is there any website which can guide me step by step to connect pgadmin to PostgreSQL.

Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432

I install pgadmin4 using the following command sudo install pgadmin4 and then I installed postgresql using sudo install postgresql . In my terminal I ran the command psql -U postgres -h localhost
It shows connection refuse
Then I go to pgadmin4 and created a server and I wanted to connect to the server it shows
pgadmin connection refuse
Then I wrote host all all all md5 in pg_hba.conf file and I wrote listen_addresses = '*' to postgresql.conf file. and I wrote the following command sudo service postgresql restart but again It shows connection refuse message.
I wrote psql and it shows connections on Unix domain socket
Can you please help me in this regard? What I have missed?

Postgres remote connection

Hello I have installed PostgresSQL 11 on CentOS Linux release 7.6.1810.
I have edited files pg_hba.conf
host all all all md5
And postgresql.conf
listen_addresses = '*'
However, following a restart I am unable to connect from pgAdmin with error:
could not connect to server: Connection refused (0x0000274D/10061) Is
the server running on host "10.190.9.130" and accepting TCP/IP
connections on port 5432?
If I run Docker container on the same server with postgres it connects successfully. Has anyone had this issue with a manual postgres install?

SSL on postgresql FATAL ERROR

I'm currently working on ubuntu 16.04. When I make ssl configurations for postgresql and then restart the service with this command:
/etc/init.d/postgresql restart
My database starts refusing the connections
psql: could not connect to server: No such file or directory
Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
How can I fix this?