2

I am trying to move the initial Postgres data dir from

/var/lib/postgresql/10/main

to another harddrive. The harddrive is accessable within the terminal via

/media/chris/Datenspeicher

I used this guide to switch my data dir. Postgres is starting up after modifying the postgres.conf file but im not able anymore to access the database through pgadmin or the terminal.

When trying to access the database its asking if the database is running on port 5432 and accepting connections.

Why? What am I doing wrong?

Update: After clean install of ubuntu and postgres all errors still remain. The postgres log output is:

2018-07-06 14:16:04.958 CEST [5664] LOG: listening on IPv4 address "127.0.0.1", port 5432

2018-07-06 14:16:04.998 CEST [5664] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"

2018-07-06 14:16:05.124 CEST [5665] LOG: database system was shut down at 2018-07-06 14:00:21 CEST

2018-07-06 14:16:05.167 CEST [5664] LOG: database system is ready to accept connections

2018-07-06 14:16:05.714 CEST [5672] [unknown]@[unknown] LOG: incomplete startup packet

migrated from stackoverflow.com Jul 5 '18 at 7:06

This question came from our site for professional and enthusiast programmers.

  • What is the error you get? – a_horse_with_no_name Jul 5 '18 at 6:54
  • psql: cannot connect to the server: File or Directory not found. Is the server running local and accepting connections on unix-domain-socket >>/var/run/postgresql/.s.PGSQL.5432? – Trevirius Jul 5 '18 at 6:56
  • Did you check the many, many questions with that error message: stackoverflow.com/… – a_horse_with_no_name Jul 5 '18 at 7:02
  • yes i did. The systemctl status tells me the server is running but the netstat -na | grep postgres prints no answer I also purged all postgres and reainstalled – Trevirius Jul 5 '18 at 7:14
  • Look in the server log file, probably in /var/log/postgres – jjanes Jul 5 '18 at 11:45
1

Please check the socket file is in the /tmp. If it is there then create a link to /var/run.

OR, I prefer this method to move the data directory on Ubuntu.

I hope you have the backup copy of the old directory which is in /var/lib/postgresql/10/main.

service postgresql stop
rm -rf /media/chris/Datenspeicher/*
chown -R postgres:postgres /media/chris/Datenspeicher/
chmod 700 /media/chris/Datenspeicher
/usr/lib/postgresql/10/bin/initdb -D /media/chris/Datenspeicher
rm -rf /media/chris/Datenspeicher/*
sudo rsync -av /var/lib/postgresql/10/main/* /media/chris/Datenspeicher
in postgresql.conf file,  data_directory = '/media/chris/Datenspeicher'
service postgresql start
  • inside /tmp is no file related to postgres your provided tasks are sadly not helping either. its resulting in same error message when trying to connect with psql – Trevirius Jul 5 '18 at 8:29
  • Ok, try to find the file find / -name s.PGSQL.5432 then create the link to /var/run/postgresql/.s.PGSQL.5432 – Bhuvanesh Jul 5 '18 at 8:45
  • sudo find / -name s.PGSQL.5432 --> find / -name s.PGSQL.5432 no access rights so the file cannot be found ? – Trevirius Jul 5 '18 at 8:50
  • run this from root user. – Bhuvanesh Jul 5 '18 at 11:53
  • even su -c 'find / -name s.PGSQL.5432' didn't help to find the file --> resulted in same message as running with sudo – Trevirius Jul 6 '18 at 7:00
0

after a clean ubuntu installation (clean all partiotions), auto mounting my second drive and using the answer from here everything works!

  1. installed postgresql-common via:

    sudo apt install postgresql-common

  2. open createcluster.conf with nano

    sudo nano /etc/postgresql-common/createcluster.conf

  3. uncomment line create_main_cluster = true

  4. change line data_directory = '/var/lib/postgresql/%v/%c' to new/dir/%v/%c

  5. save file

  6. install postgresql via sudo apt install -y postgresql-10

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.