postgresql/src/bin/pg_dump
Andres Freund a4b4cc1d60 Handle DROP DATABASE getting interrupted
Until now, when DROP DATABASE got interrupted in the wrong moment, the removal
of the pg_database row would also roll back, even though some irreversible
steps have already been taken. E.g. DropDatabaseBuffers() might have thrown
out dirty buffers, or files could have been unlinked. But we continued to
allow connections to such a corrupted database.

To fix this, mark databases invalid with an in-place update, just before
starting to perform irreversible steps. As we can't add a new column in the
back branches, we use pg_database.datconnlimit = -2 for this purpose.

An invalid database cannot be connected to anymore, but can still be
dropped.

Unfortunately we can't easily add output to psql's \l to indicate that some
database is invalid, it doesn't fit in any of the existing columns.

Add tests verifying that a interrupted DROP DATABASE is handled correctly in
the backend and in various tools.

Reported-by: Evgeny Morozov <postgresql3@realityexists.net>
Author: Andres Freund <andres@anarazel.de>
Reviewed-by: Daniel Gustafsson <daniel@yesql.se>
Reviewed-by: Thomas Munro <thomas.munro@gmail.com>
Discussion: https://postgr.es/m/20230509004637.cgvmfwrbht7xm7p6@awork3.anarazel.de
Discussion: https://postgr.es/m/20230314174521.74jl6ffqsee5mtug@awork3.anarazel.de
Backpatch: 11-, bug present in all supported versions
2023-07-13 13:03:30 -07:00
..
po Translation updates 2023-05-22 12:44:31 +02:00
t Handle DROP DATABASE getting interrupted 2023-07-13 13:03:30 -07:00
.gitignore Clean up after pg_dump test runs. 2016-05-06 22:28:01 -04:00
common.c Revert "Catalog NOT NULL constraints" and fallout 2023-04-12 19:29:21 +02:00
compress_gzip.c pg_dump: Fix gzip compression of empty data 2023-03-29 02:34:48 +02:00
compress_gzip.h Introduce a generic pg_dump compression API 2023-02-23 18:33:40 +01:00
compress_io.c Pre-beta mechanical code beautification. 2023-05-19 17:24:48 -04:00
compress_io.h Advance input pointer when LZ4 compressing data 2023-05-17 16:49:34 +02:00
compress_lz4.c Pre-beta mechanical code beautification. 2023-05-19 17:24:48 -04:00
compress_lz4.h Add LZ4 compression to pg_dump 2023-02-23 21:19:26 +01:00
compress_none.c Unify buffer sizes in pg_dump compression API 2023-03-23 17:55:52 +01:00
compress_none.h Introduce a generic pg_dump compression API 2023-02-23 18:33:40 +01:00
compress_zstd.c Pre-beta mechanical code beautification. 2023-05-19 17:24:48 -04:00
compress_zstd.h Pre-beta mechanical code beautification. 2023-05-19 17:24:48 -04:00
dumputils.c Revert MAINTAIN privilege and pg_maintain predefined role. 2023-07-07 11:25:23 -07:00
dumputils.h Revert "Add USER SET parameter values for pg_db_role_setting" 2023-05-17 20:28:57 +03:00
Makefile pg_dump: Add support for zstd compression 2023-04-05 21:39:33 +02:00
meson.build pg_dump: Add support for zstd compression 2023-04-05 21:39:33 +02:00
nls.mk Add missing source file to nls.mk 2023-05-08 08:24:42 +02:00
parallel.c Remove useless casts to (void *) in arguments of some system functions 2023-02-07 06:57:59 +01:00
parallel.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
pg_backup.h pg_dump: Remove "blob" terminology 2022-12-05 08:52:55 +01:00
pg_backup_archiver.c Pre-beta mechanical code beautification. 2023-05-19 17:24:48 -04:00
pg_backup_archiver.h Introduce a generic pg_dump compression API 2023-02-23 18:33:40 +01:00
pg_backup_custom.c Introduce a generic pg_dump compression API 2023-02-23 18:33:40 +01:00
pg_backup_db.c pg_dump: Remove "blob" terminology 2022-12-05 08:52:55 +01:00
pg_backup_db.h Revert "pg_dump: Lock all relations, not just plain tables". 2020-11-06 15:48:04 -05:00
pg_backup_directory.c pg_dump: Have _EndLO report errno after CFH->write_func() failure 2023-05-17 18:55:51 +02:00
pg_backup_null.c pg_dump: Remove "blob" terminology 2022-12-05 08:52:55 +01:00
pg_backup_tar.c Pre-beta mechanical code beautification. 2023-05-19 17:24:48 -04:00
pg_backup_tar.h Fix tar files emitted by pg_dump and pg_basebackup to be POSIX conformant. 2012-09-28 15:19:15 -04:00
pg_backup_utils.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
pg_backup_utils.h Update copyright for 2023 2023-01-02 15:00:37 -05:00
pg_dump.c Fix pg_dump's failure to honor dependencies of SQL functions. 2023-06-04 13:05:54 -04:00
pg_dump.h Fix pg_dump's failure to honor dependencies of SQL functions. 2023-06-04 13:05:54 -04:00
pg_dump_sort.c Fix pg_dump's failure to honor dependencies of SQL functions. 2023-06-04 13:05:54 -04:00
pg_dumpall.c Handle DROP DATABASE getting interrupted 2023-07-13 13:03:30 -07:00
pg_restore.c Improve frontend error logging style. 2022-04-08 14:55:14 -04:00