patternsqlMinor
postgresql-setup --initdb with custom data directory
Viewed 0 times
postgresqlinitdbdirectorywithcustomsetupdata
Problem
I am trying to setup Postgres 12 on Centos 8.
Postgres shall be installed in the default directory i.e.
I want to use postgresql-setup as root, as I believe it will create systemd service files along with it, rather than using pg_ctl or running initdb as postgres user.
However, if I try
I will receive the following error.
What is the best way to achieve this?
Postgres shall be installed in the default directory i.e.
/var/lib/pgsql, however I want the data directory to be in /data/pgsqlI want to use postgresql-setup as root, as I believe it will create systemd service files along with it, rather than using pg_ctl or running initdb as postgres user.
However, if I try
$ postgresql-setup --initdb --pgdata=/data/pgsql/I will receive the following error.
postgresql-setup: unrecognized option '--pgdata=/data/pgsql'
FATAL: can't parse argumentsWhat is the best way to achieve this?
Solution
If you wish to place your data in a custom directory
Then get
As mentioned above, just add the
This will create a
To check its content:
Reload systemd:
Initialize the PostgreSQL data directory:
Start and enable the service:
/pgdata/14/data, create the directory with the correct permissions:mkdir -p /pgdata/14/data
sudo chown postgres:postgres /pgdata/14/data
Then get
systemctl to create a service file:sudo systemctl edit postgresql-14.service
As mentioned above, just add the
PGDATA location:[Service]
Environment=PGDATA=/pgdata/14/data
This will create a
/etc/systemd/system/postgresql-14.service.d/override.conf file. This will be merged with the original service file.To check its content:
# cat /etc/systemd/system/postgresql-14.service.d/override.conf
[Service]
Environment=PGDATA=/pgdata/14/data
Reload systemd:
# systemctl daemon-reload
Initialize the PostgreSQL data directory:
sudo /usr/pgsql-14/bin/postgresql-14-setup initdb
Start and enable the service:
sudo systemctl enable postgresql-14
sudo systemctl start postgresql-14
Context
StackExchange Database Administrators Q#292431, answer score: 4
Revisions (0)
No revisions yet.