I made a really stupid thing: I ran sudo chmod -R 777 / for all folders inside the root directory. After that even sudo didn't work because of invalid permissions. I fixed the problem with sudo, but I need to create a backup dump file of my database in PostgreSQL. As you could guess, after my idiotic action pg_dump and psql don't work anymore. When I try to execute them I get:

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"

Fixing your system's permissions is gonna be something tough. you have two options: reinstall all packages in your system or reinstall it from scratch, backing up your data. Personally, I'd go with the second option.

First, check where PostgreSQL is storing your databases with:

sudo cat /etc/postgresql/{version}/main/postgresql.conf | grep data_directory

(For this procedure, I'll use "/srv/postgresql/9.6/main" for the examples and 9.6 as version). Then, try to fix your permissions with these commands:

sudo chown postgres.postgres -R /srv/postgresql/9.6/main
sudo find /srv/postgresql/9.6/main -type d -print0 | xargs -r -0 chmod 700
sudo find /srv/postgresql/9.6/main -type f -print0 | xargs -r -0 chmod 600
sudo chown postgres.postgres -R /var/run/postgresql
sudo chmod u=rwx,g=rws,o=rx /var/run/postgresql
sudo find /var/run/postgresql -type f -print0 | xargs -r -0 chmod 600
sudo chmod u=rwx,g=rs /var/run/postgresql/*.pid
sudo service postgresql restart

Finally, try to connect to the service with:

sudo -u postgres psql

If that doesn't work, backup your data_directory, fully reinstall your PostgreSQL packages, so it'll fix your permissions, and try again.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.