Postgresql: change default data path
I would like to point the PostgreSQL server to a particular non-default data directory upon startup. Right now, I have to (either manually or in a script) use pg_ctl to stop and restart the database with my /new/path/to/data
.
OS is Ubuntu where the default data directory is /var/lib/postgresql/8.4/main
Solution 1:
Open /etc/postgresql/8.4/main/postgresql.conf
and adjust data_directory property to your new data path and restart the server using (preffered) pg_ctlcluster 8.4 main stop/start
or pg_ctl if you want in that way.
Make sure that /new/path/to/data
is accessible only for postgres user:
chown postgres.postgres /new/path/to/data
chmod 700 /new/path/to/data