1

I try to run an application where its database on postgresql. It won't work and I'm getting the following error whenever I try to interact with the Postgres service:

could not connect to server: Aucun fichier ou dossier de ce type
 Is the server running locally and accepting
 connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432`

I checked if Postgresql service is running

sudo systemctl status postgresql 
postgresql.service - PostgreSQL RDBMS
 Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enab
 Active: active (exited) since Thu 2019年04月04日 10:28:27 +01; 58min ago
 Main PID: 1212 (code=exited, status=0/SUCCESS)
 Tasks: 0 (limit: 3522)
 CGroup: /system.slice/postgresql.service
avril 04 10:28:27 ubuntu systemd[1]: Starting PostgreSQL RDBMS...
avril 04 10:28:27 ubuntu systemd[1]: Started PostgreSQL RDBMS.

checked the content of the socket unix connection

ls /var/run/postgresql/

got this empty folder

brahim@ubuntu:/var/log/postgresql$ ls /var/run/postgresql/
10-main.pg_stat_tmp

checked the content of the data directory

ls /var/lib/postgresql/10/main/

it contains the following

 base pg_logical pg_serial pg_subtrans pg_wal
 global pg_multixact pg_snapshots pg_tblspc pg_xact
 pg_commit_ts pg_notify pg_stat pg_twophase 
 postgresql.auto.conf pg_dynshmem pg_replslot pg_stat_tmp 
 PG_VERSION postmaster.opts

the file postgresql.conf has the following configuration

 # - Connection Settings -
 #listen_addresses = 'localhost'
 port = 5432
 max_connections = 100
 unix_socket_directories = '/var/run/postgresql'

I tried to uncomment the listen_addresses instruction and it didn't work, also I've tried with '*' for all, same thing

the postgresql file log has

2019年04月04日 12:17:57.765 +01 [942] LOG: listening on IPv4 address "127.0.0.1", port 5432
2019年04月04日 12:17:57.767 +01 [942] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2019年04月04日 12:17:58.190 +01 [971] LOG: database system was shut down at 2019年04月03日 20:19:54 +01
2019年04月04日 12:17:58.192 +01 [971] PANIC: replication checkpoint has wrong magic 1886413116 instead of 307747550
2019年04月04日 12:17:59.900 +01 [942] LOG: startup process (PID 971) was terminated by signal 6: Aborted
2019年04月04日 12:17:59.900 +01 [942] LOG: aborting startup due to startup process failure
2019年04月04日 12:17:59.902 +01 [942] LOG: database system is shut down

I am running postgresql 10.6 any thoughts

asked Apr 4, 2019 at 11:29
10
  • @a_horse_with_no_name yes, i've tried that, and i get the fallowing #psql: could not connect to server: Connexion refusée #Is the server running on host "localhost" (127.0.0.1) and accepting #TCP/IP connections on port 5432? Commented Apr 4, 2019 at 12:33
  • 2
    Looking closer at the postgres log, it seems your data directory is corrupt: "replication checkpoint has wrong magic 1886413116 instead of 307747550" and the subsequent "aborting startup due to startup process failure". I don't know if that can be properly fixed, but one way would be to get rid of the current data directory, create a new one using initdb then restore your backup. Commented Apr 4, 2019 at 12:36
  • @dezso >brahim@ubuntu:/etc/postgresql/10/main$ ls -la /var/run/postgresql total 0 drwxrwsr-x 3 postgres postgres 60 avril 4 13:22 . drwxr-xr-x 37 root root 980 avril 4 12:18 .. drwxr-s--- 2 postgres postgres 40 avril 4 12:17 10-main.pg_stat_tmp as i mentioned whatever commands you put in to interact with postgresql service it generates the same error code for example 'psql' Commented Apr 4, 2019 at 12:37
  • "replication checkpoint has wrong magic" Is this server supposed to be using logical replication? Is it the publisher or the subscriber? Commented Apr 4, 2019 at 12:47
  • @a_horse_with_no_name after that i creat a new one with ./initdb -D /usr/local/pgsql/data the creation was done successfully, but i try to start it with the fallowing sudo ./pg_ctl -D /usr/local/pgsql/data -l logfile start but i get permission denied error #pg_ctl: cannot be run as root Please log in (using, e.g., "su") as the (unprivileged) user that will own the server process# i changed the owner of the /usr/local/pgsql/data/ to the usr brahim ls - la /usr/local/pgsql/data/ got this #total 8 drwxr-xr-x 2 brahim brahim 4096 avril 4 13:55 . drwxr-xr-x 3 root root 4096 avril 4 13:55 Commented Apr 4, 2019 at 13:22

2 Answers 2

1

Try passing the -a option to ls to also show files starting with the period . character (i.e. "hidden" files):

$ ls -a /var/run/postgresql/
. .. .s.PGSQL.5432 .s.PGSQL.5432.lock
answered Dec 12, 2019 at 20:06
-1

Solución que me funcionó en Postgresql 11:

sudo pg_ctlcluster 11 main start

También revisar que tenga bien configurado pg_hba.conf

answered Oct 29, 2019 at 17:06
1
  • 1
    Hi Idexan, any chance you can add some more detail about why you think his is wrong, and how to configure pg_hba.conf to make this go away? I see that you are using pg_ctlcluster but he isn't. (I could be wrong, I don't see it). This site is about Q&A, and having those answers is sure sometimes helpful, instead of just "copy-paste this it'll work". Commented Oct 29, 2019 at 17:51

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.