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

Commit0fd38e1

Browse files
committed
Don't skip SQL backends in logical decoding for visibility computation.
The logical decoding patchset introduced PROC_IN_LOGICAL_DECODING flagPGXACT flag, that allows such backends to be skipped when computingthe xmin horizon/snapshots. That's fine and sensible for walsendersstreaming out logical changes, but not at all fine for SQL backendsdoing logical decoding. If the latter set that flag any change theyhave performed outside of logical decoding will not be regarded asvisible - which e.g. can lead to that change being vacuumed away.Note that not setting the flag for SQL backends isn't particularlybothersome - the SQL backend doesn't do streaming, so it only runs fora limited amount of time.Per buildfarm member 'tick' and Alvaro.Backpatch to 9.4, where logical decoding was introduced.
1 parent75ef435 commit0fd38e1

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

‎contrib/test_decoding/expected/decoding_into_rel.out

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
-- test that we can insert the result of a get_changes call into a
22
-- logged relation. That's really not a good idea in practical terms,
33
-- but provides a nice test.
4+
-- predictability
5+
SET synchronous_commit = on;
46
SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot', 'test_decoding');
57
?column?
68
----------

‎contrib/test_decoding/sql/decoding_into_rel.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
-- test that we can insert the result of a get_changes call into a
22
-- logged relation. That's really not a good idea in practical terms,
33
-- but provides a nice test.
4+
5+
-- predictability
6+
SET synchronous_commit=on;
7+
48
SELECT'init'FROM pg_create_logical_replication_slot('regression_slot','test_decoding');
59

610
-- slot works

‎src/backend/replication/logical/logical.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,19 @@ StartupDecodingContext(List *output_plugin_options,
146146
* logical decoding backend which doesn't need to be checked individually
147147
* when computing the xmin horizon because the xmin is enforced via
148148
* replication slots.
149+
*
150+
* We can only do so if we're outside of a transaction (i.e. the case when
151+
* streaming changes via walsender), otherwise a already setup
152+
* snapshot/xid would end up being ignored. That's not a particularly
153+
* bothersome restriction since the SQL interface can't be used for
154+
* streaming anyway.
149155
*/
150-
LWLockAcquire(ProcArrayLock,LW_EXCLUSIVE);
151-
MyPgXact->vacuumFlags |=PROC_IN_LOGICAL_DECODING;
152-
LWLockRelease(ProcArrayLock);
156+
if (!IsTransactionOrTransactionBlock())
157+
{
158+
LWLockAcquire(ProcArrayLock,LW_EXCLUSIVE);
159+
MyPgXact->vacuumFlags |=PROC_IN_LOGICAL_DECODING;
160+
LWLockRelease(ProcArrayLock);
161+
}
153162

154163
ctx->slot=slot;
155164

‎src/include/storage/proc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ struct XidCache
4343
#definePROC_IN_ANALYZE0x04/* currently running analyze */
4444
#definePROC_VACUUM_FOR_WRAPAROUND0x08/* set by autovac only */
4545
#definePROC_IN_LOGICAL_DECODING0x10/* currently doing logical
46-
* decoding */
46+
* decodingoutside xact*/
4747

4848
/* flags reset at EOXact */
4949
#definePROC_VACUUM_STATE_MASK \

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp