From 366d81a8fd37db5d63f3b94797cfe9e1a9dfd986 Mon Sep 17 00:00:00 2001 From: xue_meng_en <1836611252@qq.com> Date: Tue, 22 Mar 2022 17:49:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dgs=5Fdump=E5=A4=87=E4=BB=BD?= =?UTF-8?q?=E5=90=8E=E5=BA=8F=E5=88=97=E5=80=BC=E9=80=92=E5=A2=9E=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/bin/pg_dump/pg_dump.cpp | 23 +++++++++++++++++++++++ src/test/regress/input/gs_dump.source | 1 + src/test/regress/output/gs_dump.source | 6 ++++++ 3 files changed, 30 insertions(+) diff --git a/src/bin/pg_dump/pg_dump.cpp b/src/bin/pg_dump/pg_dump.cpp index 1a42a86b..7e0a942a 100644 --- a/src/bin/pg_dump/pg_dump.cpp +++ b/src/bin/pg_dump/pg_dump.cpp @@ -20836,6 +20836,7 @@ static void dumpSequenceData(Archive* fout, TableDataInfo* tdinfo, bool large) called = (strcmp(PQgetvalue(res, 0, 4), "t") == 0); #ifdef PGXC +#ifdef ENABLE_MULTIPLE_NODES /* * In Postgres-XC it is possible that the current value of a * sequence cached on each node is different as several sessions @@ -20897,6 +20898,28 @@ static void dumpSequenceData(Archive* fout, TableDataInfo* tdinfo, bool large) ExecuteSqlStatement(fout, "ROLLBACK TO SAVEPOINT bfnextval"); ExecuteSqlStatement(fout, "RELEASE bfnextval"); +#else + resetPQExpBuffer(query); + PQclear(res); + appendPQExpBuffer(query, "SELECT last_value, is_called FROM %s;", fmtId(tbinfo->dobj.name)); + res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); + + if (PQntuples(res) != 1) { + write_msg(NULL, + ngettext("query to get nextval of sequence %s " + "returned %d rows (expected 1)\n", + "query to get nextval of sequence %s " + "returned %d rows (expected 1)\n", + PQntuples(res)), + fmtId(tbinfo->dobj.name), + PQntuples(res)); + PQclear(res); + destroyPQExpBuffer(query); + exit_nicely(1); + } + last = PQgetvalue(res, 0, 0); +#endif + #endif resetPQExpBuffer(query); diff --git a/src/test/regress/input/gs_dump.source b/src/test/regress/input/gs_dump.source index aab8ae23..553cd04d 100644 --- a/src/test/regress/input/gs_dump.source +++ b/src/test/regress/input/gs_dump.source @@ -54,5 +54,6 @@ ALTER TABLE rlsrel1 FORCE ROW LEVEL SECURITY; ALTER TABLE rlsrel2 ENABLE ROW LEVEL SECURITY; \! @abs_bindir@/gs_dump --help > @abs_bindir@/gs_dump.log 2>&1 \! @abs_bindir@/gs_dump basedb -p @portstring@ --with-encryption=AES128 --with-key=abcdefghigklmnop --include-alter-table -n dumptest -s > @abs_bindir@/dump.sql 2>&1 ; echo $? +SELECT * FROM dumptest."seq$"; \c regression drop database if exists basedb; diff --git a/src/test/regress/output/gs_dump.source b/src/test/regress/output/gs_dump.source index 86e06719..465d37db 100644 --- a/src/test/regress/output/gs_dump.source +++ b/src/test/regress/output/gs_dump.source @@ -57,5 +57,11 @@ ALTER TABLE rlsrel2 ENABLE ROW LEVEL SECURITY; \! @abs_bindir@/gs_dump --help > @abs_bindir@/gs_dump.log 2>&1 \! @abs_bindir@/gs_dump basedb -p @portstring@ --with-encryption=AES128 --with-key=abcdefghigklmnop --include-alter-table -n dumptest -s > @abs_bindir@/dump.sql 2>&1 ; echo $? 0 +SELECT * FROM dumptest."seq$"; + sequence_name | last_value | start_value | increment_by | max_value | min_value | cache_value | log_cnt | is_cycled | is_called | uuid + ---------------+------------+-------------+--------------+---------------------+-----------+-------------+---------+-----------+-----------+------ + seq$ | 101 | 101 | 1 | 9223372036854775807 | 1 | 1 | 0 | f | f | 0 + (1 row) + \c regression drop database if exists basedb;