已关闭
[Bug]: shark pg_identity_dump_restore用例中D兼容库identity列dump/restore失败 #8403
liyangx创建于  8月17日关闭于  23 天前
liyangx成员
8月17日 创建

内部开发

测试类型

SQL功能

测试版本

7.0.0LTS

问题描述

涉及问题引入PR:https://gitcode.com/opengauss/openGauss-server/pull/9137

问题一: shark 的 pg_identity_dump_restore 用例发现 D 兼容库下 identity 列 dump/restore 失败(修复后请放开 contrib/shark/parallel_schedule 中 pg_identity_dump_restore 用例)

D 兼容库中创建包含 identity 列的表可以成功,数据也可以正常插入;但使用 gs_dump 导出后,再通过 gsql/gs_restore 恢复到另一个 D 兼容库时,恢复过程中报错。

gs_dump 生成的 D identity 恢复语句包含当前 D identity 语法不支持的 sequence 选项:

ALTER TABLE public.book ALTER COLUMN bookid ADD IDENTITY (
    1, 1, public.book_bookid_seq_identity
    CACHE 1
);

恢复时报错:

ERROR: syntax error at or near "CACHE"

随后由于 identity sequence 未创建成功,又触发后续错误:

ERROR: relation "book_bookid_seq_identity" does not exist

最终导致 book.bookid 未恢复为 identity 列,后续插入数据失败。
分析:pg_dump.cpp 中为 D identity sequence 增加了 seqofDIdentity 处理分支,生成 ALTER COLUMN ... ADD IDENTITY(start, increment, sequence_name) 形式的恢复语句。但该分支后续仍复用了普通 sequence 的选项输出逻辑,继续拼接了 CACHE 等 sequence 选项。当前 shark D identity 语法只支持:

IDENTITY
IDENTITY(start, increment)
IDENTITY(start, increment, sequence_name)

不支持在 ADD IDENTITY 参数中携带 CACHE 子句,因此 dump 产物在恢复端无法解析。

============================================================================

问题二:server 仓 shark 中 gs_dump_d_format 用例暴露问题(修复后请放开 contrib/shark/parallel_schedule 中 gs_dump_d_format 用例)

D兼容库中创建包含 identity 列的表可以成功,数据也可以正常插入;但使用 gs_dump 导出后,再通过 gs_restore 恢复到另一个 D兼容库时,恢复过程中报错,导致 gs_restore 返回码为 1。
失败原因是 gs_dump 生成的 identity 恢复语句在恢复端无法解析:

ALTER TABLE public.table_ident ALTER COLUMN id ADD IDENTITY  (
    1, 1, public.table_ident_id_seq_identity
    CACHE 1
    SESSION
);

恢复时报错:

ERROR: syntax error at or near "CACHE"

随后由于 identity sequence 未创建成功,又触发:

ERROR: relation "table_ident_id_seq_identity" does not exist

操作系统和硬件信息

不限

测试环境

企业版单机

被测功能

验证 shark 用例:pg_identity_dump_restore、gs_dump_d_format

预置条件

操作步骤

问题一:check 用例 pg_identity_dump_restore

================================================================

问题二:

  1. 创建源库和恢复库:
drop database if exists dump_id_repro;
drop database if exists restore_id_repro;
create database dump_id_repro with dbcompatibility 'D';
create database restore_id_repro with dbcompatibility 'D';
  1. 在源库创建 shark 扩展、建 identity 表并插入数据:
\c dump_id_repro
create extension if not exists shark;
set d_format_behavior_compat_options = 'enable_sbr_identifier';

create table table_ident(id int identity, name char(20));
insert into table_ident values('aaa'),('bbb'),('ccc');

select * from table_ident;
  1. 执行导出和恢复:
gs_dump dump_id_repro -p 14541 -f /tmp/dump_id_repro.tar -F t
echo "dump rc=$?"

gs_restore -d restore_id_repro -p 14541 /tmp/dump_id_repro.tar
echo "restore rc=$?"

预期输出

正常 ok

实际输出

问题一:diffs

==========================================

问题二:

