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
-
What is the error you get?user1822– user18222018年07月05日 06:54:14 +00:00Commented 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?Trevirius– Trevirius2018年07月05日 06:56:44 +00:00Commented Jul 5, 2018 at 6:56
-
Did you check the many, many questions with that error message: stackoverflow.com/…user1822– user18222018年07月05日 07:02:21 +00:00Commented 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 reainstalledTrevirius– Trevirius2018年07月05日 07:14:43 +00:00Commented Jul 5, 2018 at 7:14
-
Look in the server log file, probably in /var/log/postgresjjanes– jjanes2018年07月05日 11:45:31 +00:00Commented Jul 5, 2018 at 11:45
2 Answers 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
-
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 psqlTrevirius– Trevirius2018年07月05日 08:29:35 +00:00Commented 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
TheDataGuy– TheDataGuy2018年07月05日 08:45:52 +00:00Commented 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 ?Trevirius– Trevirius2018年07月05日 08:50:58 +00:00Commented Jul 5, 2018 at 8:50
-
run this from root user.TheDataGuy– TheDataGuy2018年07月05日 11:53:45 +00:00Commented 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 withsudo
Trevirius– Trevirius2018年07月06日 07:00:36 +00:00Commented Jul 6, 2018 at 7:00
after a clean ubuntu installation (clean all partiotions), auto mounting my second drive and using the answer from here everything works!
installed postgresql-common via:
sudo apt install postgresql-common
open createcluster.conf with nano
sudo nano /etc/postgresql-common/createcluster.conf
uncomment line
create_main_cluster = true
change line
data_directory = '/var/lib/postgresql/%v/%c'
tonew/dir/%v/%c
save file
install postgresql via
sudo apt install -y postgresql-10