Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
host    all             all             10.0.2.23/24 (Address of remote server)          trustmd5 (scram-sha-256 in version after 10 if needed)

host    replication     all                 10.0.2.22/30   (Address of local server needed after Graceful Switchover)        md5 (scram-sha-256 in version after trust10 if needed)
host    replication     all                 10.0.2.23/30  (Address of remote server)         md5 (scram-sha-256 in version after 10 if trustneeded)

Line 1 of the above code block is just for remote connection. Lines 3 &4 are mainly for replication connections that are for all privileged users (usually postgres or some specific user). Line 3 is a local server address and is mainly used to ensure that the switchback happens without any issues.

...

  1. The location of the configuration files (postgresql.conf, pg_hba.conf, and pg_indent.conf). This location can be different from the primary data directory, but the example below has these two in the same directory. Keeping the same as the primary is recommended, but this can also be different in the standby.

  2. The tablespace location of the primary is in a different location from the default data directory. The above code snippet also shows the permission of these folders.

Image RemovedImage Added

...

  1. The method used for creating the DR cluster (WAL Streaming)

  2. The replication user that is used for streaming connection to the primary cluster. By default, the Postgres user is used. It is recommended to use a different user for establishing this connection. Sample user creation SQL used.

...

  1. SUPERUSER role needed here because only SUPERUSER can retrieve the sync status between primary database and standby database

Code Block
create user repuser replication login encrypted password 'xxxxxx';
alter ROLE repuser SUPERUSER;
  1. The password of the replication user that is used for streaming connection to the primary cluster.

  2. A replication test that can be done to ensure the correct username and password with necessary privileges and the whether the pg_hba.conf updates are correct.

  3. The result of the replication test.

  4. By, default the observer is enabled that will start monitoring the configuration as soon the DR cluster is created.

  5. Click start to start creating the DR cluster using WAL streaming method.

...

The configuration parameter changes done by Dbvisit as part of the DR cluster creation.

PRIMARY:

No changes here

STANDBY:

postgresql.conf

Code Block
#------------------------------------------------------------------------------
# CUSTOMIZED OPTIONS
#------------------------------------------------------------------------------

# Add settings for extensions here

# Added by Dbvisit StandbyMP
# archive_mode = 'off'

# Added by Dbvisit StandbyMP
hot_standby = 'offon'

# Added by Dbvisit StandbyMP
primarylog_conninfodestination = 'user=postgres password=xxxxxx channel_binding=prefer host=centlin72.oraclekiwi.co.nz port=5435 sslmode=prefer sslcompression=0 ssl_min_protocol_version=TLSv1.2 gssencmode=prefer krbsrvname=postgres target_session_attrs=any'stderr'

# Added by Dbvisit StandbyMP
log_directory = 'log'

# Added by Dbvisit StandbyMP
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log'

# Added by Dbvisit StandbyMP
primarylog_slotrotation_nameage = 'dbvisit_31d'

# Added by Dbvisit StandbyMP
datalogging_directorycollector = '/u01/PG5435-13'

STANDBY:

Code Block
#------------------------------------------------------------------------------
# CUSTOMIZED OPTIONS
#------------------------------------------------------------------------------

# Add settings for extensions here

# Added by Dbvisit StandbyMP
# archive_mode = 'off'

# Added by Dbvisit StandbyMP
hot_standby = 'on'

# Added by Dbvisit StandbyMP
primary_conninfo = ''

# Added by Dbvisit StandbyMP
primary_slot_name = ''

# Added by Dbvisit StandbyMP
data_directory = '/u01/PG5435-13'

3. Create DR Cluster using WAL Archive Mode

3.1 Explanation

Below is a detailed explanation of how the DR cluster is created in the background.

