文档首页> 数据复制服务 DRS> 实时同步> 同步场景操作参考> GaussDB分布式版为源任务序列值同步
更新时间:2024-06-21 GMT+08:00
分享

GaussDB分布式版为源任务序列值同步

GaussDB分布式版为源任务暂不支持同步序列值,如果同步的表中存在关联的序列,需要在任务结束后,参考以下内容手动同步序列值。

操作步骤

  1. 使用DRS同步任务测试连接时的用户登录GaussDB分布式版实例。
  2. 执行如下语句,查询库中具有管理序列的表及其关联的序列。

    set search_path to '';select d.refobjid::regclass::text as tablename, d.objid::regclass::text as seqname from pg_depend d where d.refclassid='pg_class'::regclass and d.objid in (select oid from pg_class where relkind in ('S','L')) UNION select a.adrelid::regclass::text,d.refobjid::regclass::text from pg_attrdef a JOIN pg_depend d ON (a.oid=d.objid) where d.refobjid in (select oid from pg_class where relkind in ('S','L')) and d.classid='pg_attrdef'::regclass order by tablename, seqname;

  3. 针对每个同步的表关联的序列,使用具有MONADMIN或者SYSADMIN的权限的用户在源库CN节点执行如下语句,查询所有节点对应的最新序列值next_new_val。

    execute direct on all $$select last_value, increment_by, cache_value, (last_value + increment_by * cache_value) as next_new_val from '<seqname>'$$;

    其中<seqname>为2中查询结果中带schema的序列名,查询结果中的next_new_val为last_value + increment_by * cache_value,考虑了序列值缓存的情况,保证序列值不会重复。

  4. 针对每个同步的表关联的序列,参考如下语句在目标库设置新的序列值。

    select setval('<seqname>', <target_value>);

    其中,<target_value>为3中查询出的next_new_val值中的最大值(自增序列,increment_by > 0)或最小值(自减序列,increment_by < 0)。

  5. 检查目标库的序列值。

    针对每个同步的表关联的序列,使用如下语句获取目标库序列的新值。

    select nextval(<seqname>');

    检查得到的结果是否大于等于(自增序列,increment_by > 0)或小于等于(自减序列,increment_by < 0)源库所有节点的序列值。

分享:

    相关文档

    相关产品