pgsql: Fix handling of shared statistics with dropped databases

Поиск
Список
Период
Сортировка
От Michael Paquier
Тема pgsql: Fix handling of shared statistics with dropped databases
Дата
Msg-id E1qcw9a-002J2z-Hh@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
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 5891c7a8ed8f, 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

Branch
------
REL_16_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/c397c98ae63d57c35766dbefe4ea34a5162abf53

Modified Files
--------------
src/backend/utils/activity/pgstat_database.c |  13 +++
src/backend/utils/init/postinit.c            | 118 ++++++++++++++-------------
2 files changed, 74 insertions(+), 57 deletions(-)


В списке pgsql-committers по дате отправления:

Предыдущее
От: Alvaro Herrera
Дата:
Сообщение: pgsql: Fix not-null constraint test
Следующее
От: Amit Kapila
Дата:
Сообщение: pgsql: Fix typo in decode.c.