...

  1. Trigger CSD in archive mode.

  2. Create Base Backup Files

    • Generate the essential base backup files using the following command (By default Postgres is installed under /usr/pgsql-<version> directory)

      Code Block
      $PG_HOME/bin/pg_basebackup -D tempBackupDir -F tar -X stream -R --progress --verbose 
    • The aforementioned command will generate the subsequent files to be transferred to the Standby to facilitate the cluster restoration process.

      • base.tar: PostgreSQL base files, including settings and etc

      • pg_wal.tar: wal data files for standby to restore

      • tblspc_xxxxx.tar: customized table space files

      • backup_manifest: backup metadata, is used for pg_verifybackup to verify the backup

  3. Tar the following PostgreSQL configuration files on the primary server

    • Postgresql.conf

    • pg_ident.conf

    • pg_hba.conf

  4. Transfer Backup Files from Primary to Standby, which are generated on step 3 and step 2

  5. Data directory setup

    • On the Standby, receive and extract all files generated from Step 2 and Step 3. Place these files in the designated data folder, previously allocated, before initiating CSD.

  6. Config directory setup

    • Extract the files from the tarball received in Step 4 and place them into the target configuration directory on the standby server.

    • Configure PostgreSQL in archive mode as per the Dbvisit DR cluster creation parameter

  7. If the OS is Windows, register the Windows service for the cluster

  8. After configuring the data and config directories, restart the standby PostgreSQL server

  9. Apply Configuration Changes from CSD

    • Applying the latest changes on configuration coming CSD and persisting configuration data on the Control Center

3.2 Steps for creating DR cluster using Archive Mode

To start the DR cluster creation using archive mode

Note

The Primary Cluster will be restarted to enable the archive mode and also provide the location for archive and restore command along with archive timeout parameter. This is updated on postgresql.conf file.

Note

The primary cluster will be restarted even if the archive mode is already enabled to update other parameters.

The creation of the DR cluster can be started either by clicking on Set up now? ( 1 ) or from the ACTIONS menu by clicking on “Set Up Disaster Recovery” ( 2 )

...

The top screen displays the usual configuration details

  1. Configuration name of the PostgreSQL for which DR cluster will be created

  2. The primary hostname and the status of the PostgreSQL cluster (ONLINE)

  3. The standby hostname and also mentioning that no standby cluster exists

  4. The locations of the standby cluster datafiles. This location is recommended to be the same as the primary, but this can be changed and provided a custom location. For Linux the permission of these folders must be like below.

Code Block
-bash-4.2$ ls -lrt /u01
drwx------.  5 postgres postgres  4096 Aug 16 16:41 tablespace
drwx------. 20 postgres postgres  4096 Aug 26 12:06 PG5432-12
  1. The location of the configuration files (postgresql.conf, pg_hba.conf, and pg_indent.conf). This location can be different from the primary data directory, but the example below has these two in the same directory. Keeping the same as the primary is recommended, but this can also be different in the standby.

  2. The tablespace location of the primary is in a different location from the default data directory. The above code snippet also shows the permission of these folders.

  3. The tablespace location of the standby. This folder can also be different from the primary but it is recommended to keep the directory structures same as primary.

...

After this choose the WAL file archiving method with a Hot or Warm standby option.

  1. For this example, a Hot standby is created that can be accessible for reporting purposes as the databases in the cluster are in read only mode.

  2. The WAL file archiving method is used to create the standby cluster.

  3. The location on a primary where the base backup is taken and the location to which it's transferred in the standby. This location provided is a default location but it's recommended to provide a different location to accommodate backups that are larger in size.

  4. The custom backup location of primary and standby in which the WAL archive files are copied in the primary and transferred to standby.

  5. The archive timeout in seconds. This corresponds to the archive_timeout parameter in postgresql.conf. After 60 sec, a checkpoint is forced on primary triggering a WAL archive file creation to sync with the standby. This would ensure that the standby is always 60 seconds behind the primary.

  6. By, default the observer is enabled that will start monitoring the configuration as soon the DR cluster is created.

  7. The primary cluster will be restarted irrespective of whether the archive_mode is off or on in the postgresql.conf file.

  8. Click start to create the DR cluster.

...

After successful completion. The summary displayed will show the time it took to create the DR cluster ( 1 ) and also the step by steps for the DR cluster ( 2 ).

