更新时间:2024-01-31 GMT+08:00
分享

复制函数

复制函数是系统为实现高可用在各个实例间进行日志同步或数据同步所提供的统计或操作方法。

除统计查询外的复制函数为内部调用函数,不建议用户直接使用。

pg_create_logical_replication_slot('slot_name', 'plugin_name')

描述:创建逻辑复制槽。

参数说明:

  • slot_name

    流复制槽名称。

    取值范围:字符串,不支持除字母,数字,以及(_?-.)以外的字符。

  • plugin_name

    插件名称。

    取值范围:字符串,当前只支持“mppdb_decoding”。

返回值类型:name, text

备注:第一个返回值表示slot_name,第二个返回值表示该逻辑复制槽解码的起始LSN位置。

pg_create_physical_replication_slot ('slot_name', isDummyStandby)

描述:创建物理复制槽。

参数说明:

  • slot_name

    流复制槽名称。

    取值范围:字符串,不支持除字母,数字,以及(_?-.)以外的字符。

  • isDummyStandby

    复制槽是否为从备。

    取值范围:布尔值,支持true或false。

返回值类型:name, text

备注:第一个返回值表示slot_name,第二个返回值表示该物理复制槽解码的起始LSN位置。

pg_get_replication_slots()

描述:显示当前DN上所有的复制槽信息。

返回值类型:record

函数返回信息如下:

表1 pg_get_replication_slots()字段

名称

类型

描述

slot_name

text

复制槽的名称

plugin

name

逻辑复制槽对应的输出插件名

slot_type

text

复制槽的类型

datoid

oid

复制槽的数据库OID

active

boolean

复制槽是否为激活状态

xmin

xid

复制槽事务标识

catalog_xmin

text

逻辑复制槽对应的最早解码事务标识

restart_lsn

text

复制槽的Xlog文件信息

dummy_standby

boolean

复制槽是否为从备

示例:

1
2
3
4
5
SELECT * FROM pg_get_replication_slots();
    slot_name    | plugin | slot_type | datoid | active | xmin | catalog_xmin |    restart_lsn    | dummy_standby
-----------------+--------+-----------+--------+--------+------+--------------+-------------------+---------------
 gs_roach_common |        | physical  |      0 | f      |      |    602861775 | FFFFFFFF/FFFFFFFF | f
(1 row)

pg_drop_replication_slot('slot_name')

描述:删除流复制槽。

参数说明:

  • slot_name

    流复制槽名称。

    取值范围:字符串,不支持除字母,数字,以及(_?-.)以外的字符。

返回值类型:void

pg_logical_slot_peek_changes('slot_name', 'LSN', upto_nchanges, 'options_name', 'options_value')

描述:解码并不推进流复制槽(下次解码可以再次获取本次解出的数据)。

参数说明:

  • slot_name

    流复制槽名称。

    取值范围:字符串,不支持除字母,数字,以及(_?-.)以外的字符。

  • LSN

    日志的LSN,表示只解码小于等于此LSN的日志。

    取值范围:字符串(LSN,格式为xlogid/xrecoff),如'1/2AAFC60'。为NULL时表示不对解码截止的日志位置做限制。

  • upto_nchanges

    解码条数(包含begin和commit)。假设一共有三条事务,分别包含3、5、7条记录,如果upto_nchanges为4,那么会解码出前两个事务共8条记录。解码完第二条事务时发现解码条数记录大于等于upto_nchanges,会停止解码。

    取值范围:非负整数。

    LSN和upto_nchanges中任一参数达到限制,解码都会结束。

  • options:此项为可选参数。
    • include-xids

      解码出的data列是否包含xid信息。

      取值范围:0或1,默认值为1。

      • 0:设为0时,解码出的data列不包含xid信息。
      • 1:设为1时,解码出的data列包含xid信息。
    • skip-empty-xacts

      解码时是否忽略空事务信息。

      取值范围:0或1,默认值为0。

      • 0:设为0时,解码时不忽略空事务信息。
      • 1:设为1时,解码时会忽略空事务信息。
    • include-timestamp

      解码信息是否包含commit时间戳。

      取值范围:0或1,默认值为0。

      • 0:设为0时,解码信息不包含commit时间戳。
      • 1:设为1时,解码信息包含commit时间戳。

返回值类型:text, uint, text

备注:函数返回解码结果,每一条解码结果包含三列,对应上述返回值类型,分别表示LSN位置、xid和解码内容。

pg_logical_slot_get_changes('slot_name', 'LSN', upto_nchanges, 'options_name', 'options_value')

描述:解码并推进流复制槽。

参数说明: 与pg_logical_slot_peek_changes一致,详细内容请参见pg_logical_slot_peek_changes('slot_name', 'LSN', upto_nchanges, 'options_name', 'options_value')

pg_replication_slot_advance ('slot_name', 'LSN')

描述:直接推进流复制槽到指定LSN,不输出解码结果。

参数说明:

  • slot_name

    流复制槽名称。

    取值范围:字符串,不支持除字母,数字,以及(_?-.)以外的字符。

  • LSN

    推进到的日志LSN位置,下次解码时只会输出提交位置比该LSN大的事务结果。如果输入的LSN比当前流复制槽记录的推进位置还要小,则直接返回;如果输入的LSN比当前最新物理日志LSN还要大,则推进到当前最新物理日志LSN。

    取值范围:字符串(LSN,格式为xlogid/xrecoff)。

返回值类型:name, text

备注:返回值分别对应slot_name和实际推进至的LSN。

pg_stat_get_data_senders()

描述:显示当前DN上所有的数据页复制发送线程的统计信息。

返回值类型:record

函数返回信息如下:

表2 pg_stat_get_data_senders()字段

