pg.ddx.io pgsql-committers@postgresql.org mailing list archivehelp / color / mirror / Atom feed
pgsql: Fix handling of shared statistics with dropped databases 3+ messages / 1 participants [nested] [flat]
* pgsql: Fix handling of shared statistics with dropped databases @ 2023-09-03 23:05 Michael Paquier <michael@paquier.xyz> 0 siblings, 0 replies; 3+ messages in thread From: Michael Paquier @ 2023-09-03 23:05 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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 ------ master Details ------- https://git.postgresql.org/pg/commitdiff/2b8e5273e949003f299ddcae5f8c4b44c6eb9edc Modified Files -------------- src/backend/utils/activity/pgstat_database.c | 13 +++ src/backend/utils/init/postinit.c | 118 ++++++++++++++------------- 2 files changed, 74 insertions(+), 57 deletions(-) ^ permalink raw reply [nested|flat] 3+ messages in thread
* pgsql: Fix handling of shared statistics with dropped databases @ 2023-09-03 23:05 Michael Paquier <michael@paquier.xyz> 0 siblings, 0 replies; 3+ messages in thread From: Michael Paquier @ 2023-09-03 23:05 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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(-) ^ permalink raw reply [nested|flat] 3+ messages in thread
* pgsql: Fix handling of shared statistics with dropped databases @ 2023-09-03 23:05 Michael Paquier <michael@paquier.xyz> 0 siblings, 0 replies; 3+ messages in thread From: Michael Paquier @ 2023-09-03 23:05 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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_15_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/5a9325fdde1d8ab8031fa09ebd0f63dc3f967a0a Modified Files -------------- src/backend/utils/activity/pgstat_database.c | 13 +++ src/backend/utils/init/postinit.c | 118 ++++++++++++++------------- 2 files changed, 74 insertions(+), 57 deletions(-) ^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2023-09-03 23:05 UTC | newest] Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2023-09-03 23:05 pgsql: Fix handling of shared statistics with dropped databases Michael Paquier <michael@paquier.xyz> 2023-09-03 23:05 pgsql: Fix handling of shared statistics with dropped databases Michael Paquier <michael@paquier.xyz> 2023-09-03 23:05 pgsql: Fix handling of shared statistics with dropped databases Michael Paquier <michael@paquier.xyz>
This inbox is served by DDX for PostgreSQL; see mirroring instructions for how to clone and mirror all data and code used for this inbox