...

The dashboard will now show the following

  1. The configuration is in sync. The standby is in sync with the primary.

  2. The observer is monitoring the configuration.

  3. The method used in creating the DR cluster (WAL file archiving).

  4. The standby status is now “HOT STANDBY”. The standby cluster database is in read-only status.

Image Removed

Below are the parameters that are modified on both Primary and Standby clusters.

PRIMARY:

Code Block
#-------on'

# Added by Dbvisit StandbyMP
primary_conninfo = ''

# Added by Dbvisit StandbyMP
primary_slot_name = ''

# Added by Dbvisit StandbyMP
data_directory = '/u01/PG5435-13'

postgresql.auto.conf

Code Block
primary_conninfo = 'user=postgres password=pg channel_binding=prefer host=postgresql1 port=5434 sslmode=prefer sslcompression=0 sslsni=1 ssl_min_protocol_version=TLSv1.2 gssencmode=prefer krbsrvname=postgres target_session_attrs=any'
primary_slot_name = 'dbvisit_3'

3. Create DR Cluster using WAL Archive Mode

3.1 Explanation

Below is a detailed explanation of how the DR cluster is created in the background.

Drawio
mVer2
zoom1
simple0
inComment0
custContentId3678273563
pageId3673391206
lbox1
diagramDisplayNamecsd archive.drawio
contentVer7
revision7
baseUrlhttps://dbvisit.atlassian.net/wiki
diagramNamecsd archive.drawio
pCenter0
width711
links
tbstyle
height1171

  1. Trigger CSD in archive mode.

  2. Create Base Backup Files

    • Generate the essential base backup files using the following command (By default Postgres is installed under /usr/pgsql-<version> directory)

      Code Block
      $PG_HOME/bin/pg_basebackup -D tempBackupDir -F tar -X stream -R --progress --verbose 
    • The aforementioned command will generate the subsequent files to be transferred to the Standby to facilitate the cluster restoration process.

      • base.tar: PostgreSQL base files, including settings and etc

      • pg_wal.tar: wal data files for standby to restore

      • tblspc_xxxxx.tar: customized table space files

      • backup_manifest: backup metadata, is used for pg_verifybackup to verify the backup

  3. Tar the following PostgreSQL configuration files on the primary server

    • Postgresql.conf

    • pg_ident.conf

    • pg_hba.conf

  4. Transfer Backup Files from Primary to Standby, which are generated on step 3 and step 2

  5. Data directory setup

    • On the Standby, receive and extract all files generated from Step 2 and Step 3. Place these files in the designated data folder, previously allocated, before initiating CSD.

  6. Config directory setup

    • Extract the files from the tarball received in Step 4 and place them into the target configuration directory on the standby server.

    • Configure PostgreSQL in archive mode as per the Dbvisit DR cluster creation parameter

  7. If the OS is Windows, register the Windows service for the cluster

  8. After configuring the data and config directories, restart the standby PostgreSQL server

  9. Apply Configuration Changes from CSD

    • Applying the latest changes on configuration coming CSD and persisting configuration data on the Control Center

3.2 Steps for creating DR cluster using Archive Mode

To start the DR cluster creation using archive mode

Note

The Primary Cluster will be restarted to enable the archive mode and also provide the location for archive and restore command along with archive timeout parameter. This is updated on postgresql.conf file.

Note

The primary cluster will be restarted even if the archive mode is already enabled to update other parameters.

Note

The primary cluster has already been configured with archive backup in archive mode. Setting up a new configuration with Dbvisit DR in archive mode could potentially disrupt the existing backup setup. Therefore, it is advisable to create a backup of the postgresql.conf file if deemed necessary.

The creation of the DR cluster can be started either by clicking on Set up now? ( 1 ) or from the ACTIONS menu by clicking on “Set Up Disaster Recovery” ( 2 )

...

