Share

Changing PostgreSQL Data Folder (expert users)

Warning:

Local installations of Flow Production Tracking are no longer offered. This documentation is intended only for those with existing instances of Shotgun Enterprise Docker. Click here for a list of our current offerings.

Assumptions

  • The Postgresql version is 15

1. Create the new data folder

First, create the folder in which you want to store the PostgreSQL database.

sudo mkdir /postgres
sudo chown postgres:postgres /postgres

Then, stop the PostgreSQL, if running.

 sudo service postgresql-15 stop

2. Change the folder by copying the old data folder

If you want to copy the existing data folder to a new location, rsync the data to the new location. Skip the rsync if you want to initialize a new data folder. Make sure to omit the trailing slashes for rsync to properly mimic the original directory structure in the destination, including permissions and ownership.

 sudo rsync -av /var/lib/pgsql/15 /postgres 

3. Change the data folder used by PostgreSQL when starting

Customize the systemd configuration for PostgreSQL in order to override the PGDATA folder.

 sudo vi /etc/systemd/system/postgresql-15.service

Insert the following.

# Include the default config:
.include /usr/lib/systemd/system/postgresql-15.service

[Service]
Environment=PGDATA=/postgres

Reload the systemd daemon.

 sudo systemctl daemon-reload

4. Initialize an empty data folder

If you didn’t copy a previous data folder, the new data folder needs to be initialized. First, edit the bootstrap script to set the new PGDATA folder.

 vi postgres_bootstrap_centos7.sh

Edit PGDATA

 export PGDATA=/postgres

Re-run the PostgreSQL bootstrap script

 bash postgres_bootstrap_centos7.sh

PostgreSQL should start using the new folder

 ps aux | grep postgres

Was this information helpful?