Converge all SQL-level statistics timing values to float8 milliseconds.
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 30 Apr 2012 18:02:47 +0000 (14:02 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 30 Apr 2012 18:03:33 +0000 (14:03 -0400)
This patch adjusts the core statistics views to match the decision already
taken for pg_stat_statements, that values representing elapsed time should
be represented as float8 and measured in milliseconds.  By using float8,
we are no longer tied to a specific maximum precision of timing data.
(Internally, it's still microseconds, but we could now change that without
needing changes at the SQL level.)

The columns affected are
pg_stat_bgwriter.checkpoint_write_time
pg_stat_bgwriter.checkpoint_sync_time
pg_stat_database.blk_read_time
pg_stat_database.blk_write_time
pg_stat_user_functions.total_time
pg_stat_user_functions.self_time
pg_stat_xact_user_functions.total_time
pg_stat_xact_user_functions.self_time

The first four of these are new in 9.2, so there is no compatibility issue
from changing them.  The others require a release note comment that they
are now double precision (and can show a fractional part) rather than
bigint as before; also their underlying statistics functions now match
the column definitions, instead of returning bigint microseconds.

doc/src/sgml/monitoring.sgml
src/backend/access/transam/xlog.c
src/backend/catalog/system_views.sql
src/backend/postmaster/pgstat.c
src/backend/utils/adt/pgstatfuncs.c
src/include/catalog/catversion.h
src/include/catalog/pg_proc.h
src/include/pgstat.h
src/test/regress/expected/rules.out

index e52b32da6b8c79d65bc1e623d772b570fad45e8d..b27c6861302eee37a0384532fec40a88374c0ec5 100644 (file)
@@ -665,7 +665,7 @@ postgres: <replaceable>user</> <replaceable>database</> <replaceable>host</> <re
      </row>
      <row>
       <entry><structfield>checkpoint_write_time</></entry>
-      <entry><type>bigint</type></entry>
+      <entry><type>double precision</type></entry>
       <entry>
         Total amount of time that has been spent in the portion of
         checkpoint processing where files are written to disk, in milliseconds
@@ -673,7 +673,7 @@ postgres: <replaceable>user</> <replaceable>database</> <replaceable>host</> <re
      </row>
      <row>
       <entry><structfield>checkpoint_sync_time</></entry>
-      <entry><type>bigint</type></entry>
+      <entry><type>double precision</type></entry>
       <entry>
         Total amount of time that has been spent in the portion of
         checkpoint processing where files are synchronized to disk, in
@@ -840,13 +840,13 @@ postgres: <replaceable>user</> <replaceable>database</> <replaceable>host</> <re
     </row>
     <row>
      <entry><structfield>blk_read_time</></entry>
-     <entry><type>bigint</></entry>
+     <entry><type>double precision</></entry>
      <entry>Time spent reading data file blocks by backends in this database,
       in milliseconds</entry>
     </row>
     <row>
      <entry><structfield>blk_write_time</></entry>
-     <entry><type>bigint</></entry>
+     <entry><type>double precision</></entry>
      <entry>Time spent writing data file blocks by backends in this database,
       in milliseconds</entry>
     </row>
@@ -1318,13 +1318,13 @@ postgres: <replaceable>user</> <replaceable>database</> <replaceable>host</> <re
     </row>
     <row>
      <entry><structfield>total_time</></entry>
-     <entry><type>bigint</></entry>
+     <entry><type>double precision</></entry>
      <entry>Total time spent in this function and all other functions
      called by it, in milliseconds</entry>
     </row>
     <row>
      <entry><structfield>self_time</></entry>
-     <entry><type>bigint</></entry>
+     <entry><type>double precision</></entry>
      <entry>Total time spent in this function itself, not including
      other functions called by it, in milliseconds</entry>
     </row>
@@ -1534,8 +1534,6 @@ postgres: <replaceable>user</> <replaceable>database</> <replaceable>host</> <re
    The functions for per-function statistics take a function OID.
    Note that only tables, indexes, and functions in the current database
    can be seen with these functions.
-   It should also be noted that while the views present timing values in
-   milliseconds, the underlying functions report timings in microseconds.
   </para>
 
   <para>
index debf12eaedcbad4f903868e8cfda05a2b33dd286..b584cb0d0ba8deada78eefd2ad9e78385ac7bb8a 100644 (file)
@@ -7511,7 +7511,6 @@ LogCheckpointEnd(bool restartpoint)
 
    CheckpointStats.ckpt_end_t = GetCurrentTimestamp();
 
-
    TimestampDifference(CheckpointStats.ckpt_write_t,
                        CheckpointStats.ckpt_sync_t,
                        &write_secs, &write_usecs);
@@ -7520,7 +7519,7 @@ LogCheckpointEnd(bool restartpoint)
                        CheckpointStats.ckpt_sync_end_t,
                        &sync_secs, &sync_usecs);
 
-   /* Record checkpoint timing summary data. */
+   /* Accumulate checkpoint timing summary data, in milliseconds. */
    BgWriterStats.m_checkpoint_write_time +=
        write_secs * 1000 + write_usecs / 1000;
    BgWriterStats.m_checkpoint_sync_time +=
index 9dacd01ecab6e11a62038630cd90405fb8548ea9..7cc1d41a7daa7cf6233694be7d5f9bbf0eac21f1 100644 (file)
@@ -604,8 +604,8 @@ CREATE VIEW pg_stat_database AS
             pg_stat_get_db_temp_files(D.oid) AS temp_files,
             pg_stat_get_db_temp_bytes(D.oid) AS temp_bytes,
             pg_stat_get_db_deadlocks(D.oid) AS deadlocks,
-            pg_stat_get_db_blk_read_time(D.oid) / 1000 AS blk_read_time,
-            pg_stat_get_db_blk_write_time(D.oid) / 1000 AS blk_write_time,
+            pg_stat_get_db_blk_read_time(D.oid) AS blk_read_time,
+            pg_stat_get_db_blk_write_time(D.oid) AS blk_write_time,
             pg_stat_get_db_stat_reset_time(D.oid) AS stats_reset
     FROM pg_database D;
 
