Question

Hi Im running on a centos 7 machine, Im in the process of migrating an old postgres database to the new server, it has like 10TB of data so Im trying it with pg_basebackup. The new server has an independent disk with enough storage to handle the operation, but it's not the primary disk. I would like to set the PGDATA into this big data disk.

I have followed this steps:

  1. Install postgres-12 and postgres12-contrib

  2. Mount the data-disk into the new machine

  3. Create an empty pgdata directory in the data disk. All with user postgres.

  4. Use /usr/bin/pg_basebackup -h IP_OF_OLD_MACHINE -D /mnt/disks/data-disk/pgdata -P -U USERNAME --wal-method=stream

I think pg_basebackup ended successfully, data it took several hours but finished without prompting any error at all.

total 132K
-rw-------. 1 postgres postgres  230 Mar 18 12:36 backup_label
drwx------. 7 postgres postgres 4.0K Mar 18 12:43 base
-rw-------. 1 postgres postgres   30 Mar 19 00:13 current_logfiles
drwx------. 2 postgres postgres 4.0K Mar 19 00:13 global
drwx------. 2 postgres postgres 4.0K Mar 18 12:36 log
drwx------. 2 postgres postgres 4.0K Mar 18 12:36 pg_commit_ts
drwx------. 2 postgres postgres 4.0K Mar 18 12:36 pg_dynshmem
-rw-------. 1 postgres postgres 4.8K Mar 18 12:36 pg_hba.conf
-rw-------. 1 postgres postgres 4.7K Mar 18 12:36 pg_hba.conf~
-rw-------. 1 postgres postgres 1.6K Mar 19 00:13 pg_ident.conf
drwx------. 4 postgres postgres 4.0K Mar 18 12:36 pg_logical
drwx------. 4 postgres postgres 4.0K Mar 18 12:36 pg_multixact
drwx------. 2 postgres postgres 4.0K Mar 18 12:36 pg_notify
drwx------. 2 postgres postgres 4.0K Mar 18 12:36 pg_replslot
drwx------. 2 postgres postgres 4.0K Mar 18 12:36 pg_serial
drwx------. 2 postgres postgres 4.0K Mar 18 12:36 pg_snapshots
drwx------. 2 postgres postgres 4.0K Mar 18 12:36 pg_stat
drwx------. 2 postgres postgres 4.0K Mar 18 12:36 pg_stat_tmp
drwx------. 2 postgres postgres 4.0K Mar 18 12:36 pg_subtrans
drwx------. 2 postgres postgres 4.0K Mar 18 12:36 pg_tblspc
drwx------. 2 postgres postgres 4.0K Mar 18 12:36 pg_twophase
-rw-------. 1 postgres postgres    3 Mar 19 08:27 PG_VERSION
drwx------. 3 postgres postgres 4.0K Mar 18 12:36 pg_wal
drwx------. 2 postgres postgres 4.0K Mar 18 12:36 pg_xact
-rw-------. 1 postgres postgres   88 Mar 18 12:36 postgresql.auto.conf
-rw-------. 1 postgres postgres  24K Mar 19 08:39 postgresql.conf

Ok, now im trying to initialize a postgres server with this data, the one i've just brought.

This are my attempts, looking the documentation:

/usr/pgsql-12/bin/postgresql-12-setup initdb -D /mnt/disks/data-disk/pgdata
systemctl: invalid option -- 'D'
failed to find PGDATA setting in -D.service


/usr/pgsql-12/bin/postgresql-12-setup initdb --pgdata=/mnt/disks/data-disk/pgdata
systemctl: unrecognized option '--pgdata=/mnt/disks/data-disk/pgdata.service'
failed to find PGDATA setting in --pgdata=/mnt/disks/data-disk/pgdata.service

Is there some mistake in the process?

Update: As @pifor told me i added the PATH to the postgres bash_profile and then started to recognize PG_DATA. The problem now is that initdb aims to find an empty folder, and its not empty due to the pg_basebackup

Was it helpful?

Solution

A physical backup (like pg_basebackup) results in an already initialized directory. You don't run initdb. You just start it up, possibly after changing the config files in whatever way is appropriate for your situation.

You probably should have configured this for streaming though with a named slot though, or it will have fallen behind while the backup was being taken, but that would be a different question.

Why not just move the drive array from one server to the other? Is the desire to change the storage hardware as well as the server hardware?

Licensed under: CC-BY-SA with attribution
Not affiliated with dba.stackexchange
scroll top