4.3. Advanced cloning options

4.3.1. pg_basebackup options when cloning a standby
4.3.2. Managing passwords
4.3.3. Separate replication user
4.3.4. Tablespace mapping

4.3.1. pg_basebackup options when cloning a standby

As ltcluster uses pg_basebackup to clone a standby, it's possible to provide additional parameters for pg_basebackup to customise the cloning process.

By default, pg_basebackup performs a checkpoint before beginning the backup process. However, a normal checkpoint may take some time to complete; a fast checkpoint can be forced with ltcluster standby clone's -c/--fast-checkpoint option. Note that this may impact performance of the server being cloned from (typically the primary) so should be used with care.

Other options can be passed to pg_basebackup by including them in the ltcluster.conf setting pg_basebackup_options.

Not that by default, ltcluster executes pg_basebackup with -X/--wal-method set to stream. From LightDB 21, if replication slots are in use, it will also create a replication slot before running the base backup, and execute pg_basebackup with the -S/--slot option set to the name of the previously created replication slot.

These parameters can set by the user in pg_basebackup_options, in which case they will override the ltcluster default values. However normally there's no reason to do this.

If using a separate directory to store WAL files, provide the option --waldir with the absolute path to the WAL directory. Any WALs generated during the cloning process will be copied here, and a symlink will automatically be created from the main data directory.

See the LightDB pg_basebackup documentation for more details of available options.

4.3.2. Managing passwords

If replication connections to a standby's upstream server are password-protected, the standby must be able to provide the password so it can begin streaming replication.

The recommended way to do this is to store the password in the lightdb system user's ~/.pgpass file. For more information on using the password file, see the documentation section password file.

Note

If using a pgpass file, an entry for the replication user (by default the user who connects to the ltcluster database) must be provided, with database name set to replication, e.g.:

          node1:5432:replication:ltcluster:12345

If, for whatever reason, you wish to include the password in recovery.conf, set use_primary_conninfo_password to true in ltcluster.conf. This will read a password set in PGPASSWORD (but not ~/.pgpass) and place it into the primary_conninfo string in recovery.conf. Note that PGPASSWORD will need to be set during any action which causes recovery.conf to be rewritten, e.g. ltcluster standby follow.

4.3.3. Separate replication user

In some circumstances it might be desirable to create a dedicated replication-only user (in addition to the user who manages the ltcluster metadata). In this case, the replication user should be set in ltcluster.conf via the parameter replication_user; ltcluster will use this value when making replication connections and generating recovery.conf. This value will also be stored in the parameter ltcluster.nodes table for each node; it no longer needs to be explicitly specified when cloning a node or executing ltcluster standby follow.

4.3.4. Tablespace mapping

ltcluster provides a tablespace_mapping configuration file option, which will makes it possible to map the tablespace on the source node to a different location on the local node.

To use this, add tablespace_mapping to ltcluster.conf like this:

  tablespace_mapping='/var/lib/pgsql/tblspc1=/data/pgsql/tblspc1'

where the left-hand value represents the tablespace on the source node, and the right-hand value represents the tablespace on the standby to be cloned.

This parameter can be provided multiple times.