Reputation: 33
I followed several tutorials to install PostgreSQL on my Ubuntu 20.4, but I've a problem. In order to install Postgres I used
sudo apt install postgresql postgresql-contrib
It seems ok, however when I throw
sudo -i -u postgres
postgres@gabriele:~$ psql
I see this error
psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: >File o directory non esistente Is the server running locally and accepting connections on that socket?
I don't know how resolve this thing. Maybe, when I use pgAdmin4 to work with DB I find no server connection and I don't know how to connect a server. It is my first time with this kind of things, can somebady help me?
Upvotes: 0
Views: 2215
Reputation: 9248
Usually you want to start the Postgres database server in the background as a service (except e.g. in a container). It seems like you are trying to start it in the foreground instead. You can do that using the following command.
sudo systemctl start postgresql
You may check if it is running using this:
sudo systemctl status postgresql
If it is running you should see something like this.
● postgresql.service - PostgreSQL RDBMS
Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
Active: active (exited) since Tue 2022-03-15 16:57:15 CET; 4min 34s ago
Process: 205678 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
Main PID: 205678 (code=exited, status=0/SUCCESS)
Then you will still not be able to connect via psql
as by default configuration Postgres won't successfully authenticate you as it is using Peer Authentication
and your username is likely not postgres
which is the default user and database psql
uses.
The error message will be something like this psql: error: FATAL: Peer authentication failed for user "postgres"
.
There is a guide on how to change the configuration in this answer so you will be able to successfully authenticate.
Whether you're using psql
, pgAdmin
or another client should not matter as long as you have authentication configured correctly and are connecting with the right username
, database name
, host
and port
. You can see the defaults and how you can specify your own values using psql --help
.
PS: You might also wanna consider using the official Postgres container instead of installing Postgres on your system. There is a description on how to get that up and running on DockerHub as well.
Upvotes: 1