1

I have the following case:

  • the master database has an additional tablespace
  • I'm trying to replicate the master with the pg_basebackup tool
  • the directory / partition layout on the slave is the same as on the master

What parameters should I use to set up replication safely? Do I need to map tablespace with -T parameter or is it only required if I am doing pg_basebackup on the master? pg_basebackup is generaly safe? Data not be deleted from the master?

My command is:

db_slave# pg_basebackup -h db_master -p 5433 -U replication -D /var/lib/postgresql/12/main -P -Xs -Fp -R

But I get:

pg_basebackup: error: directory "/home/db" exists but is not empty
pg_basebackup: removing data directory "/var/lib/postgresql/12/main"

Tablespace is store in /home/db. Thanks a lot for all answers.

1 Answer 1

1

If you use pg_basebackup without -T, it assumes that the tablespace directories are in the same location as on the primary database machine. The documentation states:

As with the main target directory, newdir need not exist already, but if it does exist it must be empty.

If you want to backup the tablespaces to a different location, use the -T option.

2
  • Thank you for your answer. So if I make a backup using pg_basebackup without changing the tablespace location (without -T parameter), they will be placed on the slave server in the same location as on the master server. I understand that they will not be touched on the master?
    – don999
    Commented Nov 21, 2021 at 20:27
  • Yes, they will be placed in the same place on the standby. They will certainly be touched on the primary - but only read. Commented Nov 22, 2021 at 2:57

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.