@@ -626,8 +626,8 @@ CREATE VIEW pg_stat_user_functions AS
             N.nspname AS schemaname,
             P.proname AS funcname,
             pg_stat_get_function_calls(P.oid) AS calls,
-            pg_stat_get_function_time(P.oid) / 1000 AS total_time,
-            pg_stat_get_function_self_time(P.oid) / 1000 AS self_time
+            pg_stat_get_function_total_time(P.oid) AS total_time,
+            pg_stat_get_function_self_time(P.oid) AS self_time
     FROM pg_proc P LEFT JOIN pg_namespace N ON (N.oid = P.pronamespace)
     WHERE P.prolang != 12  -- fast check to eliminate built-in functions
           AND pg_stat_get_function_calls(P.oid) IS NOT NULL;
@@ -638,8 +638,8 @@ CREATE VIEW pg_stat_xact_user_functions AS
             N.nspname AS schemaname,
             P.proname AS funcname,
             pg_stat_get_xact_function_calls(P.oid) AS calls,
-            pg_stat_get_xact_function_time(P.oid) / 1000 AS total_time,
-            pg_stat_get_xact_function_self_time(P.oid) / 1000 AS self_time
+            pg_stat_get_xact_function_total_time(P.oid) AS total_time,
+            pg_stat_get_xact_function_self_time(P.oid) AS self_time
     FROM pg_proc P LEFT JOIN pg_namespace N ON (N.oid = P.pronamespace)
     WHERE P.prolang != 12  -- fast check to eliminate built-in functions
           AND pg_stat_get_xact_function_calls(P.oid) IS NOT NULL;
index 04f7c1aa71195119373a8b72d1b95f46a08ef502..ac971abb184d1923273aa5c0bec392cff6a95a36 100644 (file)
@@ -848,8 +848,8 @@ pgstat_send_funcstats(void)
        m_ent = &msg.m_entry[msg.m_nentries];
        m_ent->f_id = entry->f_id;
        m_ent->f_numcalls = entry->f_counts.f_numcalls;
-       m_ent->f_time = INSTR_TIME_GET_MICROSEC(entry->f_counts.f_time);
-       m_ent->f_time_self = INSTR_TIME_GET_MICROSEC(entry->f_counts.f_time_self);
+       m_ent->f_total_time = INSTR_TIME_GET_MICROSEC(entry->f_counts.f_total_time);
+       m_ent->f_self_time = INSTR_TIME_GET_MICROSEC(entry->f_counts.f_self_time);
 
        if (++msg.m_nentries >= PGSTAT_NUM_FUNCENTRIES)
        {
@@ -1467,7 +1467,7 @@ pgstat_init_function_usage(FunctionCallInfoData *fcinfo,
    fcu->fs = &htabent->f_counts;
 
    /* save stats for this function, later used to compensate for recursion */
-   fcu->save_f_time = htabent->f_counts.f_time;
+   fcu->save_f_total_time = htabent->f_counts.f_total_time;
 
    /* save current backend-wide total time */
    fcu->save_total = total_func_time;
@@ -1528,19 +1528,19 @@ pgstat_end_function_usage(PgStat_FunctionCallUsage *fcu, bool finalize)
    INSTR_TIME_ADD(total_func_time, f_self);
 
    /*
-    * Compute the new total f_time as the total elapsed time added to the
-    * pre-call value of f_time.  This is necessary to avoid double-counting
-    * any time taken by recursive calls of myself.  (We do not need any
-    * similar kluge for self time, since that already excludes any recursive
-    * calls.)
+    * Compute the new f_total_time as the total elapsed time added to the
+    * pre-call value of f_total_time.  This is necessary to avoid
+    * double-counting any time taken by recursive calls of myself.  (We do
+    * not need any similar kluge for self time, since that already excludes
+    * any recursive calls.)
     */
-   INSTR_TIME_ADD(f_total, fcu->save_f_time);
+   INSTR_TIME_ADD(f_total, fcu->save_f_total_time);
 
    /* update counters in function stats table */
    if (finalize)
        fs->f_numcalls++;
-   fs->f_time = f_total;
-   INSTR_TIME_ADD(fs->f_time_self, f_self);
+   fs->f_total_time = f_total;
+   INSTR_TIME_ADD(fs->f_self_time, f_self);
 
    /* indicate that we have something to send */
    have_function_stats = true;
@@ -4573,8 +4573,8 @@ pgstat_recv_funcstat(PgStat_MsgFuncstat *msg, int len)
             * we just got.
             */
            funcentry->f_numcalls = funcmsg->f_numcalls;
-           funcentry->f_time = funcmsg->f_time;
-           funcentry->f_time_self = funcmsg->f_time_self;
+           funcentry->f_total_time = funcmsg->f_total_time;
+           funcentry->f_self_time = funcmsg->f_self_time;
        }
        else
        {
@@ -4582,8 +4582,8 @@ pgstat_recv_funcstat(PgStat_MsgFuncstat *msg, int len)
             * Otherwise add the values to the existing entry.
             */
            funcentry->f_numcalls += funcmsg->f_numcalls;
-           funcentry->f_time += funcmsg->f_time;
-           funcentry->f_time_self += funcmsg->f_time_self;
+           funcentry->f_total_time += funcmsg->f_total_time;
+           funcentry->f_self_time += funcmsg->f_self_time;
        }
    }
 }
index 0be55e007cac93b1401c2f753380ea0eb57c15b9..83d0c229917b3e83f74025c6dd9f8a8f1cbcc522 100644 (file)
@@ -45,7 +45,7 @@ extern Datum pg_stat_get_analyze_count(PG_FUNCTION_ARGS);
 extern Datum pg_stat_get_autoanalyze_count(PG_FUNCTION_ARGS);
 
 extern Datum pg_stat_get_function_calls(PG_FUNCTION_ARGS);