gs_dump 成功,gs_restore 也应成功,返回码为 0。
恢复库中 table_ident 表应创建成功,identity 属性和对应 sequence 应恢复成功,数据可正常查询。

\c restore_id_repro
\d+ table_ident
select * from table_ident;

日志信息

问题一:用例diffs

======================================================================

*** /home/tester2/sda/openGauss-server-ob-ai/contrib/shark/expected/pg_identity_dump_restore.out.smartmatch	2026-08-14 15:49:23.691307965 +0800
--- /home/tester2/sda/openGauss-server-ob-ai/contrib/shark/results/pg_identity_dump_restore.out	2026-08-14 15:49:21.947287941 +0800
***************
*** 43,50 ****
  SET
  CREATE TABLE
  ALTER TABLE
! ALTER TABLE
! ALTER SEQUENCE
  CREATE TABLE
  ALTER TABLE
  ALTER TABLE
--- 43,52 ----
  SET
  CREATE TABLE
  ALTER TABLE
! gsql:/home/tester2/sda/openGauss-server-ob-ai/contrib/shark/tmp_check/install/home/tester2/sda/openGauss-server-ob-ai/mppdb_temp_install/bin/s_test_pg_identity_dump_restore.sql:72: ERROR:  syntax error at or near "CACHE"
! LINE 2:     CACHE 1
!             ^
! gsql:/home/tester2/sda/openGauss-server-ob-ai/contrib/shark/tmp_check/install/home/tester2/sda/openGauss-server-ob-ai/mppdb_temp_install/bin/s_test_pg_identity_dump_restore.sql:79: ERROR:  relation "book_bookid_seq_identity" does not exist
  CREATE TABLE
  ALTER TABLE
  ALTER TABLE
***************
*** 52,62 ****
  ALTER TABLE
  ALTER TABLE
  ALTER TABLE
!  setval 
! --------
!       4
! (1 row)
! 
   setval 
  --------
       22
--- 54,63 ----
  ALTER TABLE
  ALTER TABLE
  ALTER TABLE
