I've installed PostgreSQL 9.3 on Centos 7. After installing I could start the system service and login to psql. I want to move the PGDATA folder to another partition, so I tried several things to change DATADIR.
I copied the /var/lib/pgsql/data
folder to /postgresdata/data
, then created a symlink:
systemctl stop postgresql
cp -rp /var/lib/pgsql/data /postgresdata/data
mv /var/lib/pgsql/data /var/lib/pgsql/data.old
ln -s /postgresdata/data /var/lib/pgsql/data
systemctl start postgresql
The folder /postgresdata/
is set to 700 and owner postgres.
This results in the following error:
Job for postgresql.service failed because the control process exited with error code. See "systemctl status postgresql.service" and "journalctl -xe" for details.
I tried two other methods as well, both resulting in the same error:
Method 1: Change postgresql.conf
data_directory = '/postgresdata/data'
Method 2: Change the system service setting:
vim /usr/lib/systemd/system/postgresql.service
Then change:
# Environment=PGDATA=/var/lib/pgsql/data
Environment=PGDATA=/postgresdata/data
Both result in the same error.
When I run journalctl -xe
I get this:
-- Unit postgresql.service has begun starting up.
apr 25 15:08:03 srv001 pg_ctl[15517]: FATAL: could not open file "/postgresdata/data/PG_VERSION": Permission denied
apr 25 15:08:04 srv001 systemd[1]: postgresql.service: control process exited, code=exited status=1
apr 25 15:08:04 srv001 pg_ctl[15517]: pg_ctl: could not start server
apr 25 15:08:04 srv001 pg_ctl[15517]: Examine the log output.
apr 25 15:08:04 srv001 systemd[1]: Failed to start PostgreSQL database server.
-- Subject: Unit postgresql.service has failed
-- Defined-By: systemd
-- Unit postgresql.service has failed.
Looking at /postgresdata/data/PG_VERSION
I see no problems with rights. They're identical to the original it seems.
How can I move the data-folder for PostgreSQL on Centos 7?