I want to create a configuration to get a PostgreSQL HA. In my Master I want to configure a postgresql.conf file with this:
archive_command = 'local_backup_script.sh "%p" "%f"'
archive_command = 'cp "%p" /path/to/archive/"%f"'
Then I have a doubt: Where do I have to put the script?
You can put it wherever you like, so long as the
postgres user has permission to execute it, and permission to cd into the directory it’s in.
I usually put it in
/usr/local/bin unless I’m working on a system that has a versioned repository of scripts, in which case it’s in there – something like
I recommend using a fully qualified path to make its location obvious, e.g.
archive_command = '/usr/local/bin/pg_archive_wal.sh "%p" "%f"'
(calling it “backup script” is misleading; it isn’t doing backups at all, it’s just archiving WAL, which may be part of a backup or replication process).
You can put it anywhere that PostgreSQL can find and execute it.
I put it in the data directory itself, because I consider it to be configuration in the same way the postgresql.conf and pg_hba.conf and such are, and want them to be backed up together.
(That is also the directory that will be searched for the script if you don’t specify a path to it. At least on Linux)