Unable to connect to postgres in ubuntu - postgresql

I am trying to install postgresql on ubuntu.
I followed the steps from http://hocuspokus.net/2008/05/install-postgresql-on-ubuntu-804/.
And on typing the command :
psql template1
I am getting the following error:
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"?

The problem for me was that I had previously installed version 9.1, and 9.1 was still hogging the default port 5432. I was able to find this with the command:
root#labs:/home/caleb# /etc/init.d/postgresql status
9.1/main (port 5432): down
9.2/main (port 5433): online
So I was able to see that my 9.2 database was running on port 5433. So to connect, I had to explicitly specify port 5433:
psql -p 5433

try the following
psql template0

what resolved this error for me was deleting a file called postmaster.pid in the postgres directory. please see my question/answer using the following link for step by step instructions. my issue was not related to file permissions:
psql: could not connect to server: No such file or directory (Mac OS X)

You can also get in the CLI via this command:
psql -U postgres -p 5432 -h localhost

This should solve the error,
make a symbolic link to the /tmp/.s.PGSQL.5432:
sudo ln -s /tmp/.s.PGSQL.5432 /var/run/postgresql/.s.PGSQL.5432
Thanks to this post

Related

Connect to postgres with custom database cluster location with psql

Instead of using /usr/local/pgsql/data, I create my database cluster with the following code
initdb -D /tmp/psql
pg_ctl -D /tmp/psql -l logfile -o "--unix_socket_directories='$PWD'" start
But when I run psql, I get the following error.
psql: error: 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"?
I have read the doc and I cannot find related options for changing the location for database cluster. What have I missed?
I ran into the same issue and specifying the socket directory with the -h option fixes the issue.
psql -h $PWD -p 5432 postgres

Sqitch cannot connect to a running Postgres instance

I have a Postgres 9.6 instance on OSX that is up and running, but Sqitch throws the following error when I try sqitch status in a working directory with a sqitch.conf:
$ sqitch status
# On database db:pg:my_db
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"?
This is odd because I have already checked that Postgres is running by checking its status and logging in directly:
$ pg_isready
/tmp:5432 - accepting connections
$ psql -U postgres
psql (9.6.19)
Type "help" for help.
postgres=#
This seems to be just a problem with sqitch.
For more detail, this Postgres was installed via brew install postgresql#9.6 and is located in the default directory:
$ which psql
/usr/local/opt/postgresql#9.6/bin/psql
Regarding Sqitch, I have tried both installing with Homebrew and using Docker (my current approach). The docker install is based on the official instructions:
docker pull sqitch/sqitch
curl -L https://git.io/JJKCn -o sqitch && chmod +x sqitch
./sqitch status
I tried setting psql explicitly as well with sqitch config --user engine.pg.client /usr/local/opt/postgresql#9.6/bin/psql
Regardless, I still get the following with any sqitch command:
$ sqitch status
# On database db:pg:my_db
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"?
I'm not sure what I'm missing and could use some input. Thanks in advance.
I don't know what's up with the Brew-installed Sqitch, but when you run it from the Docker image, that container does not have Postgres running inside it, so connections to localhost will fail. You instead need to connect to Postgres outside the container. If you're running it on your Mac, this is straightforward to do: Make sure Postgres is listening on the IP ports, not just a Unix domain socket, and specify host.docker.internal as the host name, like so:
sqitch status db:pg://host.docker.internal/my_db

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?

could not connect to database postgres

createuser: could not connect to database postgres: 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"?
I am trying to install dspace 6.3 on ubuntu server 18.04 but after installing postgresql when I run the command createuser -U postgres -d -A -P dspace I am getting the above error help please
Did you start the server? Try sudo service postgresql restart or sudo systemctl restart postgresql

psql: could not connect to server [ubuntu]

Under the postgres user, I tried the psql command and I'm getting this error:
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"
But when I run /usr/local/pgsql/bin/psql, it is working.
Is there anything wrong with my configuration?
the above issue seems related to PostgreSQL default port no,
Change the port no in postgresql.conf file and restart the DB server. if u have changed the port while installing.
(OR)
instead of psql type full command like
"psql -p 5432 -h localhost"
You could include the database user too:
psql -U postgres -p 5432 -h localhost
Did you reinstall the postgresql-9.6.3 ?
You need to uninstall postgresql completely
sudo apt-get --purge autoremove postgresql*
sudo apt install postgresql-9.6