mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-09-12 19:17:54 +02:00
25d9bf2e3e
The current implementation fires an AFTER ROW trigger for each tuple that looks like it might be non-unique according to the index contents at the time of insertion. This works well as long as there aren't many conflicts, but won't scale to massive unique-key reassignments. Improving that case is a TODO item. Dean Rasheed
27 lines
1.0 KiB
SQL
27 lines
1.0 KiB
SQL
VACUUM;
|
|
|
|
--
|
|
-- sanity check, if we don't have indices the test will take years to
|
|
-- complete. But skip TOAST relations (since they will have varying
|
|
-- names depending on the current OID counter) as well as temp tables
|
|
-- of other backends (to avoid timing-dependent behavior).
|
|
--
|
|
SELECT relname, relhasindex
|
|
FROM pg_class c LEFT JOIN pg_namespace n ON n.oid = relnamespace
|
|
WHERE relkind = 'r' AND (nspname ~ '^pg_temp_') IS NOT TRUE
|
|
ORDER BY relname;
|
|
|
|
--
|
|
-- another sanity check: every system catalog that has OIDs should have
|
|
-- a unique index on OID. This ensures that the OIDs will be unique,
|
|
-- even after the OID counter wraps around.
|
|
-- We exclude non-system tables from the check by looking at nspname.
|
|
--
|
|
SELECT relname, nspname
|
|
FROM pg_class c LEFT JOIN pg_namespace n ON n.oid = relnamespace
|
|
WHERE relhasoids
|
|
AND ((nspname ~ '^pg_') IS NOT FALSE)
|
|
AND NOT EXISTS (SELECT 1 FROM pg_index i WHERE indrelid = c.oid
|
|
AND indkey[0] = -2 AND indnatts = 1
|
|
AND indisunique AND indimmediate);
|