The top screen displays the usual configuration details

  1. Configuration name of the PostgreSQL for which DR cluster will be created

  2. The primary hostname and the status of the PostgreSQL cluster (ONLINE)

  3. The standby hostname and also mentioning that no standby cluster exists

  4. The locations of the standby cluster datafiles. This location is recommended to be the same as the primary, but this can be changed and provided a custom location. For Linux the permission of these folders must be like below.

Code Block
-bash-4.2$ ls -lrt /u01
drwx------.  5 postgres postgres  4096 Aug 16 16:41 tablespace
drwx------. 20 postgres postgres  4096 Aug 26 12:06 PG5432-12
  1. The location of the configuration files (postgresql.conf, pg_hba.conf, and pg_indent.conf). This location can be different from the primary data directory, but the example below has these two in the same directory. Keeping the same as the primary is recommended, but this can also be different in the standby.

  2. The tablespace location of the primary is in a different location from the default data directory. The above code snippet also shows the permission of these folders.

  3. The tablespace location of the standby. This folder can also be different from the primary but it is recommended to keep the directory structures same as primary.

...

After this choose the WAL file archiving method with a Hot or Warm standby option.

  1. For this example, a Hot standby is created that can be accessible for reporting purposes as the databases in the cluster are in read only mode.

  2. The WAL file archiving method is used to create the standby cluster.

  3. The location on a primary where the base backup is taken and the location to which it's transferred in the standby. This location provided is a default location but it's recommended to provide a different location to accommodate backups that are larger in size.

  4. The custom backup location of primary and standby in which the WAL archive files are copied in the primary and transferred to standby.

  5. The archive timeout in seconds. This corresponds to the archive_timeout parameter in postgresql.conf. The archive_timeout specifies the maximum time interval between the completion of a WAL file and its archiving, and also indicates the maximum lag standby (replica) database can potentially fall behind the primary database in terms of the time of changes applied.

  6. By, default the observer is enabled that will start monitoring the configuration as soon the DR cluster is created.

  7. The primary cluster will be restarted irrespective of whether the archive_mode is off or on in the postgresql.conf file.

  8. Click start to create the DR cluster.

...

After successful completion. The summary displayed will show the time it took to create the DR cluster ( 1 ) and also the step by steps for the DR cluster ( 2 ).

...

The dashboard will now show the following

  1. The configuration is in sync. The standby is in sync with the primary.

  2. The observer is monitoring the configuration.

  3. The method used in creating the DR cluster (WAL file archiving).

  4. The standby status is now “HOT STANDBY”. The standby cluster database is in read-only status.

Image Added

Below are the parameters that are modified on both Primary and Standby clusters.

PRIMARY:

Code Block
#---------------------------------------------------------------------------------
# CUSTOMIZED OPTIONS
#------------------------------------------------------------------------------

# Add settings for extensions here

# Added by Dbvisit StandbyMP
archive_command = '"/usr/dbvisit/standbymp/bin/dbvpgarchive" "-configurationId" "6" "-targetAddr" "centlin72.oraclekiwi.co.nz" "-targetPort" "7890" "-sourceFile" "/u01/PG5432-12/%p" "-targetFile" "/u01/backup/PG5432-12/6/%f" "-localAddr" "" "-localPort" "7890" "-pgBin" "/usr/pgsql-12/bin" "-pgData" "/u01/PG5432-12" "-backupFile" "/u01/backup/PG5432-12/6/%f"'

# Added by Dbvisit StandbyMP
archive_mode = 'on'

# Added by Dbvisit StandbyMP
archive_timeout = 60

# Added by Dbvisit StandbyMP
hot_standby = 'off'

# Added by Dbvisit StandbyMP
archive_cleanup_commanddata_directory = '"/usr/pgsql-12/bin/pg_archivecleanup" "/u01/backup/PG5432-12/1" "%r"'

# Added by Dbvisit StandbyMP
data_directory = '/u01/PG5432-12'

# Added by Dbvisit StandbyMP
port = 5432

