forked from yugabyte/yugabyte-db
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support generic WAL messages for logical decoding
This feature allows software to insert data into WAL stream that can be read by wal2json. Those messages could be useful to control replication, for example. Messages can be sent as transactional or not. Non-transactional messages mean that it is sent even if the transaction is rollbacked. There was a PR yugabyte#20 for this same feature but I didn't use it. Indeed, this code was dusty in my computer for a few months. NOTE: 'message' test will fail on <= 9.5 because this feature was coded in 9.6 (I don't want to complicate Makefile).
- Loading branch information
Euler Taveira
committed
Aug 22, 2017
1 parent
2828409
commit 645ab69
Showing
4 changed files
with
273 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
\set VERBOSITY terse | ||
-- predictability | ||
SET synchronous_commit = on; | ||
SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot', 'wal2json'); | ||
?column? | ||
---------- | ||
init | ||
(1 row) | ||
|
||
SELECT 'msg1' FROM pg_logical_emit_message(true, 'wal2json', 'this is a\ message'); | ||
?column? | ||
---------- | ||
msg1 | ||
(1 row) | ||
|
||
SELECT 'msg2' FROM pg_logical_emit_message(false, 'wal2json', 'this is "another" message'); | ||
?column? | ||
---------- | ||
msg2 | ||
(1 row) | ||
|
||
BEGIN; | ||
SELECT 'msg3' FROM pg_logical_emit_message(true, 'wal2json', 'this message will not be printed'); | ||
?column? | ||
---------- | ||
msg3 | ||
(1 row) | ||
|
||
SELECT 'msg4' FROM pg_logical_emit_message(false, 'wal2json', 'this message will be printed even if the transaction is rollbacked'); | ||
?column? | ||
---------- | ||
msg4 | ||
(1 row) | ||
|
||
ROLLBACK; | ||
BEGIN; | ||
SELECT 'msg5' FROM pg_logical_emit_message(true, 'wal2json', 'this is message #1'); | ||
?column? | ||
---------- | ||
msg5 | ||
(1 row) | ||
|
||
SELECT 'msg6' FROM pg_logical_emit_message(false, 'wal2json', 'this message will be printed before message #1'); | ||
?column? | ||
---------- | ||
msg6 | ||
(1 row) | ||
|
||
SELECT 'msg7' FROM pg_logical_emit_message(true, 'wal2json', 'this is message #2'); | ||
?column? | ||
---------- | ||
msg7 | ||
(1 row) | ||
|
||
COMMIT; | ||
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'pretty-print', '1'); | ||
data | ||
--------------------------------------------------------------------------------------------------------- | ||
{ + | ||
"change": [ + | ||
{ + | ||
"kind": "message", + | ||
"transactional": true, + | ||
"prefix": "wal2json", + | ||
"content": "this is a\ message" + | ||
} + | ||
] + | ||
} | ||
{ + | ||
"change": [ + | ||
{ + | ||
"kind": "message", + | ||
"transactional": false, + | ||
"prefix": "wal2json", + | ||
"content": "this is "another" message" + | ||
} + | ||
] + | ||
} | ||
{ + | ||
"change": [ + | ||
{ + | ||
"kind": "message", + | ||
"transactional": false, + | ||
"prefix": "wal2json", + | ||
"content": "this message will be printed even if the transaction is rollbacked"+ | ||
} + | ||
] + | ||
} | ||
{ + | ||
"change": [ + | ||
{ + | ||
"kind": "message", + | ||
"transactional": false, + | ||
"prefix": "wal2json", + | ||
"content": "this message will be printed before message #1" + | ||
} + | ||
] + | ||
} | ||
{ + | ||
"change": [ + | ||
{ + | ||
"kind": "message", + | ||
"transactional": true, + | ||
"prefix": "wal2json", + | ||
"content": "this is message #1" + | ||
} + | ||
,{ + | ||
"kind": "message", + | ||
"transactional": true, + | ||
"prefix": "wal2json", + | ||
"content": "this is message #2" + | ||
} + | ||
] + | ||
} | ||
(5 rows) | ||
|
||
SELECT 'stop' FROM pg_drop_replication_slot('regression_slot'); | ||
?column? | ||
---------- | ||
stop | ||
(1 row) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
\set VERBOSITY terse | ||
|
||
-- predictability | ||
SET synchronous_commit = on; | ||
|
||
SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot', 'wal2json'); | ||
|
||
SELECT 'msg1' FROM pg_logical_emit_message(true, 'wal2json', 'this is a\ message'); | ||
SELECT 'msg2' FROM pg_logical_emit_message(false, 'wal2json', 'this is "another" message'); | ||
|
||
BEGIN; | ||
SELECT 'msg3' FROM pg_logical_emit_message(true, 'wal2json', 'this message will not be printed'); | ||
SELECT 'msg4' FROM pg_logical_emit_message(false, 'wal2json', 'this message will be printed even if the transaction is rollbacked'); | ||
ROLLBACK; | ||
|
||
BEGIN; | ||
SELECT 'msg5' FROM pg_logical_emit_message(true, 'wal2json', 'this is message #1'); | ||
SELECT 'msg6' FROM pg_logical_emit_message(false, 'wal2json', 'this message will be printed before message #1'); | ||
SELECT 'msg7' FROM pg_logical_emit_message(true, 'wal2json', 'this is message #2'); | ||
COMMIT; | ||
|
||
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'pretty-print', '1'); | ||
|
||
SELECT 'stop' FROM pg_drop_replication_slot('regression_slot'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters