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?
1 Answer 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.
-
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 asystemctl edit postgresql-12.service
, but do I need to modify the line that saysEnvironment=PGDATA=/old/data/directory/
in tandem with this or will thepostgresql.conf
change handle that part?vPilot– vPilot2021年07月27日 21:04:08 +00:00Commented Jul 27, 2021 at 21:04 -
1I 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.jjanes– jjanes2021年07月27日 21:16:19 +00:00Commented Jul 27, 2021 at 21:16
Explore related questions
See similar questions with these tags.