# Added by Dbvisit StandbyMP
restore_command = '"/usr/dbvisit/standbymp/bin/dbvpgrestore" "-configurationId" "1" "-sourceFile" "/u01/backup/PG5432-12/1/%f" "-targetFile" "%p" "-localAddr" "" "-localPort" "7890" "-pgBin" "/usr/pgsql-12/bin" "-pgData" "/u01/PG5432-12"'

STANDBY:

Code Block
#--------------------------------'

STANDBY:

Code Block
#---------------------------------------------------------------------------------
# CUSTOMIZED OPTIONS
#------------------------------------------------------------------------------

# Add settings for extensions here

# Added by Dbvisit StandbyMP
archive_commandmode = '"/usr/dbvisit/standbymp/bin/dbvpgarchive" "-configurationId" "6" "-targetAddr" "centlin72.oraclekiwi.co.nz" "-targetPort" "7890" "-sourceFile" "/u01/PG5432-12/%p" "-targetFile" "/u01/backup/PG5432-12/6/%f" "-localAddr" "" "-localPort" "7890" "-pgBin" off'

# Added by Dbvisit StandbyMP
archive_timeout = 60

# Added by Dbvisit StandbyMP
hot_standby = 'on'

# Added by Dbvisit StandbyMP
archive_cleanup_command = '"/usr/pgsql-12/bin" "-pgData" "/u01/PG5432-12" "-backupFile/pg_archivecleanup" "/u01/backup/PG5432-12/6/%f" "%r"'

# Added by Dbvisit StandbyMP
archivedata_modedirectory = 'off/u01/PG5432-12'

# Added by Dbvisit StandbyMP
archive_timeoutport = 605432

# Added by Dbvisit StandbyMP
hot_standby = 'on'

# Added by Dbvisit StandbyMP
archive_cleanuprestore_command = '"/usr/dbvisit/pgsql-12standbymp/bin/pg_archivecleanupdbvpgrestore" "-configurationId" "6" "-sourceFile" "/u01/backup/PG5432-12/6/%f" "%r-targetFile"' 
# Added by Dbvisit StandbyMP
data_directory = '/u01/PG5432-12'

# Added by Dbvisit StandbyMP
port = 5432

# Added by Dbvisit StandbyMP
restore_command = '"/usr/dbvisit/standbymp/bin/dbvpgrestore" "-configurationId" "6" "-sourceFile" "/u01/backup/PG5432-12/6/%f" "-targetFile" "%p" "-localAddr" "" "-localPort" "7890" "-pgBin" "/usr/pgsql-12/bin" "-pgData" ""'

...

"%p" "-localAddr" "" "-localPort" "7890" "-pgBin" "/usr/pgsql-12/bin" "-pgData" ""'

4. Create DR Cluster using WAL File shipping Mode

...

  1. The configuration name and the time gap between standby and primary.

  2. The automated standby update is enabled, and also the observer is enabled.

  3. The primary cluster is online

  4. The method using which the standby is synced with primary. In this case its the SHIPPING ( WAL file shipping) method.

  5. The standby cluster status is now “HOT STANDBY,” and the standby cluster databases are accessible via read-only mode.

...

The changes done on postgresql.conf file done by Dbvisit.

PRIMARY:

...

  1. is now “HOT STANDBY,” and the standby cluster databases are accessible via read-only mode.

...

The changes done on postgresql.conf file done by Dbvisit.

PRIMARY:

No changes here

STANDBY:

Code Block
#------------------------------------------------------------------------------
# CUSTOMIZED OPTIONS
#------------------------------------------------------------------------------

# Add settings for extensions here

# Added by Dbvisit StandbyMP
#
archive_mode = 'off'

# Added by Dbvisit StandbyMP
datahot_directorystandby = '/u01/PG5433-12on'

# Added by Dbvisit StandbyMP
hotlog_standbydestination = 'onstderr'

# Added by Dbvisit StandbyMP
log_directory = 'log'

# primary_conninfo Added by Dbvisit StandbyMP
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log'

# Added by Dbvisit StandbyMP
log_rotation_age = '1d'

# archive_mode Added by Dbvisit StandbyMP
logging_collector = 'offon'