Make stats_temp_directory PGC_SIGHUP, and document how it may cause a temporary
authorMagnus Hagander <magnus@hagander.net>
Mon, 25 Aug 2008 15:11:01 +0000 (15:11 +0000)
committerMagnus Hagander <magnus@hagander.net>
Mon, 25 Aug 2008 15:11:01 +0000 (15:11 +0000)
"outage" of the statistics views.

This requires making the stats collector respond to SIGHUP, like the other
utility processes already did.

doc/src/sgml/config.sgml
src/backend/postmaster/pgstat.c
src/backend/postmaster/postmaster.c
src/backend/utils/misc/guc.c

index bd14199e2471b3f392b8c4a0c253b9857f0a3985..ed5e112d1d20b5d6b62cccc43785297e1e73f75b 100644 (file)
@@ -3418,7 +3418,9 @@ COPY postgres_log FROM '/full/path/to/logfile.csv' WITH csv;
         path relative to the data directory or an absolute path. The default is
         <filename>pg_stat_tmp</filename>. Pointing this at a RAM based filesystem
         will decrease physical I/O requirements and can lead to increased 
-        performance. This parameter can only be set at server start.
+        performance. If this parameter is changed when the system is running,
+        the statistics functions might return no information until a new 
+        file has been written, which typically happens twice per second.
        </para>
       </listitem>
      </varlistentry>
index 23b803539caaf7f9466cfb527c75bdb77c78055f..0f19aee795bf99ac80a511634af08426942094dd 100644 (file)
@@ -203,6 +203,7 @@ static PgStat_GlobalStats globalStats;
 
 static volatile bool need_exit = false;
 static volatile bool need_statwrite = false;
+static volatile bool got_SIGHUP = false;
 
 /*
  * Total time charged to functions so far in the current backend.
@@ -224,6 +225,7 @@ NON_EXEC_STATIC void PgstatCollectorMain(int argc, char *argv[]);
 static void pgstat_exit(SIGNAL_ARGS);
 static void force_statwrite(SIGNAL_ARGS);
 static void pgstat_beshutdown_hook(int code, Datum arg);
+static void pgstat_sighup_handler(SIGNAL_ARGS);
 
 static PgStat_StatDBEntry *pgstat_get_db_entry(Oid databaseid, bool create);
 static void pgstat_write_statsfile(bool permanent);
@@ -2571,7 +2573,7 @@ PgstatCollectorMain(int argc, char *argv[])
         * Ignore all signals usually bound to some action in the postmaster,
         * except SIGQUIT and SIGALRM.
         */
-       pqsignal(SIGHUP, SIG_IGN);
+       pqsignal(SIGHUP, pgstat_sighup_handler);
        pqsignal(SIGINT, SIG_IGN);
        pqsignal(SIGTERM, SIG_IGN);
        pqsignal(SIGQUIT, pgstat_exit);
@@ -2634,6 +2636,15 @@ PgstatCollectorMain(int argc, char *argv[])
                if (need_exit)
                        break;
 
+               /*
+                * Reload configuration if we got SIGHUP from the postmaster.
+                */
+               if (got_SIGHUP)
+               {
+                       ProcessConfigFile(PGC_SIGHUP);
+                       got_SIGHUP = false;
+               }
+
                /*
                 * If time to write the stats file, do so.      Note that the alarm
                 * interrupt isn't re-enabled immediately, but only after we next
@@ -2834,6 +2845,13 @@ force_statwrite(SIGNAL_ARGS)
        need_statwrite = true;
 }
 
+/* SIGHUP handler for collector process */
+static void
+pgstat_sighup_handler(SIGNAL_ARGS)
+{
+       got_SIGHUP = true;
+}
+
 
 /*
  * Lookup the hash table entry for the specified database. If no hash
index 0f57ab5e04da80c4138736904edff56c9f5c583b..afebb51845e81c71403d61ccc8f090977be78504 100644 (file)
@@ -1923,7 +1923,8 @@ SIGHUP_handler(SIGNAL_ARGS)
                        signal_child(PgArchPID, SIGHUP);
                if (SysLoggerPID != 0)
                        signal_child(SysLoggerPID, SIGHUP);
-               /* PgStatPID does not currently need SIGHUP */
+               if (PgStatPID != 0)
+                       signal_child(PgStatPID, SIGHUP);
 
                /* Reload authentication config files too */
                load_hba();
index 63969c1392d9f5cd759f3184e3b19ae497bc46a5..4ca25dc5abd96c73f75cc2e7d1518a77ae481a73 100644 (file)
@@ -2470,7 +2470,7 @@ static struct config_string ConfigureNamesString[] =
        },
 
        {
-               {"stats_temp_directory", PGC_POSTMASTER, STATS_COLLECTOR,
+               {"stats_temp_directory", PGC_SIGHUP, STATS_COLLECTOR,
                        gettext_noop("Writes temporary statistics files to the specified directory."),
                        NULL,
                        GUC_SUPERUSER_ONLY