Backup and Restoration Control Functions
Backup Control Functions
Backup control functions help with online backup.
- pg_create_restore_point(name text)
Description: Creates a named point for performing the restoration operation (restricted to the system administrator).
Return type: text
Note: pg_create_restore_point creates a named transaction log record that can be used as a restoration target, and returns the corresponding transaction log location. The given name can then be used with recovery_target_name to specify the point up to which restoration will proceed. Avoid creating multiple restoration points with the same name, since restoration will stop at the first one whose name matches the restoration target.
- pg_current_xlog_location()
Description: Obtains the write position of the current transaction log.
Return type: text
Note: pg_current_xlog_location displays the write position of the current transaction log in the same format as those of the previous functions. Read-only operations do not require permissions of the system administrator.
- pg_current_xlog_insert_location()
Description: Obtains the insert position of the current transaction log.
Return type: text
Note: pg_current_xlog_insert_location displays the insert position of the current transaction log. The insertion point is the logical end of the transaction log at any instant, while the write location is the end of what has been written out from the server's internal buffers. The write position is the end that can be detected externally from the server. This operation can be performed to archive only some of completed transaction log files. The insert position is mainly used for commissioning the server. Read-only operations do not require permissions of the system administrator.
- gs_current_xlog_insert_end_location()
Description: Obtains the insert position of the current transaction log.
Return type: text
Note: gs_current_xlog_insert_end_location displays the insert position of the current transaction log.
- pg_start_backup(label text[, fast boolean ])
Description: Starts to perform online backup. (An administrator, replication role, or O&M administrator must enable operation_mode.) Label strings starting with gs_roach are reserved and can be used only by the internal backup tool GaussRoach.
Return type: text
Note: pg_start_backup receives a user-defined backup label (usually the name of the position where the backup dump file is stored). This function writes a backup label file to the data directory of the database cluster and then returns the starting position of backed up transaction logs in text mode.
1 2 3 4 5
gaussdb=# SELECT pg_start_backup('label_goes_here',true); pg_start_backup ----------------- 0/3000020 (1 row)
- pg_stop_backup()
Description: Completes online backup An administrator, replication role, or O&M administrator must enable operation_mode.
Return type: text
Note: pg_stop_backup deletes the label file created by pg_start_backup and creates a backup history file in the transaction log archive area. The history file includes the label given to pg_start_backup, the start and end transaction log locations for the backup, and the start and end time of the backup. The return value is the backup's ending transaction log location. After the end position is calculated, the insert position of the current transaction log automatically goes ahead to the next transaction log file. The ended transaction log file can be immediately archived so that backup is complete.
- pg_switch_xlog()
Description: Switches to a new transaction log file An administrator or O&M administrator must enable operation_mode.
Return type: text
Note: pg_switch_xlog moves to the next transaction log file so that the current log file can be archived (if continuous archive is used). The return value is the ending transaction log location + 1 within the just-completed transaction log file. If there has been no transaction log activity since the last transaction log switchover, pg_switch_xlog does not move but returns the start location of the transaction log file currently in use.
- pg_xlogfile_name(location text)
Description: Converts the position string in a transaction log to a file name.
Return type: text
Note: pg_xlogfile_name extracts only the transaction log file name. If the given transaction log position is the transaction log file border, a transaction log file name will be returned for both the two functions. This is usually the desired behavior for managing transaction log archiving, since the preceding file is the last one that currently needs to be archived.
- pg_xlogfile_name_offset(location text)
Description: Converts the position string in a transaction log to a file name and returns the byte offset in the file.
Return type: text, integer
Note: pg_xlogfile_name_offset can extract transaction log file names and byte offsets from the returned results of the preceding functions. Example:
1 2 3 4 5 6 7
gaussdb=# SELECT * FROM pg_xlogfile_name_offset(pg_stop_backup()); NOTICE: pg_stop_backup cleanup done, waiting for required WAL segments to be archived NOTICE: pg_stop_backup complete, all required WAL segments have been archived file_name | file_offset --------------------------+------------- 000000010000000000000003 | 272 (1 row)
- pg_xlog_location_diff(location text, location text)
Description: Calculates the difference in bytes between two transaction log locations.
Return type: numeric
- pg_cbm_start_tracked_location()
Description: Queries the start LSN parsed by CBM.
Return type: text
- pg_cbm_tracked_location()
Description: Queries the LSN location parsed by CBM.
Return type: text
- pg_cbm_get_merged_file(startLSNArg text, endLSNArg text)
Description: Combines CBM files within the specified LSN range into one and returns the name of the combined file.
Return type: text
Note: Only the system administrator or O&M administrator can obtain the CBM combination file.
- pg_cbm_get_changed_block(startLSNArg text, endLSNArg text)
Description: Combines CBM files within the specified LSN range into a table and return records of this table.
Return type: record
Note: The table columns returned by pg_cbm_get_changed_block include the start LSN, end LSN, tablespace OID, database OID, table relfilenode, table fork number, whether the table is a system catalog, whether the table is deleted, whether the table is created, whether the table is truncated, number of pages in the truncated table, number of modified pages, and list of modified page numbers.
- pg_cbm_recycle_file(targetLSNArg text)
Description: Deletes the CBM files that are no longer used and returns the first LSN after the deletion.
Return type: text
- pg_cbm_force_track(targetLSNArg text,timeOut int)
Description: Forcibly executes the CBM trace to the specified Xlog position and returns the Xlog position of the actual trace end point.
Return type: text
- pg_enable_delay_ddl_recycle()
Description: Enables DDL delay and returns the Xlog position of the enabling point. An administrator or O&M administrator must enable operation_mode.
Return type: text
- pg_disable_delay_ddl_recycle(barrierLSNArg text, isForce bool)
Description: Disables DDL delay and returns the Xlog range where DDL delay takes effect. An administrator or O&M administrator must enable operation_mode.
Return type: record
- pg_enable_delay_xlog_recycle()
Description: Enables the Xlog recycling delay function for CN recovery. An administrator or O&M administrator must enable operation_mode.
Return type: void
- pg_disable_delay_xlog_recycle()
Description: Disables the Xlog recycling delay function for CN recovery. An administrator or O&M administrator must enable operation_mode.
Return type: void
- pg_cbm_rotate_file(rotate_lsn text)
Description: Forcibly switches the file after the CBM parses rotate_lsn. This function is called during the build process.
Return type: void
- gs_roach_stop_backup(backupid text)
Description: Stops a backup started by the internal backup tool GaussRoach. It is similar to the pg_stop_backup system function but is more lightweight.
Return type: text. The content is the insertion position of the current log.
- gs_roach_enable_delay_ddl_recycle(backupid name)
Description: Enables DDL delay and returns the log location of the enabling point. It is similar to the pg_enable_delay_ddl_recycle system function but is more lightweight. In addition, different backupid values can be used to concurrently open DDL statements with delay.
Return type: text. The content is the log location of the start point.
- gs_roach_disable_delay_ddl_recycle(backupid text)
Description: Disables DDL delay, returns the range of logs on which DDL delay takes effect. It is similar to the pg_enable_delay_ddl_recycle system function but is more lightweight. In addition, the DDL delay function can be disabled concurrently by specifying different backupid values.
Return type: record. The content is the range of logs for which DDL is delayed to take effect.
- gs_roach_switch_xlog(request_ckpt bool)
Description: Switches the currently used log segment file and triggers a full checkpoint if request_ckpt is set to true.
Return type: text. The content is the location of the segment log.
- gs_block_dw_io(timeout int, identifier text)
Description: Blocks doublewrite page flushing.
Parameter description:
- timeout
Value range: [0,3600], in seconds. The value 0 indicates that the block duration is 0s.
- identifier
Value range: a string, supporting only uppercase letters, lowercase letters, digits, and underscores (_).
Return type: Boolean
Note: To call this function, the user must have the SYSADMIN or OPRADMIN permission. An O&M administrator must enable operation_mode.
- timeout
- gs_is_dw_io_blocked()
Description: Checks whether disk flushing on the current doublewrite page is blocked. If disk flushing is blocked, true is returned.
Return type: Boolean
Note: To call this function, the user must have the SYSADMIN or OPRADMIN permission. An O&M administrator must enable operation_mode.
- gs_pitr_advance_last_updated_barrier()
Description: In PITR mode, forcibly pushes the global maximum archived recovery point uploaded to OBS/NAS last time to the current point. No input parameter is required.
Return type: text
Note: To call this function, the user must have the SYSADMIN or OPRADMIN permission. An O&M administrator must enable operation_mode. This parameter is valid only on the first normal CN in a distributed system. The return value is the latest local maximum archived recovery point.
- gs_pitr_clean_local_barrier_files('delete_timestamp')
Description: Clears locally cached barrier record files.
Value range: The delete_timestamp parameter is of the text type. It is a Linux timestamp and contains 10 characters.
Return type: text
Note: To call this function, the user must have the SYSADMIN or OPRADMIN permission. An O&M administrator must enable operation_mode. The returned result is the start timestamp of the earliest barrier file on the local host after the deletion.
- gs_get_barrier_lsn(barrier_name text)
Description: Obtains the LSN corresponding to the barrier created using a backup.
Return type: text
Note: Currently, only gs_roach_full and gs_roach_inc are supported. To call this function, the user must have the SYSADMIN or OPRADMIN permission. An O&M administrator must enable operation_mode.
- gs_gbr_relation_associated_filenode(schemaName name, tableName name)
Description: Returns the relfilenode of all indexes, sequences, partitions, TOASTs, and TOAST indexes related to the input table.
Return type: record
Note: The table columns returned by gs_gbr_relation_associated_filenode include the file type relkind, namespace where the file is located, relation name corresponding to the file, OID of the database where the file is located, OID of the tablespace where the file is located, and relfilenode of the file.
- pg_create_physical_replication_slot_extern(slotname text, dummy_standby bool, extra_content text, need_recycle_xlog bool)
Value range of slotname: a string, supporting only lowercase letters, digits, underscores (_), question marks (?), hyphens (-), and periods (.). One or two periods cannot be used alone as the replication slot name. You are advised to use an alphabetic character string as the archive slot name, and the length cannot exceed 64 characters.
Description: Creates an OBS or a NAS archive slot. slotname indicates the name of the archive slot or recovery slot. The primary and standby slots must use the same slot name. dummy_standby is a reserved parameter. extra_content contains some information about the archive slot. For an OBS archive slot, the format is OBS;obs_server_ip;obs_bucket_name;obs_ak;obs_sk;archive_path;is_recovery;is_vote_replicate, in which OBS indicates the archive media of the archive slot, obs_server_ip indicates the IP address of OBS, obs_bucket_name indicates the bucket name, obs_ak indicates the AK of OBS, obs_sk indicates the SK of OBS, archive_path indicates the archive path, and is_recovery specifies whether the slot is an archive slot or a recovery slot (0: archive slot; 1: recovery slot). is_vote_replicate specifies whether the voting copy is archived first. The value 0 indicates that the synchronous standby server is archived first, and the value 1 indicates that the voting copy is archived first. This column is reserved in the current version and is not adapted yet. For a NAS archive slot, the format is NAS;archive_path;is_recovery;is_vote_replicate. Compared with the OBS archive slot, the NAS archive slot does not have the OBS configuration information, while the meanings of other fields are the same.
If the media is not OBS or NAS, the OBS archive slot is used by default. The extra_content format is obs_server_ip;obs_bucket_name;obs_ak;obs_sk;archive_path;is_recovery;is_vote_replicate.
need_recycle_xlog specifies whether to recycle old archived logs when creating an archive slot. The value true indicates that old archived logs are recycled, and the value false indicates that old archive logs are not recycled.
Return type: record contains slotname and xlog_position
Note: Users who call this function must have the SYSADMIN permission or the REPLICATION permission, or inherit the gs_role_replication permission of the built-in role. Currently, multiple archive slots cannot be created.
Examples:
Create an OBS archive slot.
1 2 3 4 5
gaussdb=# SELECT * FROM pg_create_physical_replication_slot_extern('uuid', false, 'OBS;obs.cn-north-7.ulanqab.huawei.com;dyk;19D772JBCACXX3KWS51D;********;gaussdb_uuid/dn1;0;0', false); slotname | xlog_position ----------+--------------- uuid | (1 row)
Create a NAS archive slot.
1 2 3 4
gaussdb=# SELECT * FROM pg_create_physical_replication_slot_extern('uuid', false, 'NAS;/data/nas/media/gaussdb_uuid/dn1;0;0', false); slotname | xlog_position ----------+--------------- uuid |
- gs_set_obs_delete_location(delete_location text)
Description: Sets the location where OBS archive logs can be deleted. The value of delete_location is an LSN. The logs before this location have been replayed and flushed to disks and can be deleted on OBS.
Return type: xlog_file_name text, indicating the file name of the logs that can be deleted. The value of this parameter is returned regardless of whether OBS is deleted successfully.
gaussdb=# SELECT gs_set_obs_delete_location('0/54000000'); gs_set_obs_delete_location ----------------------------- 000000010000000000000054_00 (1 row)
- gs_set_obs_delete_location_with_slotname(cstring, cstring )
Description: Sets the location where OBS archive logs in a specified archive slot can be deleted. The first parameter indicates the LSN. The logs before this location have been replayed and flushed to disks and can be deleted on OBS. The second parameter indicates the name of the archive slot.
Return type: xlog_file_name text, indicating the file name of the logs that can be deleted. The value of this parameter is returned regardless of whether OBS is deleted successfully.
- gs_get_global_barrier_status()
Description: gs_get_global_barrier_status is used to query the latest global barrier archived in OBS by the primary cluster.
Return type: text
global_barrier_id: globally latest barrier ID.
global_achive_barrier_id: globally latest archived barrier ID.
- gs_get_global_barriers_status()
Description: gs_get_global_barriers_status is used to query the latest global barrier archived in OBS by the primary cluster.
Return type: text
slot_name: slot name.
global_barrier_id: globally latest barrier ID.
global_achive_barrier_id: globally latest archived barrier ID.
Restoration Control Functions
Restoration control functions provide information about the status of standby nodes. These functions may be executed both during restoration and in normal running.
- pg_is_in_recovery()
Description: Returns true if restoration is still in progress.
Return type: Boolean
- pg_last_xlog_receive_location()
Description: Obtains the last transaction log location received and synchronized to disk by streaming replication. While streaming replication is in progress, this will increase monotonically. If restoration has been completed, then this value will remain static at the value of the last WAL record received and synchronized to disk during restoration. If streaming replication is disabled or if it has not yet started, the function returns a null value.
Return type: text
- pg_last_xlog_replay_location()
Description: Obtains last transaction log location replayed during restoration. If restoration is still in progress, this will increase monotonically. If restoration has been completed, then this value will remain static at the value of the last WAL record received during that restoration. When the server has been started normally without restoration, the function returns a null value.
Return type: text
- pg_last_xact_replay_timestamp()
Description: Obtains the timestamp of last transaction replayed during restoration. This is the time to commit a transaction or abort a WAL record on the primary node. If no transactions have been replayed during restoration, this function will return a null value. If restoration is still in progress, this will increase monotonically. If restoration has been completed, then this value will remain static at the value of the last WAL record received during that restoration. If the server normally starts without manual intervention, this function will return a null value.
Return type: timestamp with time zone
Restoration control functions control restoration processes. These functions may be executed only during restoration.
- pg_is_xlog_replay_paused()
Description: Returns true if restoration is paused.
Return type: Boolean
- pg_xlog_replay_pause()
Description: Pauses restoration immediately.
Return type: void
- pg_xlog_replay_resume()
Description: Restarts restoration if it was paused.
Return type: void
- gs_get_active_archiving_standby()
Description: Queries information about archive standby nodes in the same shard. The standby node name, archive location, and number of archived logs are returned.
Return type: text, int
- gs_pitr_get_warning_for_xlog_force_recycle()
Description: Checks whether logs are recycled because a large number of logs are stacked in the archive slot after archiving is enabled.
Return type: Boolean
- gs_pitr_clean_history_global_barriers(stop_barrier_timestamp cstring)
Description: Clears all barrier records generated before the specified time. The earliest barrier record is returned. The input parameter is of the cstring type and is a Linux timestamp. You need to perform this operation as an administrator or O&M administrator.
Return type: text
- gs_pitr_archive_slot_force_advance(stop_barrier_timestamp cstring)
Description: Forcibly pushes the archive slot and clears unnecessary barrier records. The new archive slot location is returned. The input parameter is of the cstring type and is a Linux timestamp. You need to perform this operation as an administrator or O&M administrator.
Return type: text
While restoration is paused, no further database changes are applied. In hot standby mode, all new queries will see the same consistent snapshot of the database, and no further query conflicts will be generated until restoration is resumed.
If streaming replication is disabled, the paused state may continue indefinitely without problem. While streaming replication is in progress, WAL records will continue to be received, which will eventually fill available disk space. This progress depends on the duration of the pause, the rate of WAL generation, and available disk space.
- gs_recent_barrier_buffer_info(start_time text, end_time text)
Description: Queries barrier information based on the time range entered by the user to obtain time_stamp, CSN, LSN, and standard_time.
Return type: record
Note: To call this function, you must have the SYSADMIN or OPRADMIN permission. The input parameters start_time and end_time are in the format of year-month-day time, where the time is in the clock format. The maximum query time span is one day. If the time span exceeds the limit, the end time is automatically converted to the limit boundary based on the query start time. Example:gaussdb=# SELECT * FROM gs_recent_barrier_buffer_info('2024-01-15 23:27:50', '2024-01-15 23:28:00'); timestamp | lsn | csn | standard_time ------------+-------------------+----------+--------------------- 1705332470 | 00000000/15FFBBA0 | 41020421 | 2024-01-15 23:27:50 1705332471 | 00000000/15FFBDF0 | 41020422 | 2024-01-15 23:27:51 1705332472 | 00000000/15FFC058 | 41020423 | 2024-01-15 23:27:52 1705332472 | 00000000/15FFC0F8 | 41020424 | 2024-01-15 23:27:52 1705332473 | 00000000/15FFC348 | 41020425 | 2024-01-15 23:27:53 1705332474 | 00000000/15FFC598 | 41020426 | 2024-01-15 23:27:54 1705332475 | 00000000/15FFC638 | 41020427 | 2024-01-15 23:27:55 1705332476 | 00000000/15FFC888 | 41020428 | 2024-01-15 23:27:56 1705332476 | 00000000/15FFDC80 | 41020433 | 2024-01-15 23:27:56 1705332477 | 00000000/15FFDD20 | 41020434 | 2024-01-15 23:27:57 1705332478 | 00000000/15FFDF70 | 41020435 | 2024-01-15 23:27:58 1705332479 | 00000000/15FFE1D8 | 41020436 | 2024-01-15 23:27:59 1705332480 | 00000000/15FFE278 | 41020437 | 2024-01-15 23:28:00 1705332480 | 00000000/15FFE4C8 | 41020438 | 2024-01-15 23:28:00 (14 rows)
- gs_show_obs_media_files(slot_name cstring, src cstring, offset int32, limit int32)
Description: Queries the OBS file list based on the archive slot (slot_name) and OBS directory address (src) entered by the user.
Return type: record
Note: To call this function, you must have the SYSADMIN or OPRADMIN permission. offset indicates the query result offset, and limit indicates the maximum number of output lines. All files in src are queried. Example:gaussdb=# SELECT gs_show_obs_archive_files('ssh','cn_5001/pg_xlog',1, 5); gs_show_obs_archive_files ------------------------------------------------------------------------------------------------- (wstdist_ssh/archive/cn_5001/pg_xlog/000000010000000000000010_01_01_00000000_00000000_00000003) (wstdist_ssh/archive/cn_5001/pg_xlog/000000010000000000000010_02_01_00000000_00000000_00000003) (wstdist_ssh/archive/cn_5001/pg_xlog/000000010000000000000010_03_01_00000000_00000000_00000003) (wstdist_ssh/archive/cn_5001/pg_xlog/000000010000000000000011_00_01_00000000_00000000_00000003) (wstdist_ssh/archive/cn_5001/pg_xlog/000000010000000000000011_01_01_00000000_00000000_00000003) (5 rows)
- gs_upload_obs_media_file(slot_name cstring, src cstring, dest cstring, is_forced bool)
Description: Uploads OBS files based on the archive slot (slot_name), source address (src), OBS address (dest), and whether to forcibly upload files (is_forced).
Return type: void
Note: To call this function, you must have the SYSADMIN or OPRADMIN permission. The original file directory must be the directory specified by $GAUSSLOG. Example:gaussdb=# SELECT * FROM gs_upload_obs_archive_file('ssh', '/data/gauss/log/stwang/test/000000010000000000000019_02_01_00000000_00000000_00000003', 'cn_5001/pg_xlog/000000010000000000000019_02_01_00000000_00000000_00000003', true); gs_upload_obs_archive_file ---------------------------- (1 row)
- gs_download_obs_media_file(slot_name cstring, src cstring, dest cstring)
Description: Downloads OBS files based on the archive slot (slot_name), download source address (src), and local destination address (dest).
Return type: void
Note: To call this function, you must have the SYSADMIN or OPRADMIN permission. The download directory must be the directory specified by $GAUSSLOG. Example:gaussdb=# SELECT * FROM gs_download_obs_archive_file('ssh','cn_5001/pg_xlog/000000010000000000000019_02_01_00000000_00000000_00000003','/data/gauss/log/stwang/test'); gs_download_obs_archive_file ------------------------------ (1 row)
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot