Changing the data directory path before the initial configuration of PostgreSQL 10.7.1

Started by Keith Christianover 5 years ago3 messagesgeneral
Jump to latest
#1Keith Christian
keith1christian@gmail.com

Hi Postgres friends,

Using Postgres 10.7.1 on Fedora core 28. Admittedly not the latest
but am helping a colleague with a production system who needs a
PostgreSQL instance on this machine.

The default /var/lib/pgsql/data directory needs to go on another
partition with more space, let's call it /xyz, so the desired data
path during configuration is /xyz/var/lib/pgsql/data.

Is it possible to edit one of the conf files and replace
/var/lib/pgsql/data with /xyz/var/lib/pgsql/data before the
/usr/bin/postgresql-setup --initdb command is run?

Or, does /usr/bin/postgresql-setup --initdb have a command line option
to configure /xyz/var/lib/pgsql/data as the desired data directory?

Thanks.

#2Devrim GÜNDÜZ
devrim@gunduz.org
In reply to: Keith Christian (#1)
Re: Changing the data directory path before the initial configuration of PostgreSQL 10.7.1

Hi,

On Thu, 2020-12-24 at 06:35 -0700, Keith Christian wrote:

Using Postgres 10.7.1 on Fedora core 28.  Admittedly not the latest
but am helping a colleague with a production system who needs a
PostgreSQL instance on this machine.

The default /var/lib/pgsql/data directory needs to go on another
partition with more space, let's call it /xyz, so the desired data
path during configuration is /xyz/var/lib/pgsql/data.

Is it possible to edit one of the conf files and replace
/var/lib/pgsql/data with /xyz/var/lib/pgsql/data before the
/usr/bin/postgresql-setup --initdb command is run?

The easiest way is moving /var/lib/pgsql/data under /xyz directory
(when the db is not running) and create a symlink in the original
location:

chown postgres: /xyz
su - postgres
mv /var/lib/pgsql/data /xyz/10-data
ln -s /xyz/10-data /var/lib/pgsql/data

Then you can use setup script as usual.

Another alternative is creating a copy of the unit file under
/etc/systemd/system, changing $PGDATA inside that file and run the
setup script. This should be documented on the top of the unit file.

-HTH

Regards,

--
Devrim Gündüz
Open Source Solution Architect, Red Hat Certified Engineer
Twitter: @DevrimGunduz , @DevrimGunduzTR

#3Keith Christian
keith1christian@gmail.com
In reply to: Devrim GÜNDÜZ (#2)
Re: Changing the data directory path before the initial configuration of PostgreSQL 10.7.1

The easiest way is moving /var/lib/pgsql/data under /xyz directory
(when the db is not running) and create a symlink in the original
location:

chown postgres: /xyz
su - postgres
mv /var/lib/pgsql/data /xyz/10-data
ln -s /xyz/10-data /var/lib/pgsql/data

Then you can use setup script as usual.

Another alternative is creating a copy of the unit file under
/etc/systemd/system, changing $PGDATA inside that file and run the
setup script. This should be documented on the top of the unit file.

Devrim,

Appreciate your quick reply and complete insructions, I'm certain that will
work!

Thank you.