postgresql/src/bin
Alvaro Herrera d9f686a72e
Fix restore of not-null constraints with inheritance
In tables with primary keys, pg_dump creates tables with primary keys by
initially dumping them with throw-away not-null constraints (marked "no
inherit" so that they don't create problems elsewhere), to later drop
them once the primary key is restored.  Because of a unrelated
consideration, on tables with children we add not-null constraints to
all columns of the primary key when it is created.

If both a table and its child have primary keys, and pg_dump happens to
emit the child table first (and its throw-away not-null) and later its
parent table, the creation of the parent's PK will fail because the
throw-away not-null constraint collides with the permanent not-null
constraint that the PK wants to add, so the dump fails to restore.

We can work around this problem by letting the primary key "take over"
the child's not-null.  This requires no changes to pg_dump, just two
changes to ALTER TABLE: first, the ability to convert a no-inherit
not-null constraint into a regular inheritable one (including recursing
down to children, if there are any); second, the ability to "drop" a
constraint that is defined both directly in the table and inherited from
a parent (which simply means to mark it as no longer having a local
definition).

Secondarily, change ATPrepAddPrimaryKey() to acquire locks all the way
down the inheritance hierarchy, in case we need to recurse when
propagating constraints.

These two changes allow pg_dump to reproduce more cases involving
inheritance from versions 16 and older.

Lastly, make two changes to pg_dump: 1) do not try to drop a not-null
constraint that's marked as inherited; this allows a dump to restore
with no errors if a table with a PK inherits from another which also has
a PK; 2) avoid giving inherited constraints throwaway names, for the
rare cases where such a constraint survives after the restore.

Reported-by: Andrew Bille <andrewbille@gmail.com>
Reported-by: Justin Pryzby <pryzby@telsasoft.com>
Discussion: https://postgr.es/m/CAJnzarwkfRu76_yi3dqVF_WL-MpvT54zMwAxFwJceXdHB76bOA@mail.gmail.com
Discussion: https://postgr.es/m/Zh0aAH7tbZb-9HbC@pryzbyj2023
2024-04-18 15:35:15 +02:00
..
initdb Fix test failures when language environment is not UTF-8. 2024-04-04 16:10:12 -07:00
pg_amcheck Support retrieval of results in chunks with libpq. 2024-04-06 20:45:11 -04:00
pg_archivecleanup Activate perlcritic InputOutput::RequireCheckedSyscalls and fix resulting warnings 2024-03-19 07:09:31 +01:00
pg_basebackup Fix assorted resource leaks in new pg_createsubscriber code. 2024-04-01 13:47:49 -04:00
pg_checksums Skip .DS_Store files in server side utils 2024-02-13 13:47:12 +01:00
pg_combinebackup Fix some memory leaks associated with parsing json and manifests 2024-04-12 10:32:30 -04:00
pg_config Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_controldata Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_ctl Activate perlcritic InputOutput::RequireCheckedSyscalls and fix resulting warnings 2024-03-19 07:09:31 +01:00
pg_dump Fix restore of not-null constraints with inheritance 2024-04-18 15:35:15 +02:00
pg_resetwal Activate perlcritic InputOutput::RequireCheckedSyscalls and fix resulting warnings 2024-03-19 07:09:31 +01:00
pg_rewind Convert uses of hash_string_pointer to fasthash equivalent 2024-04-06 12:20:40 +07:00
pg_test_fsync Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_test_timing Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_upgrade pg_upgrade: Fix typo in message 2024-04-04 12:58:57 +02:00
pg_verifybackup Don't allocate large buffer on the stack in pg_verifybackup 2024-04-12 10:52:25 -04:00
pg_waldump Update copyright for 2024 2024-01-03 20:49:05 -05:00
pg_walsummary Add missing set_pglocale_pgservice() for pg_walsummary and pg_combinebackup 2024-04-09 14:01:33 +09:00
pgbench Adjust pgbench option for debug mode. 2024-03-25 11:08:53 -05:00
pgevent Update copyright for 2024 2024-01-03 20:49:05 -05:00
psql psql: Make output of \dD more stable 2024-04-15 09:28:48 +02:00
scripts Fix test failures when language environment is not UTF-8. 2024-04-04 16:10:12 -07:00
Makefile Add new pg_walsummary tool. 2024-01-11 12:48:27 -05:00
meson.build Add new pg_walsummary tool. 2024-01-11 12:48:27 -05:00