-extern Datum pg_stat_get_function_time(PG_FUNCTION_ARGS);
+extern Datum pg_stat_get_function_total_time(PG_FUNCTION_ARGS);
 extern Datum pg_stat_get_function_self_time(PG_FUNCTION_ARGS);
 
 extern Datum pg_stat_get_backend_idset(PG_FUNCTION_ARGS);
@@ -108,7 +108,7 @@ extern Datum pg_stat_get_xact_blocks_fetched(PG_FUNCTION_ARGS);
 extern Datum pg_stat_get_xact_blocks_hit(PG_FUNCTION_ARGS);
 
 extern Datum pg_stat_get_xact_function_calls(PG_FUNCTION_ARGS);
-extern Datum pg_stat_get_xact_function_time(PG_FUNCTION_ARGS);
+extern Datum pg_stat_get_xact_function_total_time(PG_FUNCTION_ARGS);
 extern Datum pg_stat_get_xact_function_self_time(PG_FUNCTION_ARGS);
 
 extern Datum pg_stat_clear_snapshot(PG_FUNCTION_ARGS);
@@ -439,14 +439,15 @@ pg_stat_get_function_calls(PG_FUNCTION_ARGS)
 }
 
 Datum
-pg_stat_get_function_time(PG_FUNCTION_ARGS)
+pg_stat_get_function_total_time(PG_FUNCTION_ARGS)
 {
    Oid         funcid = PG_GETARG_OID(0);
    PgStat_StatFuncEntry *funcentry;
 
    if ((funcentry = pgstat_fetch_stat_funcentry(funcid)) == NULL)
        PG_RETURN_NULL();
-   PG_RETURN_INT64(funcentry->f_time);
+   /* convert counter from microsec to millisec for display */
+   PG_RETURN_FLOAT8(((double) funcentry->f_total_time) / 1000.0);
 }
 
 Datum
@@ -457,7 +458,8 @@ pg_stat_get_function_self_time(PG_FUNCTION_ARGS)
 
    if ((funcentry = pgstat_fetch_stat_funcentry(funcid)) == NULL)
        PG_RETURN_NULL();
-   PG_RETURN_INT64(funcentry->f_time_self);
+   /* convert counter from microsec to millisec for display */
+   PG_RETURN_FLOAT8(((double) funcentry->f_self_time) / 1000.0);
 }
 
 Datum
@@ -1365,30 +1367,32 @@ Datum
 pg_stat_get_db_blk_read_time(PG_FUNCTION_ARGS)
 {
    Oid         dbid = PG_GETARG_OID(0);
-   int64       result;
+   double      result;
    PgStat_StatDBEntry *dbentry;
 
+   /* convert counter from microsec to millisec for display */
    if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
        result = 0;
    else
-       result = (int64) (dbentry->n_block_read_time);
+       result = ((double) dbentry->n_block_read_time) / 1000.0;
 
-   PG_RETURN_INT64(result);
+   PG_RETURN_FLOAT8(result);
 }
 
 Datum
 pg_stat_get_db_blk_write_time(PG_FUNCTION_ARGS)
 {
    Oid         dbid = PG_GETARG_OID(0);
-   int64       result;
+   double      result;
    PgStat_StatDBEntry *dbentry;
 
+   /* convert counter from microsec to millisec for display */
    if ((dbentry = pgstat_fetch_stat_dbentry(dbid)) == NULL)
        result = 0;
    else
-       result = (int64) (dbentry->n_block_write_time);
+       result = ((double) dbentry->n_block_write_time) / 1000.0;
 
-   PG_RETURN_INT64(result);
+   PG_RETURN_FLOAT8(result);
 }
 
 Datum
@@ -1424,13 +1428,15 @@ pg_stat_get_bgwriter_maxwritten_clean(PG_FUNCTION_ARGS)
 Datum
 pg_stat_get_checkpoint_write_time(PG_FUNCTION_ARGS)
 {
-   PG_RETURN_INT64(pgstat_fetch_global()->checkpoint_write_time);
+   /* time is already in msec, just convert to double for presentation */
+   PG_RETURN_FLOAT8((double) pgstat_fetch_global()->checkpoint_write_time);
 }
 
 Datum
 pg_stat_get_checkpoint_sync_time(PG_FUNCTION_ARGS)
 {
-   PG_RETURN_INT64(pgstat_fetch_global()->checkpoint_sync_time);
+   /* time is already in msec, just convert to double for presentation */
+   PG_RETURN_FLOAT8((double) pgstat_fetch_global()->checkpoint_sync_time);
 }
 
 Datum
@@ -1622,14 +1628,14 @@ pg_stat_get_xact_function_calls(PG_FUNCTION_ARGS)
 }
 
 Datum
-pg_stat_get_xact_function_time(PG_FUNCTION_ARGS)
+pg_stat_get_xact_function_total_time(PG_FUNCTION_ARGS)
 {
    Oid         funcid = PG_GETARG_OID(0);
    PgStat_BackendFunctionEntry *funcentry;
 
    if ((funcentry = find_funcstat_entry(funcid)) == NULL)
        PG_RETURN_NULL();
-   PG_RETURN_INT64(INSTR_TIME_GET_MICROSEC(funcentry->f_counts.f_time));
+   PG_RETURN_FLOAT8(INSTR_TIME_GET_MILLISEC(funcentry->f_counts.f_total_time));
 }
 
 Datum
@@ -1640,7 +1646,7 @@ pg_stat_get_xact_function_self_time(PG_FUNCTION_ARGS)
 
    if ((funcentry = find_funcstat_entry(funcid)) == NULL)
        PG_RETURN_NULL();
