Commit 46aa77c7 authored by Tom Lane's avatar Tom Lane

Add stats functions and views to provide access to a transaction's own

statistics counts.  These numbers are being accumulated but haven't yet been
transmitted to the collector (and won't be, until the transaction ends).
For some purposes, though, it's handy to be able to look at them.

Joel Jacobson, reviewed by Itagaki Takahiro
parent 83f5491c
<!-- $PostgreSQL: pgsql/doc/src/sgml/monitoring.sgml,v 1.81 2010/07/29 19:34:40 petere Exp $ --> <!-- $PostgreSQL: pgsql/doc/src/sgml/monitoring.sgml,v 1.82 2010/08/08 16:27:03 tgl Exp $ -->
<chapter id="monitoring"> <chapter id="monitoring">
<title>Monitoring Database Activity</title> <title>Monitoring Database Activity</title>
...@@ -124,8 +124,8 @@ postgres: <replaceable>user</> <replaceable>database</> <replaceable>host</> <re ...@@ -124,8 +124,8 @@ postgres: <replaceable>user</> <replaceable>database</> <replaceable>host</> <re
<para> <para>
<productname>PostgreSQL</productname> also supports reporting of the exact <productname>PostgreSQL</productname> also supports reporting of the exact
command currently being executed by other server processes. This is an command currently being executed by other server processes. This
facility independent of the collector process. facility is independent of the collector process.
</para> </para>
<sect2 id="monitoring-stats-setup"> <sect2 id="monitoring-stats-setup">
...@@ -165,8 +165,8 @@ postgres: <replaceable>user</> <replaceable>database</> <replaceable>host</> <re ...@@ -165,8 +165,8 @@ postgres: <replaceable>user</> <replaceable>database</> <replaceable>host</> <re
</para> </para>
<para> <para>
The statistics collector communicates with the backends needing The statistics collector transmits the collected
information (including autovacuum) through temporary files. information to backends (including autovacuum) through temporary files.
These files are stored in the <filename>pg_stat_tmp</filename> subdirectory. These files are stored in the <filename>pg_stat_tmp</filename> subdirectory.
When the postmaster shuts down, a permanent copy of the statistics When the postmaster shuts down, a permanent copy of the statistics
data is stored in the <filename>global</filename> subdirectory. For increased data is stored in the <filename>global</filename> subdirectory. For increased
...@@ -219,6 +219,16 @@ postgres: <replaceable>user</> <replaceable>database</> <replaceable>host</> <re ...@@ -219,6 +219,16 @@ postgres: <replaceable>user</> <replaceable>database</> <replaceable>host</> <re
statistical information will cause a new snapshot to be fetched. statistical information will cause a new snapshot to be fetched.
</para> </para>
<para>
A transaction can also see its own statistics (as yet untransmitted to the
collector) in the views <structname>pg_stat_xact_all_tables</>,
<structname>pg_stat_xact_sys_tables</>,
<structname>pg_stat_xact_user_tables</>, and
<structname>pg_stat_xact_user_functions</>, or via these views' underlying
functions. These numbers do not act as stated above; instead they update
continuously throughout the transaction.
</para>
<table id="monitoring-stats-views-table"> <table id="monitoring-stats-views-table">
<title>Standard Statistics Views</title> <title>Standard Statistics Views</title>
...@@ -299,6 +309,27 @@ postgres: <replaceable>user</> <replaceable>database</> <replaceable>host</> <re ...@@ -299,6 +309,27 @@ postgres: <replaceable>user</> <replaceable>database</> <replaceable>host</> <re
tables are shown.</entry> tables are shown.</entry>
</row> </row>
<row>
<entry><structname>pg_stat_xact_all_tables</></entry>
<entry>Similar to <structname>pg_stat_all_tables</>, but counts actions
taken so far within the current transaction (which are <emphasis>not</>
yet included in <structname>pg_stat_all_tables</> and related views).
The columns for numbers of live and dead rows and last-vacuum and
last-analyze times are not present in this view.</entry>
</row>
<row>
<entry><structname>pg_stat_xact_sys_tables</></entry>
<entry>Same as <structname>pg_stat_xact_all_tables</>, except that only
system tables are shown.</entry>
</row>
<row>
<entry><structname>pg_stat_xact_user_tables</></entry>
<entry>Same as <structname>pg_stat_xact_all_tables</>, except that only
user tables are shown.</entry>
</row>
<row> <row>
<entry><structname>pg_stat_all_indexes</></entry> <entry><structname>pg_stat_all_indexes</></entry>
<entry>For each index in the current database, <entry>For each index in the current database,
...@@ -395,6 +426,13 @@ postgres: <replaceable>user</> <replaceable>database</> <replaceable>host</> <re ...@@ -395,6 +426,13 @@ postgres: <replaceable>user</> <replaceable>database</> <replaceable>host</> <re
</entry> </entry>
</row> </row>
<row>
<entry><structname>pg_stat_xact_user_functions</></entry>
<entry>Similar to <structname>pg_stat_user_functions</>, but counts only
calls during the current transaction (which are <emphasis>not</>
yet included in <structname>pg_stat_user_functions</>).</entry>
</row>
</tbody> </tbody>
</tgroup> </tgroup>
</table> </table>
...@@ -405,7 +443,7 @@ postgres: <replaceable>user</> <replaceable>database</> <replaceable>host</> <re ...@@ -405,7 +443,7 @@ postgres: <replaceable>user</> <replaceable>database</> <replaceable>host</> <re
</para> </para>
<para> <para>
Beginning in <productname>PostgreSQL</productname> 8.1, indexes can be Indexes can be
used either directly or via <quote>bitmap scans</>. In a bitmap scan used either directly or via <quote>bitmap scans</>. In a bitmap scan
the output of several indexes can be combined via AND or OR rules; the output of several indexes can be combined via AND or OR rules;
so it is difficult to associate individual heap row fetches so it is difficult to associate individual heap row fetches
...@@ -680,6 +718,82 @@ postgres: <replaceable>user</> <replaceable>database</> <replaceable>host</> <re ...@@ -680,6 +718,82 @@ postgres: <replaceable>user</> <replaceable>database</> <replaceable>host</> <re
</entry> </entry>
</row> </row>
<row>
<entry><literal><function>pg_stat_get_xact_numscans</function>(<type>oid</type>)</literal></entry>
<entry><type>bigint</type></entry>
<entry>
Number of sequential scans done when argument is a table,
or number of index scans done when argument is an index, in the current transaction
</entry>
</row>
<row>
<entry><literal><function>pg_stat_get_xact_tuples_returned</function>(<type>oid</type>)</literal></entry>
<entry><type>bigint</type></entry>
<entry>
Number of rows read by sequential scans when argument is a table,
or number of index entries returned when argument is an index, in the current transaction
</entry>
</row>
<row>
<entry><literal><function>pg_stat_get_xact_tuples_fetched</function>(<type>oid</type>)</literal></entry>
<entry><type>bigint</type></entry>
<entry>
Number of table rows fetched by bitmap scans when argument is a table,
or table rows fetched by simple index scans using the index
when argument is an index, in the current transaction
</entry>
</row>
<row>
<entry><literal><function>pg_stat_get_xact_tuples_inserted</function>(<type>oid</type>)</literal></entry>
<entry><type>bigint</type></entry>
<entry>
Number of rows inserted into table, in the current transaction
</entry>
</row>
<row>
<entry><literal><function>pg_stat_get_xact_tuples_updated</function>(<type>oid</type>)</literal></entry>
<entry><type>bigint</type></entry>
<entry>
Number of rows updated in table (includes HOT updates), in the current transaction
</entry>
</row>
<row>
<entry><literal><function>pg_stat_get_xact_tuples_deleted</function>(<type>oid</type>)</literal></entry>
<entry><type>bigint</type></entry>
<entry>
Number of rows deleted from table, in the current transaction
</entry>
</row>
<row>
<entry><literal><function>pg_stat_get_xact_tuples_hot_updated</function>(<type>oid</type>)</literal></entry>
<entry><type>bigint</type></entry>
<entry>
Number of rows HOT-updated in table, in the current transaction
</entry>
</row>
<row>
<entry><literal><function>pg_stat_get_xact_blocks_fetched</function>(<type>oid</type>)</literal></entry>
<entry><type>bigint</type></entry>
<entry>
Number of disk block fetch requests for table or index, in the current transaction
</entry>
</row>
<row>
<entry><literal><function>pg_stat_get_xact_blocks_hit</function>(<type>oid</type>)</literal></entry>
<entry><type>bigint</type></entry>
<entry>
Number of disk block requests found in cache for table or index, in the current transaction
</entry>
</row>
<row> <row>
<!-- See also the entry for this in func.sgml --> <!-- See also the entry for this in func.sgml -->
<entry><literal><function>pg_backend_pid</function>()</literal></entry> <entry><literal><function>pg_backend_pid</function>()</literal></entry>
...@@ -726,6 +840,33 @@ postgres: <replaceable>user</> <replaceable>database</> <replaceable>host</> <re ...@@ -726,6 +840,33 @@ postgres: <replaceable>user</> <replaceable>database</> <replaceable>host</> <re
</entry> </entry>
</row> </row>
<row>
<entry><literal><function>pg_stat_get_xact_function_calls</function>(<type>oid</type>)</literal></entry>
<entry><type>bigint</type></entry>
<entry>
Number of times the function has been called, in the current transaction.
</entry>
</row>
<row>
<entry><literal><function>pg_stat_get_xact_function_time</function>(<type>oid</type>)</literal></entry>
<entry><type>bigint</type></entry>
<entry>
Total wall clock time spent in the function, in microseconds, in the
current transaction. Includes the time spent in functions called by
this one.
</entry>
</row>
<row>
<entry><literal><function>pg_stat_get_xact_function_self_time</function>(<type>oid</type>)</literal></entry>
<entry><type>bigint</type></entry>
<entry>
Time spent in only this function, in the current transaction. Time
spent in called functions is excluded.
</entry>
</row>
<row> <row>
<entry><literal><function>pg_stat_get_backend_idset</function>()</literal></entry> <entry><literal><function>pg_stat_get_backend_idset</function>()</literal></entry>
<entry><type>setof integer</type></entry> <entry><type>setof integer</type></entry>
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* Copyright (c) 1996-2010, PostgreSQL Global Development Group * Copyright (c) 1996-2010, PostgreSQL Global Development Group
* *
* $PostgreSQL: pgsql/src/backend/catalog/system_views.sql,v 1.66 2010/04/26 14:22:37 momjian Exp $ * $PostgreSQL: pgsql/src/backend/catalog/system_views.sql,v 1.67 2010/08/08 16:27:03 tgl Exp $
*/ */
CREATE VIEW pg_roles AS CREATE VIEW pg_roles AS
...@@ -208,16 +208,46 @@ CREATE VIEW pg_stat_all_tables AS ...@@ -208,16 +208,46 @@ CREATE VIEW pg_stat_all_tables AS
WHERE C.relkind IN ('r', 't') WHERE C.relkind IN ('r', 't')
GROUP BY C.oid, N.nspname, C.relname; GROUP BY C.oid, N.nspname, C.relname;
CREATE VIEW pg_stat_xact_all_tables AS
SELECT
C.oid AS relid,
N.nspname AS schemaname,
C.relname AS 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 IN ('r', 't')
GROUP BY C.oid, N.nspname, C.relname;
CREATE VIEW pg_stat_sys_tables AS CREATE VIEW pg_stat_sys_tables AS
SELECT * FROM pg_stat_all_tables SELECT * FROM pg_stat_all_tables
WHERE schemaname IN ('pg_catalog', 'information_schema') OR WHERE schemaname IN ('pg_catalog', 'information_schema') OR
schemaname ~ '^pg_toast'; schemaname ~ '^pg_toast';
CREATE VIEW pg_stat_xact_sys_tables AS
SELECT * FROM pg_stat_xact_all_tables
WHERE schemaname IN ('pg_catalog', 'information_schema') OR
schemaname ~ '^pg_toast';
CREATE VIEW pg_stat_user_tables AS CREATE VIEW pg_stat_user_tables AS
SELECT * FROM pg_stat_all_tables SELECT * FROM pg_stat_all_tables
WHERE schemaname NOT IN ('pg_catalog', 'information_schema') AND WHERE schemaname NOT IN ('pg_catalog', 'information_schema') AND
schemaname !~ '^pg_toast'; schemaname !~ '^pg_toast';
CREATE VIEW pg_stat_xact_user_tables AS
SELECT * FROM pg_stat_xact_all_tables
WHERE schemaname NOT IN ('pg_catalog', 'information_schema') AND
schemaname !~ '^pg_toast';
CREATE VIEW pg_statio_all_tables AS CREATE VIEW pg_statio_all_tables AS
SELECT SELECT
C.oid AS relid, C.oid AS relid,
...@@ -375,6 +405,18 @@ CREATE VIEW pg_stat_user_functions AS ...@@ -375,6 +405,18 @@ CREATE VIEW pg_stat_user_functions AS
WHERE P.prolang != 12 -- fast check to eliminate built-in functions WHERE P.prolang != 12 -- fast check to eliminate built-in functions
AND pg_stat_get_function_calls(P.oid) IS NOT NULL; AND pg_stat_get_function_calls(P.oid) IS NOT NULL;
CREATE VIEW pg_stat_xact_user_functions AS
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 -- fast check to eliminate built-in functions
AND pg_stat_get_xact_function_calls(P.oid) IS NOT NULL;
CREATE VIEW pg_stat_bgwriter AS CREATE VIEW pg_stat_bgwriter AS
SELECT SELECT
pg_stat_get_bgwriter_timed_checkpoints() AS checkpoints_timed, pg_stat_get_bgwriter_timed_checkpoints() AS checkpoints_timed,
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
* *
* Copyright (c) 2001-2010, PostgreSQL Global Development Group * Copyright (c) 2001-2010, PostgreSQL Global Development Group
* *
* $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.204 2010/07/06 19:18:57 momjian Exp $ * $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.205 2010/08/08 16:27:03 tgl Exp $
* ---------- * ----------
*/ */
#include "postgres.h" #include "postgres.h"
...@@ -1402,6 +1402,23 @@ pgstat_init_function_usage(FunctionCallInfoData *fcinfo, ...@@ -1402,6 +1402,23 @@ pgstat_init_function_usage(FunctionCallInfoData *fcinfo,
INSTR_TIME_SET_CURRENT(fcu->f_start); INSTR_TIME_SET_CURRENT(fcu->f_start);
} }
/*
* find_funcstat_entry - find any existing PgStat_BackendFunctionEntry entry
* for specified function
*
* If no entry, return NULL, don't create a new one
*/
PgStat_BackendFunctionEntry *
find_funcstat_entry(Oid func_id)
{
if (pgStatFunctions == NULL)
return NULL;
return (PgStat_BackendFunctionEntry *) hash_search(pgStatFunctions,
(void *) &func_id,
HASH_FIND, NULL);
}
/* /*
* Calculate function call usage and update stat counters. * Calculate function call usage and update stat counters.
* Called by the executor after invoking a function. * Called by the executor after invoking a function.
...@@ -1560,6 +1577,32 @@ get_tabstat_entry(Oid rel_id, bool isshared) ...@@ -1560,6 +1577,32 @@ get_tabstat_entry(Oid rel_id, bool isshared)
return entry; return entry;
} }
/*
* find_tabstat_entry - find any existing PgStat_TableStatus entry for rel
*
* If no entry, return NULL, don't create a new one
*/
PgStat_TableStatus *
find_tabstat_entry(Oid rel_id)
{
PgStat_TableStatus *entry;
TabStatusArray *tsa;
int i;
for (tsa = pgStatTabList; tsa != NULL; tsa = tsa->tsa_next)
{
for (i = 0; i < tsa->tsa_used; i++)
{
entry = &tsa->tsa_entries[i];
if (entry->t_id == rel_id)
return entry;
}
}
/* Not present */
return NULL;
}
/* /*
* get_tabstat_stack_level - add a new (sub)transaction stack entry if needed * get_tabstat_stack_level - add a new (sub)transaction stack entry if needed
*/ */
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/pgstatfuncs.c,v 1.60 2010/02/26 02:01:09 momjian Exp $ * $PostgreSQL: pgsql/src/backend/utils/adt/pgstatfuncs.c,v 1.61 2010/08/08 16:27:04 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -76,6 +76,20 @@ extern Datum pg_stat_get_bgwriter_maxwritten_clean(PG_FUNCTION_ARGS); ...@@ -76,6 +76,20 @@ extern Datum pg_stat_get_bgwriter_maxwritten_clean(PG_FUNCTION_ARGS);
extern Datum pg_stat_get_buf_written_backend(PG_FUNCTION_ARGS); extern Datum pg_stat_get_buf_written_backend(PG_FUNCTION_ARGS);
extern Datum pg_stat_get_buf_alloc(PG_FUNCTION_ARGS); extern Datum pg_stat_get_buf_alloc(PG_FUNCTION_ARGS);
extern Datum pg_stat_get_xact_numscans(PG_FUNCTION_ARGS);
extern Datum pg_stat_get_xact_tuples_returned(PG_FUNCTION_ARGS);
extern Datum pg_stat_get_xact_tuples_fetched(PG_FUNCTION_ARGS);
extern Datum pg_stat_get_xact_tuples_inserted(PG_FUNCTION_ARGS);
extern Datum pg_stat_get_xact_tuples_updated(PG_FUNCTION_ARGS);
extern Datum pg_stat_get_xact_tuples_deleted(PG_FUNCTION_ARGS);
extern Datum pg_stat_get_xact_tuples_hot_updated(PG_FUNCTION_ARGS);
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_self_time(PG_FUNCTION_ARGS);
extern Datum pg_stat_clear_snapshot(PG_FUNCTION_ARGS); extern Datum pg_stat_clear_snapshot(PG_FUNCTION_ARGS);
extern Datum pg_stat_reset(PG_FUNCTION_ARGS); extern Datum pg_stat_reset(PG_FUNCTION_ARGS);
extern Datum pg_stat_reset_shared(PG_FUNCTION_ARGS); extern Datum pg_stat_reset_shared(PG_FUNCTION_ARGS);
...@@ -1092,6 +1106,192 @@ pg_stat_get_buf_alloc(PG_FUNCTION_ARGS) ...@@ -1092,6 +1106,192 @@ pg_stat_get_buf_alloc(PG_FUNCTION_ARGS)
PG_RETURN_INT64(pgstat_fetch_global()->buf_alloc); PG_RETURN_INT64(pgstat_fetch_global()->buf_alloc);
} }
Datum
pg_stat_get_xact_numscans(PG_FUNCTION_ARGS)
{
Oid relid = PG_GETARG_OID(0);
int64 result;
PgStat_TableStatus *tabentry;
if ((tabentry = find_tabstat_entry(relid)) == NULL)
result = 0;
else
result = (int64) (tabentry->t_counts.t_numscans);
PG_RETURN_INT64(result);
}
Datum
pg_stat_get_xact_tuples_returned(PG_FUNCTION_ARGS)
{
Oid relid = PG_GETARG_OID(0);
int64 result;
PgStat_TableStatus *tabentry;
if ((tabentry = find_tabstat_entry(relid)) == NULL)
result = 0;
else
result = (int64) (tabentry->t_counts.t_tuples_returned);
PG_RETURN_INT64(result);
}
Datum
pg_stat_get_xact_tuples_fetched(PG_FUNCTION_ARGS)
{
Oid relid = PG_GETARG_OID(0);
int64 result;
PgStat_TableStatus *tabentry;
if ((tabentry = find_tabstat_entry(relid)) == NULL)
result = 0;
else
result = (int64) (tabentry->t_counts.t_tuples_fetched);
PG_RETURN_INT64(result);
}
Datum
pg_stat_get_xact_tuples_inserted(PG_FUNCTION_ARGS)
{
Oid relid = PG_GETARG_OID(0);
int64 result;
PgStat_TableStatus *tabentry;
PgStat_TableXactStatus *trans;
if ((tabentry = find_tabstat_entry(relid)) == NULL)
result = 0;
else
{
result = tabentry->t_counts.t_tuples_inserted;
/* live subtransactions' counts aren't in t_tuples_inserted yet */
for (trans = tabentry->trans; trans != NULL; trans = trans->upper)
result += trans->tuples_inserted;
}
PG_RETURN_INT64(result);
}
Datum
pg_stat_get_xact_tuples_updated(PG_FUNCTION_ARGS)
{
Oid relid = PG_GETARG_OID(0);
int64 result;
PgStat_TableStatus *tabentry;
PgStat_TableXactStatus *trans;
if ((tabentry = find_tabstat_entry(relid)) == NULL)
result = 0;
else
{
result = tabentry->t_counts.t_tuples_updated;
/* live subtransactions' counts aren't in t_tuples_updated yet */
for (trans = tabentry->trans; trans != NULL; trans = trans->upper)
result += trans->tuples_updated;
}
PG_RETURN_INT64(result);
}
Datum
pg_stat_get_xact_tuples_deleted(PG_FUNCTION_ARGS)
{
Oid relid = PG_GETARG_OID(0);
int64 result;
PgStat_TableStatus *tabentry;
PgStat_TableXactStatus *trans;
if ((tabentry = find_tabstat_entry(relid)) == NULL)
result = 0;
else
{
result = tabentry->t_counts.t_tuples_deleted;
/* live subtransactions' counts aren't in t_tuples_deleted yet */
for (trans = tabentry->trans; trans != NULL; trans = trans->upper)
result += trans->tuples_deleted;
}
PG_RETURN_INT64(result);
}
Datum
pg_stat_get_xact_tuples_hot_updated(PG_FUNCTION_ARGS)
{
Oid relid = PG_GETARG_OID(0);
int64 result;
PgStat_TableStatus *tabentry;
if ((tabentry = find_tabstat_entry(relid)) == NULL)
result = 0;
else
result = (int64) (tabentry->t_counts.t_tuples_hot_updated);
PG_RETURN_INT64(result);
}
Datum
pg_stat_get_xact_blocks_fetched(PG_FUNCTION_ARGS)
{
Oid relid = PG_GETARG_OID(0);
int64 result;
PgStat_TableStatus *tabentry;
if ((tabentry = find_tabstat_entry(relid)) == NULL)
result = 0;
else
result = (int64) (tabentry->t_counts.t_blocks_fetched);
PG_RETURN_INT64(result);
}
Datum
pg_stat_get_xact_blocks_hit(PG_FUNCTION_ARGS)
{
Oid relid = PG_GETARG_OID(0);
int64 result;
PgStat_TableStatus *tabentry;
if ((tabentry = find_tabstat_entry(relid)) == NULL)
result = 0;
else
result = (int64) (tabentry->t_counts.t_blocks_hit);
PG_RETURN_INT64(result);
}
Datum
pg_stat_get_xact_function_calls(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(funcentry->f_counts.f_numcalls);
}
Datum
pg_stat_get_xact_function_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));
}
Datum
pg_stat_get_xact_function_self_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_self));
}
/* Discard the active statistics snapshot */ /* Discard the active statistics snapshot */
Datum Datum
......
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.591 2010/08/07 02:44:07 tgl Exp $ * $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.592 2010/08/08 16:27:04 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -53,6 +53,6 @@ ...@@ -53,6 +53,6 @@
*/ */
/* yyyymmddN */ /* yyyymmddN */
#define CATALOG_VERSION_NO 201008061 #define CATALOG_VERSION_NO 201008071
#endif #endif
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.575 2010/08/05 18:21:17 tgl Exp $ * $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.576 2010/08/08 16:27:04 tgl Exp $
* *
* NOTES * NOTES
* The script catalog/genbki.pl reads this file and generates .bki * The script catalog/genbki.pl reads this file and generates .bki
...@@ -3093,6 +3093,31 @@ DESCR("statistics: execution time of function"); ...@@ -3093,6 +3093,31 @@ DESCR("statistics: execution time of function");
DATA(insert OID = 2980 ( pg_stat_get_function_self_time PGNSP PGUID 12 1 0 0 f f f t f s 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_function_self_time _null_ _null_ _null_ )); DATA(insert OID = 2980 ( pg_stat_get_function_self_time PGNSP PGUID 12 1 0 0 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"); DESCR("statistics: self execution time of function");
DATA(insert OID = 3037 ( pg_stat_get_xact_numscans PGNSP PGUID 12 1 0 0 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");
DATA(insert OID = 3038 ( pg_stat_get_xact_tuples_returned PGNSP PGUID 12 1 0 0 f f f t f v 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_xact_tuples_returned _null_ _null_ _null_ ));
DESCR("statistics: number of tuples read by seqscan in current transaction");
DATA(insert OID = 3039 ( pg_stat_get_xact_tuples_fetched PGNSP PGUID 12 1 0 0 f f f t f v 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_xact_tuples_fetched _null_ _null_ _null_ ));
DESCR("statistics: number of tuples fetched by idxscan in current transaction");
DATA(insert OID = 3040 ( pg_stat_get_xact_tuples_inserted PGNSP PGUID 12 1 0 0 f f f t f v 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_xact_tuples_inserted _null_ _null_ _null_ ));
DESCR("statistics: number of tuples inserted in current transaction");
DATA(insert OID = 3041 ( pg_stat_get_xact_tuples_updated PGNSP PGUID 12 1 0 0 f f f t f v 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_xact_tuples_updated _null_ _null_ _null_ ));
DESCR("statistics: number of tuples updated in current transaction");
DATA(insert OID = 3042 ( pg_stat_get_xact_tuples_deleted PGNSP PGUID 12 1 0 0 f f f t f v 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_xact_tuples_deleted _null_ _null_ _null_ ));
DESCR("statistics: number of tuples deleted in current transaction");
DATA(insert OID = 3043 ( pg_stat_get_xact_tuples_hot_updated PGNSP PGUID 12 1 0 0 f f f t f v 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_xact_tuples_hot_updated _null_ _null_ _null_ ));
DESCR("statistics: number of tuples hot updated in current transaction");
DATA(insert OID = 3044 ( pg_stat_get_xact_blocks_fetched PGNSP PGUID 12 1 0 0 f f f t f v 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_xact_blocks_fetched _null_ _null_ _null_ ));
DESCR("statistics: number of blocks fetched in current transaction");
DATA(insert OID = 3045 ( pg_stat_get_xact_blocks_hit PGNSP PGUID 12 1 0 0 f f f t f v 1 0 20 "26" _null_ _null_ _null_ _null_ pg_stat_get_xact_blocks_hit _null_ _null_ _null_ ));
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 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 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 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 = 2230 ( pg_stat_clear_snapshot PGNSP PGUID 12 1 0 0 f f f f f v 0 0 2278 "" _null_ _null_ _null_ _null_ pg_stat_clear_snapshot _null_ _null_ _null_ )); DATA(insert OID = 2230 ( pg_stat_clear_snapshot PGNSP PGUID 12 1 0 0 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"); DESCR("statistics: discard current transaction's statistics snapshot");
DATA(insert OID = 2274 ( pg_stat_reset PGNSP PGUID 12 1 0 0 f f f f f v 0 0 2278 "" _null_ _null_ _null_ _null_ pg_stat_reset _null_ _null_ _null_ )); DATA(insert OID = 2274 ( pg_stat_reset PGNSP PGUID 12 1 0 0 f f f f f v 0 0 2278 "" _null_ _null_ _null_ _null_ pg_stat_reset _null_ _null_ _null_ ));
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* *
* Copyright (c) 2001-2010, PostgreSQL Global Development Group * Copyright (c) 2001-2010, PostgreSQL Global Development Group
* *
* $PostgreSQL: pgsql/src/include/pgstat.h,v 1.89 2010/02/26 02:01:20 momjian Exp $ * $PostgreSQL: pgsql/src/include/pgstat.h,v 1.90 2010/08/08 16:27:06 tgl Exp $
* ---------- * ----------
*/ */
#ifndef PGSTAT_H #ifndef PGSTAT_H
...@@ -692,6 +692,9 @@ extern void pgstat_report_xact_timestamp(TimestampTz tstamp); ...@@ -692,6 +692,9 @@ extern void pgstat_report_xact_timestamp(TimestampTz tstamp);
extern void pgstat_report_waiting(bool waiting); extern void pgstat_report_waiting(bool waiting);
extern const char *pgstat_get_backend_current_activity(int pid, bool checkUser); extern const char *pgstat_get_backend_current_activity(int pid, bool checkUser);
extern PgStat_TableStatus *find_tabstat_entry(Oid rel_id);
extern PgStat_BackendFunctionEntry *find_funcstat_entry(Oid func_id);
extern void pgstat_initstats(Relation rel); extern void pgstat_initstats(Relation rel);
/* nontransactional event counts are simple enough to inline */ /* nontransactional event counts are simple enough to inline */
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment