SELECT'init'FROM pg_create_logical_replication_slot('regression_slot', 'test_decoding'); -- fail because of an already existing slot SELECT'init'FROM pg_create_logical_replication_slot('regression_slot', 'test_decoding'); -- fail because of an invalid name SELECT'init'FROM pg_create_logical_replication_slot('Invalid Name', 'test_decoding');
-- fail twice because of an invalid parameter values SELECT'init'FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', 'frakbar'); SELECT'init'FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'nonexistent-option', 'frakbar'); SELECT'init'FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', 'frakbar');
-- succeed once SELECT pg_drop_replication_slot('regression_slot'); -- fail SELECT pg_drop_replication_slot('regression_slot');
-- check that we're detecting a streaming rep slot used for logical decoding SELECT'init'FROM pg_create_physical_replication_slot('repl'); SELECT data FROM pg_logical_slot_get_changes('repl', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1'); SELECT pg_drop_replication_slot('repl');
-- collect all changes SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');
ALTERTABLE replication_example ALTERCOLUMN somenum TYPE int4USING (somenum::int4); -- check that this doesn't produce any changes from the heap rewrite SELECT count(data) FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');
-- show changes SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');
-- ON CONFLICT DO UPDATE support
BEGIN; INSERTINTO replication_example(id, somedata, somenum) SELECT i, i, i FROM generate_series(-15, 15) i ON CONFLICT (id) DO UPDATESET somenum = excluded.somenum + 1; COMMIT;
/* display results */ SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');
-- MERGE support
BEGIN;
MERGE INTO replication_example t USING (SELECT i as id, i as data, i as num FROM generate_series(-20, 5) i) s ON t.id = s.id WHEN MATCHED AND t.id < 0THEN UPDATESET somenum = somenum + 1 WHEN MATCHED AND t.id >= 0THEN DELETE WHENNOT MATCHED THEN INSERTVALUES (s.*); COMMIT;
/* display results */ SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');
CREATETABLE tr_unique(id2 serial uniqueNOTNULL, data int); INSERTINTO tr_unique(data) VALUES(10); ALTERTABLE tr_unique RENAMETO tr_pkey; ALTERTABLE tr_pkey ADDCOLUMN id serial primarykey; SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1', 'include-rewrites', '1');
INSERTINTO tr_pkey(data) VALUES(1); --show deletion with primary key DELETEFROM tr_pkey;
/* display results */ SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');
/* *checkthatdiskspoolingworks(alsoforlogicalmessages)
*/
BEGIN; CREATETABLE tr_etoomuch (id serial primarykey, data int); INSERTINTO tr_etoomuch(data) SELECT g.i FROM generate_series(1, 10234) g(i); SELECT'tx logical msg'FROM pg_logical_emit_message(true, 'test', 'tx logical msg'); DELETEFROM tr_etoomuch WHERE id < 5000; UPDATE tr_etoomuch SET data = - data WHERE id > 5000; CREATETABLE tr_oddlength (id text primarykey, data text); INSERTINTO tr_oddlength VALUES('ab', 'foo'); COMMIT;
/* display results, but hide most of the output */ SELECT count(*), min(data), max(data) FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1') GROUPBY substring(data, 1, 24) ORDERBY1,2;
-- check updates of primary keys work correctly
BEGIN; CREATETABLE spoolme ASSELECT g.i FROM generate_series(1, 5000) g(i); UPDATE tr_etoomuch SET id = -id WHERE id = 5000; UPDATE tr_oddlength SET id = 'x', data = 'quux'; UPDATE tr_oddlength SET id = 'yy', data = 'a'; DELETEFROM spoolme; DROPTABLE spoolme; COMMIT;
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1') WHERE data ~ 'UPDATE';
-- check that a large, spooled, upsert works INSERTINTO tr_etoomuch (id, data) SELECT g.i, -g.i FROM generate_series(8000, 12000) g(i) ON CONFLICT(id) DO UPDATESET data = EXCLUDED.data;
SELECT substring(data, 1, 29), count(*) FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1') WITH ORDINALITY GROUPBY1 ORDERBY min(ordinality);
/* *checkwhetherwedecodesubtransactionscorrectlyinrelationwitheach *other
*/ CREATETABLE tr_sub (id serial primarykey, path text);
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');
-- test whether a known, but not yet logged toplevel xact, followed by a -- subxact commit is handled correctly
BEGIN; SELECT pg_current_xact_id() != '0'; -- so no fixed xid appears in the outfile
SAVEPOINT a; INSERTINTO tr_sub(path) VALUES ('4-top-1-#1'); RELEASE SAVEPOINT a; COMMIT;
-- test whether a change in a subtransaction, in an unknown toplevel -- xact is handled correctly.
BEGIN;
SAVEPOINT a; INSERTINTO tr_sub(path) VALUES ('5-top-1-#1'); COMMIT;
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');
-- check that DDL in aborted subtransactions handled correctly CREATETABLE tr_sub_ddl(data int);
BEGIN;
SAVEPOINT a; ALTERTABLE tr_sub_ddl ALTERCOLUMN data TYPE text; INSERTINTO tr_sub_ddl VALUES ('blah-blah');
ROLLBACK TO SAVEPOINT a; ALTERTABLE tr_sub_ddl ALTERCOLUMN data TYPE bigint; INSERTINTO tr_sub_ddl VALUES(43); COMMIT;
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');
/* *Checkwhethertreatingatableasacatalogtableworkssomewhat
*/ CREATETABLE replication_metadata (
id serial primarykey,
relation name NOTNULL,
options text[]
) WITH (user_catalog_table = true)
;
\d+ replication_metadata
/* we should handle the case without a key at all more gracefully */ CREATETABLE table_without_key(id serial, data int); INSERTINTO table_without_key(data) VALUES(1),(2); DELETEFROM table_without_key WHERE data = 1; -- won't log old keys UPDATE table_without_key SET data = 3WHERE data = 2; UPDATE table_without_key SET id = -id; UPDATE table_without_key SET id = -id; -- should log the full old row now ALTERTABLE table_without_key REPLICA IDENTITY FULL; UPDATE table_without_key SET data = 3WHERE data = 2; UPDATE table_without_key SET id = -id; UPDATE table_without_key SET id = -id; -- ensure that FULL correctly deals with new columns ALTERTABLE table_without_key ADDCOLUMN new_column text; UPDATE table_without_key SET id = -id; UPDATE table_without_key SET id = -id, new_column = 'someval'; DELETEFROM table_without_key WHERE data = 3;
CREATETABLE table_with_pkey(id serial primarykey, data int); INSERTINTO table_with_pkey(data) VALUES(1), (2); DELETEFROM table_with_pkey WHERE data = 1; -- should log the old pkey UPDATE table_with_pkey SET data = 3WHERE data = 2; UPDATE table_with_pkey SET id = -id; UPDATE table_with_pkey SET id = -id; -- check that we log nothing despite having a pkey ALTERTABLE table_without_key REPLICA IDENTITY NOTHING; UPDATE table_with_pkey SET id = -id; -- check that we log everything despite having a pkey ALTERTABLE table_without_key REPLICA IDENTITY FULL; UPDATE table_with_pkey SET id = -id; DELETEFROM table_with_pkey WHERE data = 3;
CREATETABLE table_with_unique_not_null(id serial unique, data int); ALTERTABLE table_with_unique_not_null ALTERCOLUMN id SETNOTNULL; --already set -- won't log anything, replica identity not setup INSERTINTO table_with_unique_not_null(data) VALUES(1), (2); DELETEFROM table_with_unique_not_null WHERE data = 1; UPDATE table_with_unique_not_null SET data = 3WHERE data = 2; UPDATE table_with_unique_not_null SET id = -id; UPDATE table_with_unique_not_null SET id = -id; DELETEFROM table_with_unique_not_null WHERE data = 3; -- should log old key ALTERTABLE table_with_unique_not_null REPLICA IDENTITY USINGINDEX table_with_unique_not_null_id_key; INSERTINTO table_with_unique_not_null(data) VALUES(1), (2); DELETEFROM table_with_unique_not_null WHERE data = 1; UPDATE table_with_unique_not_null SET data = 3WHERE data = 2; UPDATE table_with_unique_not_null SET id = -id; UPDATE table_with_unique_not_null SET id = -id; DELETEFROM table_with_unique_not_null WHERE data = 3;
-- check tables with dropped indexes used in REPLICA IDENTITY -- table with primary key CREATETABLE table_dropped_index_with_pk (a intPRIMARYKEY, b int, c int); CREATEUNIQUEINDEX table_dropped_index_with_pk_idx ON table_dropped_index_with_pk(a); ALTERTABLE table_dropped_index_with_pk REPLICA IDENTITY USINGINDEX table_dropped_index_with_pk_idx; DROPINDEX table_dropped_index_with_pk_idx; INSERTINTO table_dropped_index_with_pk VALUES (1,1,1), (2,2,2), (3,3,3); UPDATE table_dropped_index_with_pk SET a = 4WHERE a = 1; UPDATE table_dropped_index_with_pk SET b = 5WHERE a = 2; UPDATE table_dropped_index_with_pk SET b = 6, c = 7WHERE a = 3; DELETEFROM table_dropped_index_with_pk WHERE b = 1; DELETEFROM table_dropped_index_with_pk WHERE a = 3; DROPTABLE table_dropped_index_with_pk;
-- table without primary key CREATETABLE table_dropped_index_no_pk (a intNOTNULL, b int, c int); CREATEUNIQUEINDEX table_dropped_index_no_pk_idx ON table_dropped_index_no_pk(a); ALTERTABLE table_dropped_index_no_pk REPLICA IDENTITY USINGINDEX table_dropped_index_no_pk_idx; DROPINDEX table_dropped_index_no_pk_idx; INSERTINTO table_dropped_index_no_pk VALUES (1,1,1), (2,2,2), (3,3,3); UPDATE table_dropped_index_no_pk SET a = 4WHERE a = 1; UPDATE table_dropped_index_no_pk SET b = 5WHERE a = 2; UPDATE table_dropped_index_no_pk SET b = 6, c = 7WHERE a = 3; DELETEFROM table_dropped_index_no_pk WHERE b = 1; DELETEFROM table_dropped_index_no_pk WHERE a = 3; DROPTABLE table_dropped_index_no_pk;
-- check toast support
BEGIN; CREATE SEQUENCE toasttable_rand_seq START 79 INCREMENT 1499; -- portable "random" CREATETABLE toasttable(
id serial primarykey,
toasted_col1 text,
rand1 float8DEFAULT nextval('toasttable_rand_seq'),
toasted_col2 text,
rand2 float8DEFAULT nextval('toasttable_rand_seq')
); COMMIT; -- uncompressed external toast data INSERTINTO toasttable(toasted_col1) SELECT string_agg(g.i::text, '') FROM generate_series(1, 2000) g(i);
-- compressed external toast data INSERTINTO toasttable(toasted_col2) SELECTrepeat(string_agg(to_char(g.i, 'FM0000'), ''), 50) FROM generate_series(1, 500) g(i);
-- update of existing column UPDATE toasttable SET toasted_col1 = (SELECT string_agg(g.i::text, '') FROM generate_series(1, 2000) g(i)) WHERE id = 1;
-- This output is extremely wide, and using aligned mode causes psql to -- produce 200kB of useless dashes. Turn that off temporarily to avoid it.
\pset format unaligned SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');
\pset format aligned
INSERTINTO toasttable(toasted_col1) SELECT string_agg(g.i::text, '') FROM generate_series(1, 2000) g(i);
-- update of second column, first column unchanged UPDATE toasttable SET toasted_col2 = (SELECT string_agg(g.i::text, '') FROM generate_series(1, 2000) g(i)) WHERE id = 1;
-- make sure we decode correctly even if the toast table is gone DROPTABLE toasttable;
\pset format unaligned SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');
-- done, free logical replication slot SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'include-xids', '0', 'skip-empty-xacts', '1');
\pset format aligned
/* check that the slot is gone */
\x SELECT * FROM pg_replication_slots;
\x
Messung V0.5 in Prozent
¤ Diese beiden folgenden Angebotsgruppen bietet das Unternehmen0.13Angebot
(Wie Sie bei der Firma Beratungs- und Dienstleistungen beauftragen können 2026-08-08)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.