Fix autovacuum cost debug logging
authorDaniel Gustafsson <[email protected]>
Thu, 20 Apr 2023 13:45:44 +0000 (15:45 +0200)
committerDaniel Gustafsson <[email protected]>
Thu, 20 Apr 2023 13:45:44 +0000 (15:45 +0200)
Commit 7d71d3dd0 introduced finer grained updates of autovacuum option
changes by increasing the frequency of reading the configuration file.
The debug logging of cost parameter was however changed such that some
initial values weren't logged.  Fix by changing logging to use the old
frequency of logging regardless of them changing.

Also avoid taking a log for rendering the log message unless the set
loglevel is such that the log entry will be emitted.

Author: Masahiko Sawada <[email protected]>
Discussion: https://postgr.es/m/CAD21AoBS7o6Ljt_vfqPQPf67AhzKu3fR0iqk8B=vVYczMugKMQ@mail.gmail.com

src/backend/postmaster/autovacuum.c

index 53c8f8d79cba63b5c1c1e42bfe91c1ab0b972c68..e23ec32e22fdedd22dc2f4b1c18ad3c68ba76c0f 100644 (file)
@@ -1785,9 +1785,6 @@ FreeWorkerInfo(int code, Datum arg)
 void
 VacuumUpdateCosts(void)
 {
-       double          original_cost_delay = vacuum_cost_delay;
-       int                     original_cost_limit = vacuum_cost_limit;
-
        if (MyWorkerInfo)
        {
                if (av_storage_param_cost_delay >= 0)
@@ -1821,16 +1818,15 @@ VacuumUpdateCosts(void)
                VacuumCostBalance = 0;
        }
 
-       if (MyWorkerInfo)
+       /*
+        * Since the cost logging requires a lock, avoid rendering the log message
+        * in case we are using a message level where the log wouldn't be emitted.
+        */
+       if (MyWorkerInfo && message_level_is_interesting(DEBUG2))
        {
                Oid                     dboid,
                                        tableoid;
 
-               /* Only log updates to cost-related variables */
-               if (vacuum_cost_delay == original_cost_delay &&
-                       vacuum_cost_limit == original_cost_limit)
-                       return;
-
                Assert(!LWLockHeldByMe(AutovacuumLock));
 
                LWLockAcquire(AutovacuumLock, LW_SHARED);
@@ -1844,7 +1840,6 @@ VacuumUpdateCosts(void)
                         vacuum_cost_limit, vacuum_cost_delay,
                         vacuum_cost_delay > 0 ? "yes" : "no",
                         VacuumFailsafeActive ? "yes" : "no");
-
        }
 }