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

link|improve this question
feedback

1 Answer

up vote 3 down vote accepted

Open /etc/postgresql/8.4/main/postgresql.confand 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
link|improve this answer
Note that you must move the data directory (or do a new initdb to create a new cluster) or Postgres will throw a fit... – voretaq7 May 25 '11 at 16:06
1  
Yap, must move or copy data from previous directory to that new before server start (don't try to move or copy data if postmaster is still running using previous dir). – Grzegorz Szpetkowski May 25 '11 at 16:13
2  
yes - stop, move, then restart. Otherwise the universe will end (Or your database will be corrupted beyond the point of repair. Not a good thing either way) – voretaq7 May 25 '11 at 16:15
1  
What is your output from pg_lsclusters command ? – Grzegorz Szpetkowski May 26 '11 at 4:28
1  
If you don't use SSL connections, then simply turn off ssl property in postgresql.conf. If you need SSL, then make symbolic link server.crt in data directory as server.crt -> /etc/ssl/certs/ssl-cert-snakeoil.pem. Also you need root.crt -> /etc/postgresql-common/root.crt and server.key -> /etc/ssl/private/ssl-cert-snakeoil.key as well there. – Grzegorz Szpetkowski May 26 '11 at 5:05
show 7 more comments
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.