postgresql/src/backend
Michael Paquier 2b8e5273e9 Fix handling of shared statistics with dropped databases
Dropping a database while a connection is attempted on it was able to
lead to the presence of valid database entries in shared statistics.
The issue is that MyDatabaseId was getting set too early than it should,
as, if the connection attempted on the dropped database fails when
renamed or dropped, the shutdown callback of the shared statistics would
finish by re-inserting a correct entry related to the database already
dropped.

As analyzed by the bug reporters, this issue could lead to phantom
entries in the database list maintained by the autovacuum launcher
(in rebuild_database_list()) if the database dropped was part of the
database list when it was still valid.  After the database was dropped,
it would remain the highest on the list of databases to considered by
the autovacuum worker as things to process.  This would prevent
autovacuum jobs to happen on all the other databases still present.

The commit fixes this issue by delaying setting MyDatabaseId until the
database existence has been re-checked with the second scan on
pg_database after getting a shared lock on it, and by switching
pgstat_update_dbstats() so as nothing happens if MyDatabaseId is not
valid.

Issue introduced by 5891c7a8ed, so backpatch down to 15.

Reported-by: Will Mortensen, Jacob Speidel
Analyzed-by: Will Mortensen, Jacob Speidel
Author: Andres Freund
Discussion: https://postgr.es/m/17973-bca1f7d5c14f601e@postgresql.org
Backpatch-through: 15
2023-09-04 08:04:22 +09:00
..
access Report syncscan position at end of scan. 2023-08-31 13:02:15 +03:00
archive Redesign archive modules 2023-02-17 14:26:42 +09:00
backup Introduce macros for protocol characters. 2023-08-22 19:16:12 -07:00
bootstrap Make error messages about WAL segment size more consistent 2023-08-28 15:17:04 +02:00
catalog Correct ObjectProperty entry for transforms 2023-08-31 11:11:59 +02:00
commands Fix not-null constraint test 2023-09-01 19:49:20 +02:00
executor Fix RLS policy usage in MERGE. 2023-08-07 09:28:47 +01:00
foreign Expand some more uses of "deleg" to "delegation" or "delegated". 2023-05-21 10:55:18 -04:00
jit Remove duplicated assignment of LLVMJitHandle->lljit 2023-07-13 16:44:17 +09:00
lib Fix ILIST_DEBUG build 2023-01-18 10:26:15 -08:00
libpq Generate new LOG for "trust" connections under log_connections 2023-08-26 20:11:19 +09:00
main Remove obsolete defense against strxfrm() bugs. 2023-04-20 13:20:14 +12:00
nodes Catalog not-null constraints 2023-08-25 13:31:24 +02:00
optimizer Catalog not-null constraints 2023-08-25 13:31:24 +02:00
parser Make more use of makeColumnDef() 2023-08-29 08:45:05 +02:00
partitioning Add missing ObjectIdGetDatum() in syscache lookup calls for Oids 2023-07-20 15:18:25 +09:00
po Translation updates 2023-08-07 12:39:30 +02:00
port Add GUC parameter "huge_pages_status" 2023-07-06 14:42:36 +09:00
postmaster Initialize ListenSocket array earlier. 2023-08-29 09:09:40 +03:00
regex All supported systems have locale_t. 2023-07-09 11:55:18 +12:00
replication Fix some shadow variables in src/backend/replication/ 2023-08-31 08:07:48 +09:00
rewrite Fix RLS policy usage in MERGE. 2023-08-07 09:28:47 +01:00
snowball Fix the install rule for snowball_create.sql. 2023-05-23 11:15:57 -04:00
statistics Take pg_attribute out of VacAttrStats 2023-07-03 07:18:57 +02:00
storage Rename hook functions for debug_io_direct to match variable name. 2023-08-24 22:25:49 +12:00
tcop Fix misuse of PqMsg_Close. 2023-08-29 18:32:38 -07:00
tsearch Take pg_attribute out of VacAttrStats 2023-07-03 07:18:57 +02:00
utils Fix handling of shared statistics with dropped databases 2023-09-04 08:04:22 +09:00
.gitignore
common.mk Blind attempt to fix LLVM dependency in the backend 2022-09-15 10:53:48 +07:00
Makefile Add system view pg_wait_events 2023-08-20 15:35:02 +09:00
meson.build Add win32ver data to meson-built postgres.exe. 2023-06-12 07:40:38 -07:00
nls.mk Add missing gettext triggers 2023-05-10 13:51:51 +02:00