Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0f0e253

Browse files
author
Amit Kapila
committed
Fix fetching default toast value during decoding of in-progress transactions.
During logical decoding of in-progress transactions, we perform the toasttable scan while fetching the default toast value for an attribute. Weforgot to initialize the flag during this scan to indicate that the systemtable scan is in progress. We need this flag to ensure that during logicaldecoding we never directly access the tableam or heap APIs because we checkfor concurrent aborts only in systable_* APIs.Reported-by: Alexander LakhinAuthor: Takeshi Ideriha, Hou ZhijieReviewed-by: Amit Kapila, Hou ZhijieBackpatch-through: 14Discussion:https://postgr.es/m/18641-6687273b7f15269d@postgresql.org
1 parent5de77b6 commit0f0e253

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

‎contrib/test_decoding/expected/stream.out

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,28 @@ SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL,NULL, 'incl
106106
committing streamed transaction
107107
(17 rows)
108108

109+
-- Test that accessing a TOAST table in streaming mode is allowed.
110+
-- Create a table with a column that uses a TOASTed default value.
111+
-- (temporarily hide query, to avoid the long CREATE TABLE stmt)
112+
\set ECHO none
113+
SET debug_logical_replication_streaming = immediate;
114+
BEGIN;
115+
INSERT INTO test_tab VALUES(1);
116+
-- Force WAL flush, so that the above changes will be streamed.
117+
SELECT 'force flush' FROM pg_switch_wal();
118+
?column?
119+
-------------
120+
force flush
121+
(1 row)
122+
123+
SELECT count(*) FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1', 'stream-changes', '1');
124+
count
125+
-------
126+
3
127+
(1 row)
128+
129+
COMMIT;
130+
RESET debug_logical_replication_streaming;
109131
DROP TABLE stream_test;
110132
SELECT pg_drop_replication_slot('regression_slot');
111133
pg_drop_replication_slot

‎contrib/test_decoding/sql/stream.sql

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,27 @@ toasted-123456789012345678901234567890123456789012345678901234567890123456789012
4444

4545
SELECT dataFROM pg_logical_slot_get_changes('regression_slot',NULL,NULL,'include-xids','0','skip-empty-xacts','1','stream-changes','1');
4646

47+
-- Test that accessing a TOAST table in streaming mode is allowed.
48+
49+
-- Create a table with a column that uses a TOASTed default value.
50+
-- (temporarily hide query, to avoid the long CREATE TABLE stmt)
51+
\set ECHO none
52+
SELECT'CREATE TABLE test_tab (a text DEFAULT'''|| string_agg('toast value','')||''');'FROM generate_series(1,4000)
53+
\gexec
54+
\set ECHO all
55+
56+
SET debug_logical_replication_streaming= immediate;
57+
58+
BEGIN;
59+
INSERT INTO test_tabVALUES(1);
60+
61+
-- Force WAL flush, so that the above changes will be streamed.
62+
SELECT'force flush'FROM pg_switch_wal();
63+
64+
SELECTcount(*)FROM pg_logical_slot_get_changes('regression_slot',NULL,NULL,'include-xids','0','skip-empty-xacts','1','stream-changes','1');
65+
COMMIT;
66+
67+
RESET debug_logical_replication_streaming;
68+
4769
DROPTABLE stream_test;
4870
SELECT pg_drop_replication_slot('regression_slot');

‎src/backend/access/index/genam.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,14 @@ systable_beginscan_ordered(Relation heapRelation,
703703
index_rescan(sysscan->iscan,key,nkeys,NULL,0);
704704
sysscan->scan=NULL;
705705

706+
/*
707+
* If CheckXidAlive is set then set a flag to indicate that system table
708+
* scan is in-progress. See detailed comments in xact.c where these
709+
* variables are declared.
710+
*/
711+
if (TransactionIdIsValid(CheckXidAlive))
712+
bsysscan= true;
713+
706714
returnsysscan;
707715
}
708716

@@ -747,6 +755,14 @@ systable_endscan_ordered(SysScanDesc sysscan)
747755
index_endscan(sysscan->iscan);
748756
if (sysscan->snapshot)
749757
UnregisterSnapshot(sysscan->snapshot);
758+
759+
/*
760+
* Reset the bsysscan flag at the end of the systable scan. See detailed
761+
* comments in xact.c where these variables are declared.
762+
*/
763+
if (TransactionIdIsValid(CheckXidAlive))
764+
bsysscan= false;
765+
750766
pfree(sysscan);
751767
}
752768

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp