1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
\set VERBOSITY terse
-- predictability
SET synchronous_commit = on;
CREATE TABLE xpto (a SERIAL PRIMARY KEY, b text);
SELECT 'init' FROM pg_create_logical_replication_slot('regression_slot', 'wal2json');
?column?
----------
init
(1 row)
INSERT INTO xpto (b) VALUES('john');
INSERT INTO xpto (b) VALUES('smith');
INSERT INTO xpto (b) VALUES('robert');
BEGIN;
INSERT INTO xpto (b) VALUES('marie');
SAVEPOINT sp1;
INSERT INTO xpto (b) VALUES('ernesto');
SAVEPOINT sp2;
INSERT INTO xpto (b) VALUES('peter'); -- discard
SAVEPOINT sp3;
INSERT INTO xpto (b) VALUES('albert'); -- discard
ROLLBACK TO SAVEPOINT sp2;
RELEASE SAVEPOINT sp1;
INSERT INTO xpto (b) VALUES('francisco');
END;
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'format-version', '1', 'pretty-print', '1', 'include-typmod', '0');
data
----------------------------------------------------------
{ +
"change": [ +
{ +
"kind": "insert", +
"schema": "public", +
"table": "xpto", +
"columnnames": ["a", "b"], +
"columntypes": ["int4", "text"],+
"columnvalues": [1, "john"] +
} +
] +
}
{ +
"change": [ +
{ +
"kind": "insert", +
"schema": "public", +
"table": "xpto", +
"columnnames": ["a", "b"], +
"columntypes": ["int4", "text"],+
"columnvalues": [2, "smith"] +
} +
] +
}
{ +
"change": [ +
{ +
"kind": "insert", +
"schema": "public", +
"table": "xpto", +
"columnnames": ["a", "b"], +
"columntypes": ["int4", "text"],+
"columnvalues": [3, "robert"] +
} +
] +
}
{ +
"change": [ +
{ +
"kind": "insert", +
"schema": "public", +
"table": "xpto", +
"columnnames": ["a", "b"], +
"columntypes": ["int4", "text"],+
"columnvalues": [4, "marie"] +
} +
,{ +
"kind": "insert", +
"schema": "public", +
"table": "xpto", +
"columnnames": ["a", "b"], +
"columntypes": ["int4", "text"],+
"columnvalues": [5, "ernesto"] +
} +
,{ +
"kind": "insert", +
"schema": "public", +
"table": "xpto", +
"columnnames": ["a", "b"], +
"columntypes": ["int4", "text"],+
"columnvalues": [8, "francisco"]+
} +
] +
}
(4 rows)
SELECT 'stop' FROM pg_drop_replication_slot('regression_slot');
?column?
----------
stop
(1 row)
|