3

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

asked Jul 5, 2018 at 6:33
7
  • What is the error you get? Commented Jul 5, 2018 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? Commented Jul 5, 2018 at 6:56
  • Did you check the many, many questions with that error message: stackoverflow.com/… Commented Jul 5, 2018 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 Commented Jul 5, 2018 at 7:14
  • Look in the server log file, probably in /var/log/postgres Commented Jul 5, 2018 at 11:45

2 Answers 2

2

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
answered Jul 5, 2018 at 7:19
6
  • 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 Commented Jul 5, 2018 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 Commented Jul 5, 2018 at 8:45
  • sudo find / -name s.PGSQL.5432 --> find / -name s.PGSQL.5432 no access rights so the file cannot be found ? Commented Jul 5, 2018 at 8:50
  • run this from root user. Commented Jul 5, 2018 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 Commented Jul 6, 2018 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

answered Jul 6, 2018 at 12:34

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.