Postgresql – How to run a PostgreSQL outside the standard directories on Linux, ie outside /var/run/postgresql etc

configurationinstallationlinuxpostgresql

I need to be able to run PostgreSQL databases outside the standard installation directories, ie run the existing postgres or pg_ctl process pointing to the alternative ports, configuration and data directories and get it running, with permissions etc working okay.

I don't want it to depend on the existing package based installation setup's structures in /etc/postgresql and /var/run/postgresql and the postgres user, but use their executables if possible.

I will not be using initdb much. The data will be unzipped from other installations. The only thing required is database compatibility with the existing package based installations, which I may be able to install if they are absent. Using executables of my own will be the last resort, due to the possibility of unexpected local dependencies.

Windows appears well covered in that respect with some downloads at EnterpriseDB but there doesn't seem so much available for Linux.

Best Answer

pg_ctl allows for a -D option which allows you to point at your data wherever it is.

I do this all the time for development environments and fun things like setting up intracomputer replication environments for testing. It works fine.

The one thing you really need to be careful about is the configuration. After unzipping you should probably edit the postgresql.conf appropriately.