What is a reliable way to change PostgreSQL configuration, especially move its data directory in a script? What is a reliable way to change PostgreSQL configuration, especially move its data directory in a script? docker docker

What is a reliable way to change PostgreSQL configuration, especially move its data directory in a script?


Since you mention apt-get as the way of installing, it means we're talking about PostgreSQL as packaged for Debian and its derivatives.

In Debian, the PostgreSQL data location is set by creating a cluster like this:

# pg_createcluster --datadir=/path/to/data [other options] version name

where version is a major version as in 9.1 and name a short name of your choice identifiying this cluster. It actually puts data structures inside the directory, as opposed to just changing a line in postgresql.conf which by itself would be useless.

When running apt-get install postgresql or a variant implying to install a new PG server, it implicitly creates and starts a cluster whose name is main and datadir is /usr/lib/postgresql/<version>/main

You want to remove that cluster before creating another one to have only one cluster running, example with 9.1:

# pg_dropcluster --stop 9.1 main