CREATETABLE test_replica_identity (
id serial primarykey,
keya text notnull,
keyb text notnull,
nonkey text, CONSTRAINT test_replica_identity_unique_defer UNIQUE (keya, keyb) DEFERRABLE, CONSTRAINT test_replica_identity_unique_nondefer UNIQUE (keya, keyb)
) ;
CREATETABLE test_replica_identity_othertable (id serial primarykey); CREATETABLE test_replica_identity_t3 (id serial constraint pk primarykey deferrable);
CREATEINDEX test_replica_identity_keyab ON test_replica_identity (keya, keyb); CREATEUNIQUEINDEX test_replica_identity_keyab_key ON test_replica_identity (keya, keyb); CREATEUNIQUEINDEX test_replica_identity_nonkey ON test_replica_identity (keya, nonkey); CREATEINDEX test_replica_identity_hash ON test_replica_identity USING hash (nonkey); CREATEUNIQUEINDEX test_replica_identity_expr ON test_replica_identity (keya, keyb, (3)); CREATEUNIQUEINDEX test_replica_identity_partial ON test_replica_identity (keya, keyb) WHERE keyb != '3';
-- default is 'd'/DEFAULT for user created tables SELECT relreplident FROM pg_class WHERE oid = 'test_replica_identity'::regclass; -- but 'none' for system tables SELECT relreplident FROM pg_class WHERE oid = 'pg_class'::regclass; SELECT relreplident FROM pg_class WHERE oid = 'pg_constraint'::regclass;
---- -- Make sure we detect ineligible indexes ----
-- succeed unique index over nonnullable cols ALTERTABLE test_replica_identity REPLICA IDENTITY USINGINDEX test_replica_identity_keyab_key; ALTERTABLE test_replica_identity REPLICA IDENTITY USINGINDEX test_replica_identity_keyab_key; SELECT relreplident FROM pg_class WHERE oid = 'test_replica_identity'::regclass;
\d test_replica_identity SELECT count(*) FROM pg_index WHERE indrelid = 'test_replica_identity'::regclass AND indisreplident;
---- -- Make sure non index cases work ---- ALTERTABLE test_replica_identity REPLICA IDENTITY DEFAULT; SELECT relreplident FROM pg_class WHERE oid = 'test_replica_identity'::regclass; SELECT count(*) FROM pg_index WHERE indrelid = 'test_replica_identity'::regclass AND indisreplident;
ALTERTABLE test_replica_identity REPLICA IDENTITY FULL; SELECT relreplident FROM pg_class WHERE oid = 'test_replica_identity'::regclass;
\d+ test_replica_identity ALTERTABLE test_replica_identity REPLICA IDENTITY NOTHING; SELECT relreplident FROM pg_class WHERE oid = 'test_replica_identity'::regclass;
--- -- Test that ALTER TABLE rewrite preserves nondefault replica identity ---
-- constraint variant CREATETABLE test_replica_identity2 (id intUNIQUENOTNULL); ALTERTABLE test_replica_identity2 REPLICA IDENTITY USINGINDEX test_replica_identity2_id_key;
\d test_replica_identity2 ALTERTABLE test_replica_identity2 ALTERCOLUMN id TYPE bigint;
\d test_replica_identity2
-- straight index variant CREATETABLE test_replica_identity3 (id intNOTNULL); CREATEUNIQUEINDEX test_replica_identity3_id_key ON test_replica_identity3 (id); ALTERTABLE test_replica_identity3 REPLICA IDENTITY USINGINDEX test_replica_identity3_id_key;
\d test_replica_identity3 ALTERTABLE test_replica_identity3 ALTERCOLUMN id TYPE bigint;
\d test_replica_identity3
-- ALTER TABLE DROP NOT NULL is not allowed for columns part of an index -- used as replica identity. ALTERTABLE test_replica_identity3 ALTERCOLUMN id DROPNOTNULL; -- but it's OK when the identity is FULL ALTERTABLE test_replica_identity3 REPLICA IDENTITY FULL; ALTERTABLE test_replica_identity3 ALTERCOLUMN id DROPNOTNULL;
-- -- Test that replica identity can be set on an index that's not yet valid. -- (This matches the way pg_dump will try to dump a partitioned table.) -- CREATETABLE test_replica_identity4(id integerNOTNULL) PARTITION BY LIST (id); CREATETABLE test_replica_identity4_1(id integerNOTNULL); ALTERTABLE ONLY test_replica_identity4
ATTACH PARTITION test_replica_identity4_1 FORVALUESIN (1); ALTERTABLE ONLY test_replica_identity4 ADDCONSTRAINT test_replica_identity4_pkey PRIMARYKEY (id); ALTERTABLE ONLY test_replica_identity4
REPLICA IDENTITY USINGINDEX test_replica_identity4_pkey; ALTERTABLE ONLY test_replica_identity4_1 ADDCONSTRAINT test_replica_identity4_1_pkey PRIMARYKEY (id);
\d+ test_replica_identity4 ALTERINDEX test_replica_identity4_pkey
ATTACH PARTITION test_replica_identity4_1_pkey;
\d+ test_replica_identity4
-- Dropping the primary key is not allowed if that would leave the replica -- identity as nullable CREATETABLE test_replica_identity5 (a intnotnull, b int, c int, PRIMARYKEY (b, c)); CREATEUNIQUEINDEX test_replica_identity5_a_b_key ON test_replica_identity5 (a, b); ALTERTABLE test_replica_identity5 REPLICA IDENTITY USINGINDEX test_replica_identity5_a_b_key; ALTERTABLE test_replica_identity5 DROPCONSTRAINT test_replica_identity5_pkey; ALTERTABLE test_replica_identity5 ALTER b SETNOTNULL; ALTERTABLE test_replica_identity5 DROPCONSTRAINT test_replica_identity5_pkey; ALTERTABLE test_replica_identity5 ALTER b DROPNOTNULL;
¤ 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.0.11Bemerkung:
(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.