Ubuntu 14.04, recently installed Postgres 9.3.
Trying to set up a new data_directory to an attached, larger hard drive (/data), and I changed the postgresql.conf file to reflect that.
However, I get this error when trying to restart the server:
user@server:/etc/postgresql/9.3/main$ sudo /etc/init.d/postgresql restart
* Restarting PostgreSQL 9.3 database server
* Error: pid file is invalid, please manually kill the stale server process.
I don't have too much experience setting up Postgres, so I'm not sure what to do from here, and Googling around provides no quick answer.
Best Answer
Ubuntu and Debian use
pg_wrapper
to manage PostgreSQL. It's in thepostgresql-common
package.(As a result, this answer doesn't apply to RHEL/CentOS/Fedora).
If there's no data of value, you can just use
pg_dropcluster
(part ofpg_wrapper
) to drop (delete) your old datadir. This will destroy all data in it. Then usepg_createcluster
to make a new one in/data
. That's simplest, but of course it's destructive.If you want to retain the data, you must:
postgres
user has at leastx
rights on all directories from the data dir down to the/
directory, especially including the mount point. You may want tochmod a+x
each directory along the path, orchgrp postgres
andchmod g+x
it.mv
the data directory, as shown bypg_lsclusters
, to the desired new location. If you copy it instead, usecp -aRv
to make sure permissions are preserved correctly. Don't just move all contents, move the directory its self./etc/postgresql/mypgversion/postgresql.conf
and changedata_directory
to point to the new data directory location.I think the mistake you made was, in bold above, that you failed to stop PostgreSQL before moving the datadir. It won't stop the server because it isn't sure it'd be killing the right process, so it refuses to act. You must:
then make sure that all PostgreSQL processes have exited (very important) by making sure that this returns no results:
and only then attempt to start the server again.
Never delete
postmaster.pid
.