You need to enable JavaScript to run this app.
导航

逻辑解析(pg_decoderbufs)

最近更新时间2023.08.09 12:30:31

首次发布时间2023.08.08 23:52:58

pg_decoderbufs 是一款以 protocol buffer 格式进行逻辑解析的插件。

使用限制

pg_decoderbufs 只能对 DML (Delete、Update、Insert )进行逻辑解析,解析结果为 protocol buffer 格式。

插件选项

Options 名称debug-mode
含义在进行逻辑解码后,将解码结果以字符模式输出。

使用示例

select * from pg_logical_slot_peek_changes('demo', null, null, 'debug-mode', '1');
select * from pg_logical_slot_get_changes('demo', null, null, 'debug-mode', '1');

说明

关于 pg_logical_slot_peek_changespg_logical_slot_get_changes 函数的定义,可以通过如下 SQL 查询:

  • select * from pg_proc where proname = 'pg_logical_slot_peek_changes';
  • select * from pg_proc where proname = 'pg_logical_slot_get_changes';

映射关系

PostgreSQL 类型与 decoderbuf 字段的映射信息如下:

PostgreSQL Type OIDDecoderbuf Field
BOOLOIDdatum_boolean
INT2OIDdatum_int32
INT4OIDdatum_int32
INT8OIDdatum_int64
OIDOIDdatum_int64
FLOAT4OIDdatum_float
FLOAT8OIDdatum_double
NUMERICOIDdatum_double
CHAROIDdatum_string
VARCHAROIDdatum_string
BPCHAROIDdatum_string
TEXTOIDdatum_string
JSONOIDdatum_string
XMLOIDdatum_string
UUIDOIDdatum_string
TIMESTAMPOIDdatum_string
TIMESTAMPTZOIDdatum_string
BYTEAOIDdatum_bytes
POINTOIDdatum_point
PostGIS geometrydatum_point
PostGIS geographydatum_point

插件的使用

前置条件

  • 已将 wal_level 设置成 logical

  • 待逻辑解析的表有唯一索引、主键或者已经指定 REPLICA IDENTITY

使用插件

  1. 创建发布,并指定逻辑解析插件为 decoderbufs

    select pg_create_logical_replication_slot('demo', 'decoderbufs');
    
  2. 开启读写,并以 debug-mode 模式,查看逻辑解析。

    select * from pg_logical_slot_peek_changes('demo', null, null, 'debug-mode', '1');
    select * from pg_logical_slot_get_changes('demo', null, null, 'debug-mode', '1');
    select * from pg_replication_slots;