0

I am planning a move of Postgres' data directory from one disk to another on a CentOS 7 server. All of the data and configuration files reside in /var/lib/pgsql/12/data/.

I have previously migrated data directories before, but this time I am going to migrate the configuration files (postgresql.conf, pg_hba.conf, etc.) from the existing data directory to a new one in /etc. I see that the postgresql.conf file has the following file location configurations, with the caveat that they are driven from the -D option on startup, however startup is managed through systemctl:

#data_directory = 'ConfigDir'
#hba_file = 'ConfigDir/pg_hba.conf'
#ident_file = 'ConfigDir/pg_ident.conf'

So my question is:

Will the changes in postgresql.conf be all that needs to occur so the database starts up after migration -OR- is there something within systemctl that needs to change in tandem with the configuration so it starts up as expected?

asked Jul 27, 2021 at 18:43

1 Answer 1

1

-D and/or PGDATA are really the directory of the config file, despite the misleading names.

You need to change the postgresql.service file (used by systemctl) to point to the new directory of the config file, then change the data_directory line in config file to point back to the new/old location of the "real" data directory.

answered Jul 27, 2021 at 20:27
2
  • I will give this a try and see if this works out. I do happen to see that I don't have an AssertPathExists line within the service file. I know that I can add that by doing a systemctl edit postgresql-12.service, but do I need to modify the line that says Environment=PGDATA=/old/data/directory/ in tandem with this or will the postgresql.conf change handle that part? Commented Jul 27, 2021 at 21:04
  • 1
    I don't know what AssertPathExists is, I'm not much of a systemctl user. PGDATA is the part you need to change. Otherwise, it won't be able to find postgresql.conf in the first place, so couldn't peek inside it if it wanted to, it would never get that far. Make sure that the actual call to start the server uses PGDATA, either implicitly by not mentioning -D at all, or explicitly by something like -D $PGDATA. If there is a -D with a hard-coded directory name, then that is what needs to be changed and PGDATA is not used. You can probably guess how I learned this bitter lesson. Commented Jul 27, 2021 at 21:16

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.