名称

类型

描述

pid

bigint

线程pid

sender_pid

integer

当前sender的pid

local_role

text

本地的角色

peer_role

text

对端的角色

state

text

当前sender的复制状态

catchup_start

timestamp with time zone

catchup启动的时间

catchup_end

timestamp with time zone

catchup结束的时间

queue_size

text

数据队列大小

queue_lower_tail

text

数据队列尾1位置

queue_header

text

数据队列头位置

queue_upper_tail

text

数据队列尾2位置

send_position

text

发送端发送的位置

receive_position

text

接收端接收的位置

catchup_type

text

catchup方式为全量还是增量

catchup_bcm_filename

text

catchup当前执行的bcm文件

catchup_bcm_finished

integer

catchup已操作完成的bcm文件数量

catchup_bcm_total

integer

catchup总共需要操作的bcm文件数量

catchup_percent

text

catchup已经操作完成的百分比

catchup_remaining_time

text

catchup预估剩余时间

pg_stat_get_wal_senders()

描述:显示当前DN上所有的WAL复制发送线程的统计信息。

返回值类型:record

函数返回信息如下:

表3 pg_stat_get_wal_senders()字段

名称

类型

描述

pid

bigint

线程pid

sender_pid

integer

当前sender的pid

local_role

text

本地的角色

peer_role

text

对端的角色

peer_state

text

对端的状态

state

text

当前sender的复制状态

catchup_start

timestamp with time zone

catchup启动的时间

catchup_end

timestamp with time zone

catchup结束的时间

sender_sent_location

text

发送端发送的LSN位置

sender_write_location

text

发送端write的LSN位置

sender_flush_location

text

发送端flush的LSN位置

sender_replay_location

text

发送端replay的LSN位置

receiver_received_location

text

接收端received的LSN位置

receiver_write_location

text

接收端write的LSN位置

receiver_flush_location

text

接收端flush的LSN位置

receiver_replay_location

text

接收端replay的LSN位置

sync_percent

text

同步百分比

sync_state

text

同步状态(异步复制,同步复制,还是潜在同步者)

sync_priority

integer

同步复制的优先级(0表示异步)

sync_most_available

text

在备机同步失败时,是否阻塞主机

channel

text

WALSender的信道信息

pg_stat_get_wal_receiver()

描述:显示当前DN上所有的WAL复制接收线程的统计信息。

返回值类型:record

函数返回信息如下:

表4 pg_stat_get_wal_receiver()

名称

类型

描述

receiver_pid

integer

当前receiver的pid

local_role

text

本地的角色

peer_role

text

远端的角色

peer_state

text

远端的状态

state

text

当前receiver的复制状态

sender_sent_location

text

发送端发送的LSN位置

sender_write_location

text

发送端write的LSN位置

sender_flush_location

text

发送端flush的LSN位置

sender_replay_location

text

发送端replay的LSN位置

receiver_received_location

text

接收端received的LSN位置

receiver_write_location

text

接收端write的LSN位置

receiver_flush_location

text

接收端flush的LSN位置

receiver_replay_location

text

接收端replay的LSN位置

sync_percent

text

同步百分比

channel

text

WALReceiver的信道信息

pg_stat_get_stream_replications()

描述:显示当前DN上所有的复制统计信息。

返回值类型:record

函数返回信息如下:

表5 pg_stat_get_stream_replications()

名称

类型

描述

local_role

text

本地的角色

static_connections

integer

连接统计

db_state

text

数据库状态

detail_information

text

详细信息

示例:

1
2
3
4
5
SELECT * FROM pg_stat_get_stream_replications();
 local_role | static_connections | db_state | detail_information
------------+--------------------+----------+--------------------
 Normal     |                  0 | Normal   | Normal
(1 row)

pg_stat_xlog_space()

描述:显示当前DN上Xlog空间使用信息。

返回值类型:record

函数返回信息如下:

表6 pg_stat_xlog_space()

名称

类型

描述

xlog_files

bigint

pg_xlog目录下,去除backup、archive_status等子目录,所有识别为xlog文件的数目。

xlog_size

bigint

pg_xlog目录下,去除backup、archive_status等子目录,所有识别为xlog文件的文件大小之和,单位为MB。

other_size

bigint

pg_xlog目录下backup、archive_status等子目录文件的大小之和,单位为MB。

示例:

1
2
3
4
5
SELECT * FROM pg_stat_xlog_space();
 xlog_files | xlog_size | other_size
------------+-----------+------------
         79 |      1264 |          0
(1 row)

pgxc_stat_xlog_space()

描述:显示所有主DN上Xlog空间使用信息。

返回值类型:record

函数返回信息如下:

表7 pgxc_stat_xlog_space()

名称

类型

描述

node_name

name

节点名称

xlog_files

bigint

pg_xlog目录下,去除backup、archive_status等子目录,所有识别为xlog文件的数目。

xlog_size

bigint

pg_xlog目录下,去除backup、archive_status等子目录,所有识别为xlog文件的文件大小之和,单位为MB。

other_size

bigint

pg_xlog目录下backup、archive_status等子目录文件的大小之和,单位为MB。

示例:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
 SELECT * FROM  pgxc_stat_xlog_space();
  node_name   | xlog_files | xlog_size | other_size
--------------+------------+-----------+------------
 dn_6001_6002 |         73 |      1168 |          0
 dn_6003_6004 |         73 |      1168 |          0
 dn_6005_6006 |         73 |      1168 |          0
 cn_5003      |         79 |      1264 |          0
 cn_5001      |         72 |      1152 |          0
 cn_5002      |         73 |      1168 |          0
(6 rows)
分享:

    相关文档

    相关产品