-   PG_RETURN_INT64(INSTR_TIME_GET_MICROSEC(funcentry->f_counts.f_time_self));
+   PG_RETURN_FLOAT8(INSTR_TIME_GET_MILLISEC(funcentry->f_counts.f_self_time));
 }
 
 
index 094349f3e4aca92855f168a5e93b2dacc2997b77..b308e4b5813a6928eda38185e9577f0507679acb 100644 (file)
@@ -53,6 +53,6 @@
  */
 
 /*                         yyyymmddN */
-#define CATALOG_VERSION_NO 201204291
+#define CATALOG_VERSION_NO 201204301
 
 #endif
index 5b02f17697c6691061b2fe7c4a5b0bc54f9cba67..34b77f01919e9259576cc7efa03a93f269b89973 100644 (file)
@@ -2662,10 +2662,10 @@ DATA(insert OID = 3150 (  pg_stat_get_db_temp_files PGNSP PGUID 12 1 0 0 0 f f f
 DESCR("statistics: number of temporary files written");
 DATA(insert OID = 3151 (  pg_stat_get_db_temp_bytes PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_db_temp_bytes _null_ _null_ _null_ ));
 DESCR("statistics: number of bytes in temporary files written");
-DATA(insert OID = 2844 (  pg_stat_get_db_blk_read_time PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_db_blk_read_time _null_ _null_ _null_ ));
-DESCR("statistics: block read time in microseconds");
-DATA(insert OID = 2845 (  pg_stat_get_db_blk_write_time    PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_db_blk_write_time _null_ _null_ _null_ ));
-DESCR("statistics: block write time in microseconds");
+DATA(insert OID = 2844 (  pg_stat_get_db_blk_read_time PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 701 "26" _null_ _null_ _null_ _null_ pg_stat_get_db_blk_read_time _null_ _null_ _null_ ));
+DESCR("statistics: block read time, in msec");
+DATA(insert OID = 2845 (  pg_stat_get_db_blk_write_time    PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 701 "26" _null_ _null_ _null_ _null_ pg_stat_get_db_blk_write_time _null_ _null_ _null_ ));
+DESCR("statistics: block write time, in msec");
 DATA(insert OID = 2769 ( pg_stat_get_bgwriter_timed_checkpoints PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 20 "" _null_ _null_ _null_ _null_ pg_stat_get_bgwriter_timed_checkpoints _null_ _null_ _null_ ));
 DESCR("statistics: number of timed checkpoints started by the bgwriter");
 DATA(insert OID = 2770 ( pg_stat_get_bgwriter_requested_checkpoints PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 20 "" _null_ _null_ _null_ _null_ pg_stat_get_bgwriter_requested_checkpoints _null_ _null_ _null_ ));
@@ -2678,10 +2678,10 @@ DATA(insert OID = 2773 ( pg_stat_get_bgwriter_maxwritten_clean PGNSP PGUID 12 1
 DESCR("statistics: number of times the bgwriter stopped processing when it had written too many buffers while cleaning");
 DATA(insert OID = 3075 ( pg_stat_get_bgwriter_stat_reset_time PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 1184 "" _null_ _null_ _null_ _null_ pg_stat_get_bgwriter_stat_reset_time _null_ _null_ _null_ ));
 DESCR("statistics: last reset for the bgwriter");
-DATA(insert OID = 3160 ( pg_stat_get_checkpoint_write_time PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 20 "" _null_ _null_ _null_ _null_ pg_stat_get_checkpoint_write_time _null_ _null_ _null_ ));
-DESCR("statistics: total amount of checkpoint time spent writing buffers to disk");
-DATA(insert OID = 3161 ( pg_stat_get_checkpoint_sync_time PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 20 "" _null_ _null_ _null_ _null_ pg_stat_get_checkpoint_sync_time _null_ _null_ _null_ ));
-DESCR("statistics: total amount of checkpoint time spent synchronizing buffers to disk");
+DATA(insert OID = 3160 ( pg_stat_get_checkpoint_write_time PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 701 "" _null_ _null_ _null_ _null_ pg_stat_get_checkpoint_write_time _null_ _null_ _null_ ));
+DESCR("statistics: checkpoint time spent writing buffers to disk, in msec");
+DATA(insert OID = 3161 ( pg_stat_get_checkpoint_sync_time PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 701 "" _null_ _null_ _null_ _null_ pg_stat_get_checkpoint_sync_time _null_ _null_ _null_ ));
+DESCR("statistics: checkpoint time spent synchronizing buffers to disk, in msec");
 DATA(insert OID = 2775 ( pg_stat_get_buf_written_backend PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 20 "" _null_ _null_ _null_ _null_ pg_stat_get_buf_written_backend _null_ _null_ _null_ ));
 DESCR("statistics: number of buffers written by backends");
 DATA(insert OID = 3063 ( pg_stat_get_buf_fsync_backend PGNSP PGUID 12 1 0 0 0 f f f f t f s 0 0 20 "" _null_ _null_ _null_ _null_ pg_stat_get_buf_fsync_backend _null_ _null_ _null_ ));
@@ -2691,10 +2691,10 @@ DESCR("statistics: number of buffer allocations");
 
 DATA(insert OID = 2978 (  pg_stat_get_function_calls       PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_function_calls _null_ _null_ _null_ ));
 DESCR("statistics: number of function calls");
-DATA(insert OID = 2979 (  pg_stat_get_function_time            PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_function_time _null_ _null_ _null_ ));
-DESCR("statistics: execution time of function");
-DATA(insert OID = 2980 (  pg_stat_get_function_self_time   PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_function_self_time _null_ _null_ _null_ ));
-DESCR("statistics: self execution time of function");
+DATA(insert OID = 2979 (  pg_stat_get_function_total_time  PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 701 "26" _null_ _null_ _null_ _null_ pg_stat_get_function_total_time _null_ _null_ _null_ ));
+DESCR("statistics: total execution time of function, in msec");
+DATA(insert OID = 2980 (  pg_stat_get_function_self_time   PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 701 "26" _null_ _null_ _null_ _null_ pg_stat_get_function_self_time _null_ _null_ _null_ ));
+DESCR("statistics: self execution time of function, in msec");
 
 DATA(insert OID = 3037 (  pg_stat_get_xact_numscans                PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_xact_numscans _null_ _null_ _null_ ));
 DESCR("statistics: number of scans done for table/index in current transaction");
@@ -2716,10 +2716,10 @@ DATA(insert OID = 3045 (  pg_stat_get_xact_blocks_hit           PGNSP PGUID 12 1 0 0 0 f
 DESCR("statistics: number of blocks found in cache in current transaction");
 DATA(insert OID = 3046 (  pg_stat_get_xact_function_calls      PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_xact_function_calls _null_ _null_ _null_ ));
 DESCR("statistics: number of function calls in current transaction");
-DATA(insert OID = 3047 (  pg_stat_get_xact_function_time       PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_xact_function_time _null_ _null_ _null_ ));
-DESCR("statistics: execution time of function in current transaction");
-DATA(insert OID = 3048 (  pg_stat_get_xact_function_self_time  PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_xact_function_self_time _null_ _null_ _null_ ));
-DESCR("statistics: self execution time of function in current transaction");
+DATA(insert OID = 3047 (  pg_stat_get_xact_function_total_time PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 701 "26" _null_ _null_ _null_ _null_ pg_stat_get_xact_function_total_time _null_ _null_ _null_ ));
+DESCR("statistics: total execution time of function in current transaction, in msec");
+DATA(insert OID = 3048 (  pg_stat_get_xact_function_self_time  PGNSP PGUID 12 1 0 0 0 f f f f t f v 1 0 701 "26" _null_ _null_ _null_ _null_ pg_stat_get_xact_function_self_time _null_ _null_ _null_ ));
+DESCR("statistics: self execution time of function in current transaction, in msec");
 
 DATA(insert OID = 2230 (  pg_stat_clear_snapshot       PGNSP PGUID 12 1 0 0 0 f f f f f f v 0 0 2278 "" _null_ _null_ _null_ _null_    pg_stat_clear_snapshot _null_ _null_ _null_ ));
 DESCR("statistics: discard current transaction's statistics snapshot");
index 8549d17f28058ce0476d21b1f54714f154cb2753..3583bbe3014cf259164c1b2a5808e6a235cdd40a 100644 (file)
@@ -233,7 +233,7 @@ typedef struct PgStat_MsgTabstat
    int         m_nentries;
    int         m_xact_commit;
    int         m_xact_rollback;
-   PgStat_Counter    m_block_read_time;
+   PgStat_Counter    m_block_read_time;        /* times in microseconds */
    PgStat_Counter    m_block_write_time;
    PgStat_TableEntry m_entry[PGSTAT_NUM_TABENTRIES];
 } PgStat_MsgTabstat;
@@ -366,7 +366,7 @@ typedef struct PgStat_MsgBgWriter
    PgStat_Counter m_buf_written_backend;
    PgStat_Counter m_buf_fsync_backend;
    PgStat_Counter m_buf_alloc;
-   PgStat_Counter m_checkpoint_write_time;
+   PgStat_Counter m_checkpoint_write_time;     /* times in milliseconds */
    PgStat_Counter m_checkpoint_sync_time;
 } PgStat_MsgBgWriter;
 
@@ -407,8 +407,8 @@ typedef struct PgStat_MsgTempFile
 typedef struct PgStat_FunctionCounts
 {
    PgStat_Counter f_numcalls;
-   instr_time  f_time;
-   instr_time  f_time_self;
+   instr_time  f_total_time;
+   instr_time  f_self_time;
 } PgStat_FunctionCounts;
 
 /* ----------
@@ -429,8 +429,8 @@ typedef struct PgStat_FunctionEntry
 {
    Oid         f_id;
    PgStat_Counter f_numcalls;
-   PgStat_Counter f_time;      /* times in microseconds */
-   PgStat_Counter f_time_self;
+   PgStat_Counter f_total_time;        /* times in microseconds */
+   PgStat_Counter f_self_time;
 } PgStat_FunctionEntry;
 
 /* ----------
@@ -545,7 +545,6 @@ typedef struct PgStat_StatDBEntry
 
    TimestampTz stat_reset_timestamp;
 
-
    /*
     * tables and functions must be last in the struct, because we don't write
     * the pointers out to the stats file.
@@ -601,8 +600,8 @@ typedef struct PgStat_StatFuncEntry
 
    PgStat_Counter f_numcalls;
 
-   PgStat_Counter f_time;      /* times in microseconds */
-   PgStat_Counter f_time_self;
+   PgStat_Counter f_total_time;        /* times in microseconds */
+   PgStat_Counter f_self_time;
 } PgStat_StatFuncEntry;
 
 
@@ -705,7 +704,7 @@ typedef struct PgStat_FunctionCallUsage
    /* NULL means we are not tracking the current function call */
    PgStat_FunctionCounts *fs;
    /* Total time previously charged to function, as of function start */
-   instr_time  save_f_time;
+   instr_time  save_f_total_time;
    /* Backend-wide total time as of function start */
    instr_time  save_total;
    /* system clock as of function start */
@@ -730,7 +729,7 @@ extern char *pgstat_stat_filename;
 extern PgStat_MsgBgWriter BgWriterStats;
 
 /*
- * Updated by pgstat_count_time_* macros.
+ * Updated by pgstat_count_buffer_*_time macros
  */
 extern PgStat_Counter pgStatBlockReadTime;
 extern PgStat_Counter pgStatBlockWriteTime;
index 2b29d5c5acde3a8998e0b590f2aa5a5ef8bd3ffe..23c84ade530e1b3fd792f2ec256db72e1be2855c 100644 (file)
@@ -1296,17 +1296,17 @@ SELECT viewname, definition FROM pg_views WHERE schemaname <> 'information_schem
  pg_stat_all_indexes             | SELECT c.oid AS relid, i.oid AS indexrelid, n.nspname AS schemaname, c.relname, i.relname AS indexrelname, pg_stat_get_numscans(i.oid) AS idx_scan, pg_stat_get_tuples_returned(i.oid) AS idx_tup_read, pg_stat_get_tuples_fetched(i.oid) AS idx_tup_fetch FROM (((pg_class c JOIN pg_index x ON ((c.oid = x.indrelid))) JOIN pg_class i ON ((i.oid = x.indexrelid))) LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) WHERE (c.relkind = ANY (ARRAY['r'::"char", 't'::"char"]));
  pg_stat_all_tables              | SELECT c.oid AS relid, n.nspname AS schemaname, c.relname, pg_stat_get_numscans(c.oid) AS seq_scan, pg_stat_get_tuples_returned(c.oid) AS seq_tup_read, (sum(pg_stat_get_numscans(i.indexrelid)))::bigint AS idx_scan, ((sum(pg_stat_get_tuples_fetched(i.indexrelid)))::bigint + pg_stat_get_tuples_fetched(c.oid)) AS idx_tup_fetch, pg_stat_get_tuples_inserted(c.oid) AS n_tup_ins, pg_stat_get_tuples_updated(c.oid) AS n_tup_upd, pg_stat_get_tuples_deleted(c.oid) AS n_tup_del, pg_stat_get_tuples_hot_updated(c.oid) AS n_tup_hot_upd, pg_stat_get_live_tuples(c.oid) AS n_live_tup, pg_stat_get_dead_tuples(c.oid) AS n_dead_tup, pg_stat_get_last_vacuum_time(c.oid) AS last_vacuum, pg_stat_get_last_autovacuum_time(c.oid) AS last_autovacuum, pg_stat_get_last_analyze_time(c.oid) AS last_analyze, pg_stat_get_last_autoanalyze_time(c.oid) AS last_autoanalyze, pg_stat_get_vacuum_count(c.oid) AS vacuum_count, pg_stat_get_autovacuum_count(c.oid) AS autovacuum_count, pg_stat_get_analyze_count(c.oid) AS analyze_count, pg_stat_get_autoanalyze_count(c.oid) AS autoanalyze_count FROM ((pg_class c LEFT JOIN pg_index i ON ((c.oid = i.indrelid))) LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) WHERE (c.relkind = ANY (ARRAY['r'::"char", 't'::"char"])) GROUP BY c.oid, n.nspname, c.relname;
  pg_stat_bgwriter                | SELECT pg_stat_get_bgwriter_timed_checkpoints() AS checkpoints_timed, pg_stat_get_bgwriter_requested_checkpoints() AS checkpoints_req, pg_stat_get_checkpoint_write_time() AS checkpoint_write_time, pg_stat_get_checkpoint_sync_time() AS checkpoint_sync_time, pg_stat_get_bgwriter_buf_written_checkpoints() AS buffers_checkpoint, pg_stat_get_bgwriter_buf_written_clean() AS buffers_clean, pg_stat_get_bgwriter_maxwritten_clean() AS maxwritten_clean, pg_stat_get_buf_written_backend() AS buffers_backend, pg_stat_get_buf_fsync_backend() AS buffers_backend_fsync, pg_stat_get_buf_alloc() AS buffers_alloc, pg_stat_get_bgwriter_stat_reset_time() AS stats_reset;
- pg_stat_database                | SELECT d.oid AS datid, d.datname, pg_stat_get_db_numbackends(d.oid) AS numbackends, pg_stat_get_db_xact_commit(d.oid) AS xact_commit, pg_stat_get_db_xact_rollback(d.oid) AS xact_rollback, (pg_stat_get_db_blocks_fetched(d.oid) - pg_stat_get_db_blocks_hit(d.oid)) AS blks_read, pg_stat_get_db_blocks_hit(d.oid) AS blks_hit, pg_stat_get_db_tuples_returned(d.oid) AS tup_returned, pg_stat_get_db_tuples_fetched(d.oid) AS tup_fetched, pg_stat_get_db_tuples_inserted(d.oid) AS tup_inserted, pg_stat_get_db_tuples_updated(d.oid) AS tup_updated, pg_stat_get_db_tuples_deleted(d.oid) AS tup_deleted, pg_stat_get_db_conflict_all(d.oid) AS conflicts, pg_stat_get_db_temp_files(d.oid) AS temp_files, pg_stat_get_db_temp_bytes(d.oid) AS temp_bytes, pg_stat_get_db_deadlocks(d.oid) AS deadlocks, (pg_stat_get_db_blk_read_time(d.oid) / 1000) AS blk_read_time, (pg_stat_get_db_blk_write_time(d.oid) / 1000) AS blk_write_time, pg_stat_get_db_stat_reset_time(d.oid) AS stats_reset FROM pg_database d;
+ pg_stat_database                | SELECT d.oid AS datid, d.datname, pg_stat_get_db_numbackends(d.oid) AS numbackends, pg_stat_get_db_xact_commit(d.oid) AS xact_commit, pg_stat_get_db_xact_rollback(d.oid) AS xact_rollback, (pg_stat_get_db_blocks_fetched(d.oid) - pg_stat_get_db_blocks_hit(d.oid)) AS blks_read, pg_stat_get_db_blocks_hit(d.oid) AS blks_hit, pg_stat_get_db_tuples_returned(d.oid) AS tup_returned, pg_stat_get_db_tuples_fetched(d.oid) AS tup_fetched, pg_stat_get_db_tuples_inserted(d.oid) AS tup_inserted, pg_stat_get_db_tuples_updated(d.oid) AS tup_updated, pg_stat_get_db_tuples_deleted(d.oid) AS tup_deleted, pg_stat_get_db_conflict_all(d.oid) AS conflicts, pg_stat_get_db_temp_files(d.oid) AS temp_files, pg_stat_get_db_temp_bytes(d.oid) AS temp_bytes, pg_stat_get_db_deadlocks(d.oid) AS deadlocks, pg_stat_get_db_blk_read_time(d.oid) AS blk_read_time, pg_stat_get_db_blk_write_time(d.oid) AS blk_write_time, pg_stat_get_db_stat_reset_time(d.oid) AS stats_reset FROM pg_database d;
  pg_stat_database_conflicts      | SELECT d.oid AS datid, d.datname, pg_stat_get_db_conflict_tablespace(d.oid) AS confl_tablespace, pg_stat_get_db_conflict_lock(d.oid) AS confl_lock, pg_stat_get_db_conflict_snapshot(d.oid) AS confl_snapshot, pg_stat_get_db_conflict_bufferpin(d.oid) AS confl_bufferpin, pg_stat_get_db_conflict_startup_deadlock(d.oid) AS confl_deadlock FROM pg_database d;
  pg_stat_replication             | SELECT s.pid, s.usesysid, u.rolname AS usename, s.application_name, s.client_addr, s.client_hostname, s.client_port, s.backend_start, w.state, w.sent_location, w.write_location, w.flush_location, w.replay_location, w.sync_priority, w.sync_state FROM pg_stat_get_activity(NULL::integer) s(datid, pid, usesysid, application_name, state, query, waiting, xact_start, query_start, backend_start, state_change, client_addr, client_hostname, client_port), pg_authid u, pg_stat_get_wal_senders() w(pid, state, sent_location, write_location, flush_location, replay_location, sync_priority, sync_state) WHERE ((s.usesysid = u.oid) AND (s.pid = w.pid));
  pg_stat_sys_indexes             | SELECT pg_stat_all_indexes.relid, pg_stat_all_indexes.indexrelid, pg_stat_all_indexes.schemaname, pg_stat_all_indexes.relname, pg_stat_all_indexes.indexrelname, pg_stat_all_indexes.idx_scan, pg_stat_all_indexes.idx_tup_read, pg_stat_all_indexes.idx_tup_fetch FROM pg_stat_all_indexes WHERE ((pg_stat_all_indexes.schemaname = ANY (ARRAY['pg_catalog'::name, 'information_schema'::name])) OR (pg_stat_all_indexes.schemaname ~ '^pg_toast'::text));
  pg_stat_sys_tables              | SELECT pg_stat_all_tables.relid, pg_stat_all_tables.schemaname, pg_stat_all_tables.relname, pg_stat_all_tables.seq_scan, pg_stat_all_tables.seq_tup_read, pg_stat_all_tables.idx_scan, pg_stat_all_tables.idx_tup_fetch, pg_stat_all_tables.n_tup_ins, pg_stat_all_tables.n_tup_upd, pg_stat_all_tables.n_tup_del, pg_stat_all_tables.n_tup_hot_upd, pg_stat_all_tables.n_live_tup, pg_stat_all_tables.n_dead_tup, pg_stat_all_tables.last_vacuum, pg_stat_all_tables.last_autovacuum, pg_stat_all_tables.last_analyze, pg_stat_all_tables.last_autoanalyze, pg_stat_all_tables.vacuum_count, pg_stat_all_tables.autovacuum_count, pg_stat_all_tables.analyze_count, pg_stat_all_tables.autoanalyze_count FROM pg_stat_all_tables WHERE ((pg_stat_all_tables.schemaname = ANY (ARRAY['pg_catalog'::name, 'information_schema'::name])) OR (pg_stat_all_tables.schemaname ~ '^pg_toast'::text));
- pg_stat_user_functions          | SELECT p.oid AS funcid, n.nspname AS schemaname, p.proname AS funcname, pg_stat_get_function_calls(p.oid) AS calls, (pg_stat_get_function_time(p.oid) / 1000) AS total_time, (pg_stat_get_function_self_time(p.oid) / 1000) AS self_time FROM (pg_proc p LEFT JOIN pg_namespace n ON ((n.oid = p.pronamespace))) WHERE ((p.prolang <> (12)::oid) AND (pg_stat_get_function_calls(p.oid) IS NOT NULL));
+ pg_stat_user_functions          | SELECT p.oid AS funcid, n.nspname AS schemaname, p.proname AS funcname, pg_stat_get_function_calls(p.oid) AS calls, pg_stat_get_function_total_time(p.oid) AS total_time, pg_stat_get_function_self_time(p.oid) AS self_time FROM (pg_proc p LEFT JOIN pg_namespace n ON ((n.oid = p.pronamespace))) WHERE ((p.prolang <> (12)::oid) AND (pg_stat_get_function_calls(p.oid) IS NOT NULL));
  pg_stat_user_indexes            | SELECT pg_stat_all_indexes.relid, pg_stat_all_indexes.indexrelid, pg_stat_all_indexes.schemaname, pg_stat_all_indexes.relname, pg_stat_all_indexes.indexrelname, pg_stat_all_indexes.idx_scan, pg_stat_all_indexes.idx_tup_read, pg_stat_all_indexes.idx_tup_fetch FROM pg_stat_all_indexes WHERE ((pg_stat_all_indexes.schemaname <> ALL (ARRAY['pg_catalog'::name, 'information_schema'::name])) AND (pg_stat_all_indexes.schemaname !~ '^pg_toast'::text));
  pg_stat_user_tables             | SELECT pg_stat_all_tables.relid, pg_stat_all_tables.schemaname, pg_stat_all_tables.relname, pg_stat_all_tables.seq_scan, pg_stat_all_tables.seq_tup_read, pg_stat_all_tables.idx_scan, pg_stat_all_tables.idx_tup_fetch, pg_stat_all_tables.n_tup_ins, pg_stat_all_tables.n_tup_upd, pg_stat_all_tables.n_tup_del, pg_stat_all_tables.n_tup_hot_upd, pg_stat_all_tables.n_live_tup, pg_stat_all_tables.n_dead_tup, pg_stat_all_tables.last_vacuum, pg_stat_all_tables.last_autovacuum, pg_stat_all_tables.last_analyze, pg_stat_all_tables.last_autoanalyze, pg_stat_all_tables.vacuum_count, pg_stat_all_tables.autovacuum_count, pg_stat_all_tables.analyze_count, pg_stat_all_tables.autoanalyze_count FROM pg_stat_all_tables WHERE ((pg_stat_all_tables.schemaname <> ALL (ARRAY['pg_catalog'::name, 'information_schema'::name])) AND (pg_stat_all_tables.schemaname !~ '^pg_toast'::text));
  pg_stat_xact_all_tables         | SELECT c.oid AS relid, n.nspname AS schemaname, c.relname, pg_stat_get_xact_numscans(c.oid) AS seq_scan, pg_stat_get_xact_tuples_returned(c.oid) AS seq_tup_read, (sum(pg_stat_get_xact_numscans(i.indexrelid)))::bigint AS idx_scan, ((sum(pg_stat_get_xact_tuples_fetched(i.indexrelid)))::bigint + pg_stat_get_xact_tuples_fetched(c.oid)) AS idx_tup_fetch, pg_stat_get_xact_tuples_inserted(c.oid) AS n_tup_ins, pg_stat_get_xact_tuples_updated(c.oid) AS n_tup_upd, pg_stat_get_xact_tuples_deleted(c.oid) AS n_tup_del, pg_stat_get_xact_tuples_hot_updated(c.oid) AS n_tup_hot_upd FROM ((pg_class c LEFT JOIN pg_index i ON ((c.oid = i.indrelid))) LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) WHERE (c.relkind = ANY (ARRAY['r'::"char", 't'::"char"])) GROUP BY c.oid, n.nspname, c.relname;
  pg_stat_xact_sys_tables         | SELECT pg_stat_xact_all_tables.relid, pg_stat_xact_all_tables.schemaname, pg_stat_xact_all_tables.relname, pg_stat_xact_all_tables.seq_scan, pg_stat_xact_all_tables.seq_tup_read, pg_stat_xact_all_tables.idx_scan, pg_stat_xact_all_tables.idx_tup_fetch, pg_stat_xact_all_tables.n_tup_ins, pg_stat_xact_all_tables.n_tup_upd, pg_stat_xact_all_tables.n_tup_del, pg_stat_xact_all_tables.n_tup_hot_upd FROM pg_stat_xact_all_tables WHERE ((pg_stat_xact_all_tables.schemaname = ANY (ARRAY['pg_catalog'::name, 'information_schema'::name])) OR (pg_stat_xact_all_tables.schemaname ~ '^pg_toast'::text));
- pg_stat_xact_user_functions     | SELECT p.oid AS funcid, n.nspname AS schemaname, p.proname AS funcname, pg_stat_get_xact_function_calls(p.oid) AS calls, (pg_stat_get_xact_function_time(p.oid) / 1000) AS total_time, (pg_stat_get_xact_function_self_time(p.oid) / 1000) AS self_time FROM (pg_proc p LEFT JOIN pg_namespace n ON ((n.oid = p.pronamespace))) WHERE ((p.prolang <> (12)::oid) AND (pg_stat_get_xact_function_calls(p.oid) IS NOT NULL));
+ pg_stat_xact_user_functions     | SELECT p.oid AS funcid, n.nspname AS schemaname, p.proname AS funcname, pg_stat_get_xact_function_calls(p.oid) AS calls, pg_stat_get_xact_function_total_time(p.oid) AS total_time, pg_stat_get_xact_function_self_time(p.oid) AS self_time FROM (pg_proc p LEFT JOIN pg_namespace n ON ((n.oid = p.pronamespace))) WHERE ((p.prolang <> (12)::oid) AND (pg_stat_get_xact_function_calls(p.oid) IS NOT NULL));
  pg_stat_xact_user_tables        | SELECT pg_stat_xact_all_tables.relid, pg_stat_xact_all_tables.schemaname, pg_stat_xact_all_tables.relname, pg_stat_xact_all_tables.seq_scan, pg_stat_xact_all_tables.seq_tup_read, pg_stat_xact_all_tables.idx_scan, pg_stat_xact_all_tables.idx_tup_fetch, pg_stat_xact_all_tables.n_tup_ins, pg_stat_xact_all_tables.n_tup_upd, pg_stat_xact_all_tables.n_tup_del, pg_stat_xact_all_tables.n_tup_hot_upd FROM pg_stat_xact_all_tables WHERE ((pg_stat_xact_all_tables.schemaname <> ALL (ARRAY['pg_catalog'::name, 'information_schema'::name])) AND (pg_stat_xact_all_tables.schemaname !~ '^pg_toast'::text));
  pg_statio_all_indexes           | SELECT c.oid AS relid, i.oid AS indexrelid, n.nspname AS schemaname, c.relname, i.relname AS indexrelname, (pg_stat_get_blocks_fetched(i.oid) - pg_stat_get_blocks_hit(i.oid)) AS idx_blks_read, pg_stat_get_blocks_hit(i.oid) AS idx_blks_hit FROM (((pg_class c JOIN pg_index x ON ((c.oid = x.indrelid))) JOIN pg_class i ON ((i.oid = x.indexrelid))) LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) WHERE (c.relkind = ANY (ARRAY['r'::"char", 't'::"char"]));
  pg_statio_all_sequences         | SELECT c.oid AS relid, n.nspname AS schemaname, c.relname, (pg_stat_get_blocks_fetched(c.oid) - pg_stat_get_blocks_hit(c.oid)) AS blks_read, pg_stat_get_blocks_hit(c.oid) AS blks_hit FROM (pg_class c LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) WHERE (c.relkind = 'S'::"char");