Re: BUG #17973: Reinit of pgstats entry for dropped DB can break autovacuum daemon
Michael Paquier <michael@paquier.xyz>
From: Michael Paquier <michael@paquier.xyz>
To: Andres Freund <andres@anarazel.de>
Cc: will@extrahop.com, pgsql-bugs@lists.postgresql.org
Date: 2023-06-16T01:01:33Z
Lists: pgsql-bugs
On Wed, Jun 14, 2023 at 03:30:12PM -0700, Andres Freund wrote: > Attached is a rough prototype implementing this idea. Could you check if that > fixes the issue? It requires a few manual steps, but I have been able to stuck the autovacuum launcher schedule. Nice investigation from the reporters. I may be missing something here, but finishing with an inconsistent database list (generated based on the pgstat database entries) in the autovacuum launcher is not something that can happen only because of a worker, right? A normal backend would call pgstat_update_dbstats() once it exists, re-creating a fresh entry with the dropped database OID. Is that right? + /* + * If we haven't connected to a database yet, don't attribute time to + * "shared state" (InvalidOid is used to track stats for shared relations + * etc). + */ + if (!OidIsValid(MyDatabaseId)) + return; Hmm. pgstat_report_stat() is called by standby_redo() for a XLOG_RUNNING_XACTS record so this would prevent the startup process from doing any stats updates for the shared db state, no? Looking at the most recent things in this area, like bc49d93 or ac23b71, I don't immediately see why your new ordering suggestion would not be OK with MyDatabaseId getting set before acquiring the shared lock of the database, so as the stat entries don't get messed up. The result feels cleaner in the initialization sequence, additionally. So, nice. -- Michael
Commits
-
Fix handling of shared statistics with dropped databases
- 5a9325fdde1d 15.5 landed
- c397c98ae63d 16.0 landed
- 2b8e5273e949 17.0 landed
-
Accept fractional seconds in jsonpath's datetime() method.
- bd590d1fea1b 15.4 cited