! gsql:/home/tester2/sda/openGauss-server-ob-ai/contrib/shark/tmp_check/install/home/tester2/sda/openGauss-server-ob-ai/mppdb_temp_install/bin/s_test_pg_identity_dump_restore.sql:170: ERROR:  relation "book_bookid_seq_identity" does not exist
! LINE 1: SELECT pg_catalog.setval('book_bookid_seq_identity', 4, true...
!                                  ^
! CONTEXT:  referenced column: setval
   setval 
  --------
       22
***************
*** 72,78 ****
      102
  (1 row)
  
! 
  \c s_test_pg_identity_dump_restore_1
  set current_schema = s_test_pg_identity_dump_restore;
  \d+ test_t1
--- 73,79 ----
      102
  (1 row)
  
! total time: 265  ms
  \c s_test_pg_identity_dump_restore_1
  set current_schema = s_test_pg_identity_dump_restore;
  \d+ test_t1
***************
*** 102,108 ****
                                     Table "s_test_pg_identity_dump_restore.book"
    Column  |     Type      |                   Modifiers                   | Storage  | Stats target | Description 
  ----------+---------------+-----------------------------------------------+----------+--------------+-------------
!  bookid   | integer       | not null identity                             | plain    |              | 
   bookname | nvarchar2(50) | character set UTF8 collate utf8mb4_general_ci | extended |              | 
   author   | nvarchar2(50) | character set UTF8 collate utf8mb4_general_ci | extended |              | 
  Has OIDs: no
--- 103,109 ----
                                     Table "s_test_pg_identity_dump_restore.book"
    Column  |     Type      |                   Modifiers                   | Storage  | Stats target | Description 
  ----------+---------------+-----------------------------------------------+----------+--------------+-------------
!  bookid   | integer       | not null                                      | plain    |              | 
   bookname | nvarchar2(50) | character set UTF8 collate utf8mb4_general_ci | extended |              | 
   author   | nvarchar2(50) | character set UTF8 collate utf8mb4_general_ci | extended |              | 
  Has OIDs: no
***************
*** 118,124 ****
--- 119,131 ----
  INSERT INTO test_t2 DEFAULT VALUES;
  INSERT INTO test_t2 DEFAULT VALUES;
  INSERT INTO book VALUES('book1','author1'),('book2','author2');
+ ERROR:  invalid input syntax for integer: "book1"
+ LINE 1: INSERT INTO book VALUES('book1','author1'),('book2','author2...
+                                 ^
+ CONTEXT:  referenced column: bookid
  INSERT INTO book(bookname,author) VALUES('book3','author3'),('book4','author4');
+ ERROR:  null value in column "bookid" violates not-null constraint
+ DETAIL:  Failing row contains (null, book3, author3).
  select * from test_t1 order by 1, 2;
   a  | b 
  ----+---
***************
*** 134,147 ****
  (2 rows)
  
  select * from book order by 1, 2;
!  bookid | bookname | author  
! --------+----------+---------
!       1 | book1    | author1
!       2 | book2    | author2
!       3 | book3    | author3
!       4 | book4    | author4
! (4 rows)
  
  \c postgres
  drop database s_test_pg_identity_dump_restore;
! drop database s_test_pg_identity_dump_restore_1;
\ No newline at end of file
--- 141,150 ----
  (2 rows)
  
  select * from book order by 1, 2;
!  bookid | bookname | author 
! --------+----------+--------
! (0 rows)
  
  \c postgres
  drop database s_test_pg_identity_dump_restore;
! drop database s_test_pg_identity_dump_restore_1;

======================================================================

===========================================================================

问题二:

①执行失败截图:
5b62a69d5f1b001cabcf1a21f69976d0.png

②失败日志:

[tester2@openGauss58 sda]$ gs_dump dump_id_repro -p 14541 -f /tmp/dump_id_repro.tar -F t
gs_dump[port='14541'][dump_id_repro][2026-08-14 23:48:44]: Begin scanning database.
Progress: [==================================================] 100% (38/38, cur_step/total_step). finish scanning database
gs_dump[port='14541'][dump_id_repro][2026-08-14 23:48:44]: Finish scanning database.
gs_dump[port='14541'][dump_id_repro][2026-08-14 23:48:44]: Start dumping objects
Progress: [                                                  ] 0% (0/6114, dumpObjNums/totalObjNums). dump objecProgress: [==================================================] 100% (6114/6114, dumpObjNums/totalObjNums). dump objects
gs_dump[port='14541'][dump_id_repro][2026-08-14 23:48:44]: Finish dumping objects
gs_dump[port='14541'][dump_id_repro][2026-08-14 23:48:44]: dump database dump_id_repro successfully
gs_dump[port='14541'][dump_id_repro][2026-08-14 23:48:44]: total time: 275  ms
[tester2@openGauss58 sda]$ echo dump_rc=$?
dump_rc=0
[tester2@openGauss58 sda]$ gs_restore -d restore_id_repro -p 14541 /tmp/dump_id_repro.tar
start restore operation ...
Progress: [============                                      ] 25% (3/12, restored_entries/total_entries). restoError while PROCESSING TOC:
Error from TOC entry 578; 1259 18696 TABLE table_ident tester2
could not execute query: ERROR:  cache lookup failed for type 0
    Command was: CREATE TABLE table_ident (
    id integer NOT NULL,
    name character(20)
)
WITH (orientation=row, compression=no);



could not execute query: ERROR:  relation "public.table_ident" does not exist
    Command was: ALTER TABLE public.table_ident OWNER TO tester2;



Error from TOC entry 577; 1259 18694 SEQUENCE table_ident_id_seq_identity tester2
could not execute query: ERROR:  syntax error at or near "CACHE"
LINE 2:     CACHE 1
            ^
    Command was: ALTER TABLE public.table_ident ALTER COLUMN id ADD IDENTITY  (1, 1, public.table_ident_id_seq_identity
    CACHE 1
    SESSI...
Error from TOC entry 6123; 0 0 LARGE SEQUENCE OWNED BY table_ident_id_seq_identity tester2
could not execute query: ERROR:  relation "table_ident_id_seq_identity" does not exist
    Command was: ALTER  SEQUENCE table_ident_id_seq_identity OWNED BY table_ident.id;



Error from TOC entry 6112; 0 18696 TABLE DATA table_ident tester2
could not execute query: ERROR:  relation "public.table_ident" does not exist
    Command was: COPY public.table_ident (id, name) FROM stdin;

Error from TOC entry 6124; 0 0 SEQUENCE SET table_ident_id_seq_identity tester2
could not execute query: ERROR:  relation "table_ident_id_seq_identity" does not exist
LINE 1: SELECT pg_catalog.setval('table_ident_id_seq_identity', 3, t...
                                 ^
CONTEXT:  referenced column: setval
    Command was: SELECT pg_catalog.setval('table_ident_id_seq_identity', 3, true);



Progress: [==================================================] 100% (12/12, restored_entries/total_entries). restore entires
end restore operation ...
WARNING: errors ignored on restore: 6
restore operation successful
total time: 776  ms
[tester2@openGauss58 sda]$ echo restore_rc=$?
restore_rc=1
[tester2@openGauss58 sda]$

③用例diffs:
66f5eebe-30f0-41ed-a781-534f57456c67.png

提单组织

内部开发

测试代码

shark扩展下 pg_identity_dump_restore 、gs_dump_d_format用例

likedislike
Lliyangx成员
8月17日 添加了label:bug
opengauss_bot
opengauss_bot成员
8月17日 评论:

This issue requires an assignee. Since you haven't specified one, we've assigned TestManager as the default assignee for this issue.

likedislike
opengauss_botopengauss_bot成员
8月17日 将 TestManager 设为负责人
opengauss_botopengauss_bot成员
8月17日 添加了label:sig/StorageEngine,sig/AI,sig/CM,sig/CloudNative,sig/SecurityTechnology,sig/SQLEngine
opengauss_bot
opengauss_bot成员
8月17日 评论:

Welcome To openGauss Community

Hey @liyangx , thanks for your contribution to the community.

Bot Usage Manual

I'm the Bot here serving you. You can find the instructions on how to interact with me at Here . That means you can comment below every pull request or issue to trigger Bot Commands.

Contact Guide

If you have any questions, please contact the SIG: StorageEngine, AI, CM, CloudNative, SecurityTechnology, SQLEngine ,
and any of the maintainers: @CarrotGo, @chendong76, @chenxiaobin19, @congzhou2603, @dodders, @hwworkholic, @jemappellehc, @muyulinzhong, @quemingjian, @shenzheng4, @shirley_zhengx, @superlchf, @totaj, @wlff234, @wofanzheng, @ywzq1161327784 ,
and any of the committers: @Igali, @bihua111, @cailei19, @h_ray, @levy53071, @libiao2024, @lihaixiao, @mrzack, @wangfeihuo, @wuyuechuan, @xiong_xjun, @zhangfengzhi123, @zhangxubo, @zhangzq131, @zjh_hw .

likedislike
Lliyangx成员
8月17日 修改标题为 “[Bug]: shark pg_identity_dump_restore用例中D兼容库identity列dump/restore失败”,原标题为“[Bug]: shark用例由于PR导致差异”
Lliyangx成员
8月17日 修改了issue 的描述
Lliyangx成员
8月17日 修改了issue 的描述
ywzq1161327784ywzq1161327784成员
8月17日 关联了看板:openGauss 7.0.0-LTS
XXXCAXXXCA
8月17日 关联了pull request:fix: shark testcase result
ywzq1161327784ywzq1161327784成员
29 天前 issue状态由 待办的 改变为 已完成
chendong76chendong76成员
28 天前 issue状态由 已完成 改变为 待回归
sungang14
sungang14成员
23 天前 评论:

【回归人员】sungang14
【回归日期】20260824
【回归版本】openGauss7.0.0master
【回归结论】通过
【回归步骤】
1、shark 用例中pg_identity_dump_restore用例执行通过
2、server 仓 shark 中 gs_dump_d_format 用例执行通过
image.png
image.png

likedislike
sungang14sungang14成员
23 天前 issue状态由 待回归 改变为 已验收
sungang14sungang14成员
23 天前 关闭了 issue