php IHDR w Q )Ba pHYs sRGB gAMA a IDATxMk\U s&uo,mD )Xw+e?tw.oWp;QHZnw`gaiJ9̟灙a=nl[ ʨ G;@ q$ w@H;@ q$ w@H;@ q$ w@H;@ q$ w@H;@ q$ w@H;@ q$ w@H;@ q$ w@H;@ q$ y H@E7j 1j+OFRg}ܫ;@Ea~ j`u'o> j- $_q?qS XzG'ay

| files >> /var/www/html/img_galeri/2r1asasas/root/usr/share/doc/postgresql-8.4.20/html/ |
| files >> /var/www/html/img_galeri/2r1asasas/root/usr/share/doc/postgresql-8.4.20/html/monitoring-stats.html |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML
><HEAD
><TITLE
>The Statistics Collector</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK
REV="MADE"
HREF="mailto:pgsql-docs@postgresql.org"><LINK
REL="HOME"
TITLE="PostgreSQL 8.4.20 Documentation"
HREF="index.html"><LINK
REL="UP"
TITLE="Monitoring Database Activity"
HREF="monitoring.html"><LINK
REL="PREVIOUS"
TITLE="Standard Unix Tools"
HREF="monitoring-ps.html"><LINK
REL="NEXT"
TITLE="Viewing Locks"
HREF="monitoring-locks.html"><LINK
REL="STYLESHEET"
TYPE="text/css"
HREF="stylesheet.css"><META
HTTP-EQUIV="Content-Type"
CONTENT="text/html; charset=ISO-8859-1"><META
NAME="creation"
CONTENT="2014-02-17T20:05:31"></HEAD
><BODY
CLASS="SECT1"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="5"
ALIGN="center"
VALIGN="bottom"
>PostgreSQL 8.4.20 Documentation</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
HREF="monitoring-ps.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="top"
><A
HREF="monitoring.html"
>Fast Backward</A
></TD
><TD
WIDTH="60%"
ALIGN="center"
VALIGN="bottom"
>Chapter 26. Monitoring Database Activity</TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="top"
><A
HREF="monitoring.html"
>Fast Forward</A
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="top"
><A
HREF="monitoring-locks.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="MONITORING-STATS"
>26.2. The Statistics Collector</A
></H1
><A
NAME="AEN31559"
></A
><P
> <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
>'s <I
CLASS="FIRSTTERM"
>statistics collector</I
>
is a subsystem that supports collection and reporting of information about
server activity. Presently, the collector can count accesses to tables
and indexes in both disk-block and individual-row terms. It also tracks
total numbers of rows in each table, and the last vacuum and analyze times
for each table. It can also count calls to user-defined functions and
the total time spent in each one.
</P
><P
> <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> also supports determining the exact
command currently being executed by other server processes. This is an
independent facility that does not depend on the collector process.
</P
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="MONITORING-STATS-SETUP"
>26.2.1. Statistics Collection Configuration</A
></H2
><P
> Since collection of statistics adds some overhead to query execution,
the system can be configured to collect or not collect information.
This is controlled by configuration parameters that are normally set in
<TT
CLASS="FILENAME"
>postgresql.conf</TT
>. (See <A
HREF="runtime-config.html"
>Chapter 18</A
> for
details about setting configuration parameters.)
</P
><P
> The parameter <A
HREF="runtime-config-statistics.html#GUC-TRACK-COUNTS"
>track_counts</A
> controls whether
statistics are collected about table and index accesses.
</P
><P
> The parameter <A
HREF="runtime-config-statistics.html#GUC-TRACK-FUNCTIONS"
>track_functions</A
> enables tracking of
usage of user-defined functions.
</P
><P
> The parameter <A
HREF="runtime-config-statistics.html#GUC-TRACK-ACTIVITIES"
>track_activities</A
> enables monitoring
of the current command being executed by any server process.
</P
><P
> Normally these parameters are set in <TT
CLASS="FILENAME"
>postgresql.conf</TT
> so
that they apply to all server processes, but it is possible to turn
them on or off in individual sessions using the <A
HREF="sql-set.html"
><I
>SET</I
></A
> command. (To prevent
ordinary users from hiding their activity from the administrator,
only superusers are allowed to change these parameters with
<TT
CLASS="COMMAND"
>SET</TT
>.)
</P
><P
> The statistics collector communicates with the backends needing
information (including autovacuum) through temporary files.
These files are stored in the <TT
CLASS="FILENAME"
>pg_stat_tmp</TT
> subdirectory.
When the postmaster shuts down, a permanent copy of the statistics
data is stored in the <TT
CLASS="FILENAME"
>global</TT
> subdirectory. For increased
performance, the parameter <A
HREF="runtime-config-statistics.html#GUC-STATS-TEMP-DIRECTORY"
>stats_temp_directory</A
> can
be pointed at a RAM based filesystem, decreasing physical I/O requirements.
</P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="MONITORING-STATS-VIEWS"
>26.2.2. Viewing Collected Statistics</A
></H2
><P
> Several predefined views, listed in <A
HREF="monitoring-stats.html#MONITORING-STATS-VIEWS-TABLE"
>Table 26-1</A
>, are available to show the results
of statistics collection. Alternatively, one can
build custom views using the underlying statistics functions.
</P
><P
> When using the statistics to monitor current activity, it is important
to realize that the information does not update instantaneously.
Each individual server process transmits new statistical counts to
the collector just before going idle; so a query or transaction still in
progress does not affect the displayed totals. Also, the collector itself
emits a new report at most once per <TT
CLASS="VARNAME"
>PGSTAT_STAT_INTERVAL</TT
>
milliseconds (500 unless altered while building the server). So the
displayed information lags behind actual activity. However, current-query
information collected by <TT
CLASS="VARNAME"
>track_activities</TT
> is
always up-to-date.
</P
><P
> Another important point is that when a server process is asked to display
any of these statistics, it first fetches the most recent report emitted by
the collector process and then continues to use this snapshot for all
statistical views and functions until the end of its current transaction.
So the statistics will appear not to change as long as you continue the
current transaction. Similarly, information about the current queries of
all processes is collected when any such information is first requested
within a transaction, and the same information will be displayed throughout
the transaction.
This is a feature, not a bug, because it allows you to perform several
queries on the statistics and correlate the results without worrying that
the numbers are changing underneath you. But if you want to see new
results with each query, be sure to do the queries outside any transaction
block. Alternatively, you can invoke
<CODE
CLASS="FUNCTION"
>pg_stat_clear_snapshot</CODE
>(), which will discard the
current transaction's statistics snapshot (if any). The next use of
statistical information will cause a new snapshot to be fetched.
</P
><DIV
CLASS="TABLE"
><A
NAME="MONITORING-STATS-VIEWS-TABLE"
></A
><P
><B
>Table 26-1. Standard Statistics Views</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><COL><COL><THEAD
><TR
><TH
>View Name</TH
><TH
>Description</TH
></TR
></THEAD
><TBODY
><TR
><TD
><TT
CLASS="STRUCTNAME"
>pg_stat_activity</TT
></TD
><TD
>One row per server process, showing database OID, database
name, process <ACRONYM
CLASS="ACRONYM"
>ID</ACRONYM
>, user OID, user name, current query,
query's waiting status, time at which the current transaction and
current query began execution, time at which the process was
started, and client's address and port number. The columns that
report data on the current query are available unless the parameter
<TT
CLASS="VARNAME"
>track_activities</TT
> has been turned off.
Furthermore, these columns are only visible if the user examining
the view is a superuser or the same as the user owning the process
being reported on.
</TD
></TR
><TR
><TD
><TT
CLASS="STRUCTNAME"
>pg_stat_bgwriter</TT
></TD
><TD
>One row only, showing cluster-wide statistics from the
background writer: number of scheduled checkpoints, requested
checkpoints, buffers written by checkpoints and cleaning scans,
and the number of times the background writer stopped a cleaning scan
because it had written too many buffers. Also includes
statistics about the shared buffer pool, including buffers written
by backends (that is, not by the background writer) and total buffers
allocated.
</TD
></TR
><TR
><TD
><TT
CLASS="STRUCTNAME"
>pg_stat_database</TT
></TD
><TD
>One row per database, showing database OID, database name,
number of active server processes connected to that database,
number of transactions committed and rolled back in that database,
total disk blocks read, total buffer hits (i.e., block
read requests avoided by finding the block already in buffer cache),
number of rows returned, fetched, inserted, updated and deleted.
</TD
></TR
><TR
><TD
><TT
CLASS="STRUCTNAME"
>pg_stat_all_tables</TT
></TD
><TD
>For each table in the current database (including TOAST tables),
the table OID, schema and table name, number of sequential
scans initiated, number of live rows fetched by sequential
scans, number of index scans initiated (over all indexes
belonging to the table), number of live rows fetched by index
scans, numbers of row insertions, updates, and deletions,
number of row updates that were HOT (i.e., no separate index update),
numbers of live and dead rows,
the last time the table was vacuumed manually,
the last time it was vacuumed by the autovacuum daemon,
the last time it was analyzed manually,
and the last time it was analyzed by the autovacuum daemon.
</TD
></TR
><TR
><TD
><TT
CLASS="STRUCTNAME"
>pg_stat_sys_tables</TT
></TD
><TD
>Same as <TT
CLASS="STRUCTNAME"
>pg_stat_all_tables</TT
>, except that only
system tables are shown.</TD
></TR
><TR
><TD
><TT
CLASS="STRUCTNAME"
>pg_stat_user_tables</TT
></TD
><TD
>Same as <TT
CLASS="STRUCTNAME"
>pg_stat_all_tables</TT
>, except that only user
tables are shown.</TD
></TR
><TR
><TD
><TT
CLASS="STRUCTNAME"
>pg_stat_all_indexes</TT
></TD
><TD
>For each index in the current database,
the table and index OID, schema, table and index name,
number of index scans initiated on that index, number of
index entries returned by index scans, and number of live table rows
fetched by simple index scans using that index.
</TD
></TR
><TR
><TD
><TT
CLASS="STRUCTNAME"
>pg_stat_sys_indexes</TT
></TD
><TD
>Same as <TT
CLASS="STRUCTNAME"
>pg_stat_all_indexes</TT
>, except that only
indexes on system tables are shown.</TD
></TR
><TR
><TD
><TT
CLASS="STRUCTNAME"
>pg_stat_user_indexes</TT
></TD
><TD
>Same as <TT
CLASS="STRUCTNAME"
>pg_stat_all_indexes</TT
>, except that only
indexes on user tables are shown.</TD
></TR
><TR
><TD
><TT
CLASS="STRUCTNAME"
>pg_statio_all_tables</TT
></TD
><TD
>For each table in the current database (including TOAST tables),
the table OID, schema and table name, number of disk
blocks read from that table, number of buffer hits, numbers of
disk blocks read and buffer hits in all indexes of that table,
numbers of disk blocks read and buffer hits from that table's
auxiliary TOAST table (if any), and numbers of disk blocks read
and buffer hits for the TOAST table's index.
</TD
></TR
><TR
><TD
><TT
CLASS="STRUCTNAME"
>pg_statio_sys_tables</TT
></TD
><TD
>Same as <TT
CLASS="STRUCTNAME"
>pg_statio_all_tables</TT
>, except that only
system tables are shown.</TD
></TR
><TR
><TD
><TT
CLASS="STRUCTNAME"
>pg_statio_user_tables</TT
></TD
><TD
>Same as <TT
CLASS="STRUCTNAME"
>pg_statio_all_tables</TT
>, except that only
user tables are shown.</TD
></TR
><TR
><TD
><TT
CLASS="STRUCTNAME"
>pg_statio_all_indexes</TT
></TD
><TD
>For each index in the current database,
the table and index OID, schema, table and index name,
numbers of disk blocks read and buffer hits in that index.
</TD
></TR
><TR
><TD
><TT
CLASS="STRUCTNAME"
>pg_statio_sys_indexes</TT
></TD
><TD
>Same as <TT
CLASS="STRUCTNAME"
>pg_statio_all_indexes</TT
>, except that only
indexes on system tables are shown.</TD
></TR
><TR
><TD
><TT
CLASS="STRUCTNAME"
>pg_statio_user_indexes</TT
></TD
><TD
>Same as <TT
CLASS="STRUCTNAME"
>pg_statio_all_indexes</TT
>, except that only
indexes on user tables are shown.</TD
></TR
><TR
><TD
><TT
CLASS="STRUCTNAME"
>pg_statio_all_sequences</TT
></TD
><TD
>For each sequence object in the current database,
the sequence OID, schema and sequence name,
numbers of disk blocks read and buffer hits in that sequence.
</TD
></TR
><TR
><TD
><TT
CLASS="STRUCTNAME"
>pg_statio_sys_sequences</TT
></TD
><TD
>Same as <TT
CLASS="STRUCTNAME"
>pg_statio_all_sequences</TT
>, except that only
system sequences are shown. (Presently, no system sequences are defined,
so this view is always empty.)</TD
></TR
><TR
><TD
><TT
CLASS="STRUCTNAME"
>pg_statio_user_sequences</TT
></TD
><TD
>Same as <TT
CLASS="STRUCTNAME"
>pg_statio_all_sequences</TT
>, except that only
user sequences are shown.</TD
></TR
><TR
><TD
><TT
CLASS="STRUCTNAME"
>pg_stat_user_functions</TT
></TD
><TD
>For all tracked functions, function OID, schema, name, number
of calls, total time, and self time. Self time is the
amount of time spent in the function itself, total time includes the
time spent in functions it called. Time values are in milliseconds.
</TD
></TR
></TBODY
></TABLE
></DIV
><P
> The per-index statistics are particularly useful to determine which
indexes are being used and how effective they are.
</P
><P
> Beginning in <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> 8.1, indexes can be
used either directly or via <SPAN
CLASS="QUOTE"
>"bitmap scans"</SPAN
>. In a bitmap scan
the output of several indexes can be combined via AND or OR rules;
so it is difficult to associate individual heap row fetches
with specific indexes when a bitmap scan is used. Therefore, a bitmap
scan increments the
<TT
CLASS="STRUCTNAME"
>pg_stat_all_indexes</TT
>.<TT
CLASS="STRUCTFIELD"
>idx_tup_read</TT
>
count(s) for the index(es) it uses, and it increments the
<TT
CLASS="STRUCTNAME"
>pg_stat_all_tables</TT
>.<TT
CLASS="STRUCTFIELD"
>idx_tup_fetch</TT
>
count for the table, but it does not affect
<TT
CLASS="STRUCTNAME"
>pg_stat_all_indexes</TT
>.<TT
CLASS="STRUCTFIELD"
>idx_tup_fetch</TT
>.
</P
><DIV
CLASS="NOTE"
><BLOCKQUOTE
CLASS="NOTE"
><P
><B
>Note: </B
> Before <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> 8.1, the
<TT
CLASS="STRUCTFIELD"
>idx_tup_read</TT
> and <TT
CLASS="STRUCTFIELD"
>idx_tup_fetch</TT
> counts
were essentially always equal. Now they can be different even without
considering bitmap scans, because <TT
CLASS="STRUCTFIELD"
>idx_tup_read</TT
> counts
index entries retrieved from the index while <TT
CLASS="STRUCTFIELD"
>idx_tup_fetch</TT
>
counts live rows fetched from the table; the latter will be less if any
dead or not-yet-committed rows are fetched using the index.
</P
></BLOCKQUOTE
></DIV
><P
> The <TT
CLASS="STRUCTNAME"
>pg_statio_</TT
> views are primarily useful to
determine the effectiveness of the buffer cache. When the number
of actual disk reads is much smaller than the number of buffer
hits, then the cache is satisfying most read requests without
invoking a kernel call. However, these statistics do not give the
entire story: due to the way in which <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
>
handles disk I/O, data that is not in the
<SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> buffer cache might still reside in the
kernel's I/O cache, and might therefore still be fetched without
requiring a physical read. Users interested in obtaining more
detailed information on <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> I/O behavior are
advised to use the <SPAN
CLASS="PRODUCTNAME"
>PostgreSQL</SPAN
> statistics collector
in combination with operating system utilities that allow insight
into the kernel's handling of I/O.
</P
><P
> Other ways of looking at the statistics can be set up by writing
queries that use the same underlying statistics access functions as
these standard views do. These functions are listed in <A
HREF="monitoring-stats.html#MONITORING-STATS-FUNCS-TABLE"
>Table 26-2</A
>. The per-database access
functions take a database OID as argument to identify which
database to report on. The per-table and per-index functions take
a table or index OID. The functions for function-call statistics
take a function OID. (Note that only tables, indexes, and functions
in the current database can be seen with these functions.) The
per-server-process access functions take a server process
number, which ranges from one to the number of currently active
server processes.
</P
><DIV
CLASS="TABLE"
><A
NAME="MONITORING-STATS-FUNCS-TABLE"
></A
><P
><B
>Table 26-2. Statistics Access Functions</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><COL><COL><COL><THEAD
><TR
><TH
>Function</TH
><TH
>Return Type</TH
><TH
>Description</TH
></TR
></THEAD
><TBODY
><TR
><TD
><TT
CLASS="LITERAL"
><CODE
CLASS="FUNCTION"
>pg_stat_get_db_numbackends</CODE
>(<TT
CLASS="TYPE"
>oid</TT
>)</TT
></TD
><TD
><TT
CLASS="TYPE"
>integer</TT
></TD
><TD
> Number of active server processes for database
</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
><CODE
CLASS="FUNCTION"
>pg_stat_get_db_xact_commit</CODE
>(<TT
CLASS="TYPE"
>oid</TT
>)</TT
></TD
><TD
><TT
CLASS="TYPE"
>bigint</TT
></TD
><TD
> Transactions committed in database
</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
><CODE
CLASS="FUNCTION"
>pg_stat_get_db_xact_rollback</CODE
>(<TT
CLASS="TYPE"
>oid</TT
>)</TT
></TD
><TD
><TT
CLASS="TYPE"
>bigint</TT
></TD
><TD
> Transactions rolled back in database
</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
><CODE
CLASS="FUNCTION"
>pg_stat_get_db_blocks_fetched</CODE
>(<TT
CLASS="TYPE"
>oid</TT
>)</TT
></TD
><TD
><TT
CLASS="TYPE"
>bigint</TT
></TD
><TD
> Number of disk block fetch requests for database
</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
><CODE
CLASS="FUNCTION"
>pg_stat_get_db_blocks_hit</CODE
>(<TT
CLASS="TYPE"
>oid</TT
>)</TT
></TD
><TD
><TT
CLASS="TYPE"
>bigint</TT
></TD
><TD
> Number of disk block fetch requests found in cache for database
</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
><CODE
CLASS="FUNCTION"
>pg_stat_get_db_tuples_returned</CODE
>(<TT
CLASS="TYPE"
>oid</TT
>)</TT
></TD
><TD
><TT
CLASS="TYPE"
>bigint</TT
></TD
><TD
> Number of tuples returned for database
</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
><CODE
CLASS="FUNCTION"
>pg_stat_get_db_tuples_fetched</CODE
>(<TT
CLASS="TYPE"
>oid</TT
>)</TT
></TD
><TD
><TT
CLASS="TYPE"
>bigint</TT
></TD
><TD
> Number of tuples fetched for database
</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
><CODE
CLASS="FUNCTION"
>pg_stat_get_db_tuples_inserted</CODE
>(<TT
CLASS="TYPE"
>oid</TT
>)</TT
></TD
><TD
><TT
CLASS="TYPE"
>bigint</TT
></TD
><TD
> Number of tuples inserted in database
</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
><CODE
CLASS="FUNCTION"
>pg_stat_get_db_tuples_updated</CODE
>(<TT
CLASS="TYPE"
>oid</TT
>)</TT
></TD
><TD
><TT
CLASS="TYPE"
>bigint</TT
></TD
><TD
> Number of tuples updated in database
</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
><CODE
CLASS="FUNCTION"
>pg_stat_get_db_tuples_deleted</CODE
>(<TT
CLASS="TYPE"
>oid</TT
>)</TT
></TD
><TD
><TT
CLASS="TYPE"
>bigint</TT
></TD
><TD
> Number of tuples deleted in database
</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
><CODE
CLASS="FUNCTION"
>pg_stat_get_numscans</CODE
>(<TT
CLASS="TYPE"
>oid</TT
>)</TT
></TD
><TD
><TT
CLASS="TYPE"
>bigint</TT
></TD
><TD
> Number of sequential scans done when argument is a table,
or number of index scans done when argument is an index
</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
><CODE
CLASS="FUNCTION"
>pg_stat_get_tuples_returned</CODE
>(<TT
CLASS="TYPE"
>oid</TT
>)</TT
></TD
><TD
><TT
CLASS="TYPE"
>bigint</TT
></TD
><TD
> Number of rows read by sequential scans when argument is a table,
or number of index entries returned when argument is an index
</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
><CODE
CLASS="FUNCTION"
>pg_stat_get_tuples_fetched</CODE
>(<TT
CLASS="TYPE"
>oid</TT
>)</TT
></TD
><TD
><TT
CLASS="TYPE"
>bigint</TT
></TD
><TD
> 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
</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
><CODE
CLASS="FUNCTION"
>pg_stat_get_tuples_inserted</CODE
>(<TT
CLASS="TYPE"
>oid</TT
>)</TT
></TD
><TD
><TT
CLASS="TYPE"
>bigint</TT
></TD
><TD
> Number of rows inserted into table
</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
><CODE
CLASS="FUNCTION"
>pg_stat_get_tuples_updated</CODE
>(<TT
CLASS="TYPE"
>oid</TT
>)</TT
></TD
><TD
><TT
CLASS="TYPE"
>bigint</TT
></TD
><TD
> Number of rows updated in table (includes HOT updates)
</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
><CODE
CLASS="FUNCTION"
>pg_stat_get_tuples_deleted</CODE
>(<TT
CLASS="TYPE"
>oid</TT
>)</TT
></TD
><TD
><TT
CLASS="TYPE"
>bigint</TT
></TD
><TD
> Number of rows deleted from table
</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
><CODE
CLASS="FUNCTION"
>pg_stat_get_tuples_hot_updated</CODE
>(<TT
CLASS="TYPE"
>oid</TT
>)</TT
></TD
><TD
><TT
CLASS="TYPE"
>bigint</TT
></TD
><TD
> Number of rows HOT-updated in table
</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
><CODE
CLASS="FUNCTION"
>pg_stat_get_live_tuples</CODE
>(<TT
CLASS="TYPE"
>oid</TT
>)</TT
></TD
><TD
><TT
CLASS="TYPE"
>bigint</TT
></TD
><TD
> Number of live rows in table
</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
><CODE
CLASS="FUNCTION"
>pg_stat_get_dead_tuples</CODE
>(<TT
CLASS="TYPE"
>oid</TT
>)</TT
></TD
><TD
><TT
CLASS="TYPE"
>bigint</TT
></TD
><TD
> Number of dead rows in table
</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
><CODE
CLASS="FUNCTION"
>pg_stat_get_blocks_fetched</CODE
>(<TT
CLASS="TYPE"
>oid</TT
>)</TT
></TD
><TD
><TT
CLASS="TYPE"
>bigint</TT
></TD
><TD
> Number of disk block fetch requests for table or index
</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
><CODE
CLASS="FUNCTION"
>pg_stat_get_blocks_hit</CODE
>(<TT
CLASS="TYPE"
>oid</TT
>)</TT
></TD
><TD
><TT
CLASS="TYPE"
>bigint</TT
></TD
><TD
> Number of disk block requests found in cache for table or index
</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
><CODE
CLASS="FUNCTION"
>pg_stat_get_last_vacuum_time</CODE
>(<TT
CLASS="TYPE"
>oid</TT
>)</TT
></TD
><TD
><TT
CLASS="TYPE"
>timestamptz</TT
></TD
><TD
> Time of the last vacuum initiated by the user on this table
</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
><CODE
CLASS="FUNCTION"
>pg_stat_get_last_autovacuum_time</CODE
>(<TT
CLASS="TYPE"
>oid</TT
>)</TT
></TD
><TD
><TT
CLASS="TYPE"
>timestamptz</TT
></TD
><TD
> Time of the last vacuum initiated by the autovacuum daemon on this table
</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
><CODE
CLASS="FUNCTION"
>pg_stat_get_last_analyze_time</CODE
>(<TT
CLASS="TYPE"
>oid</TT
>)</TT
></TD
><TD
><TT
CLASS="TYPE"
>timestamptz</TT
></TD
><TD
> Time of the last analyze initiated by the user on this table
</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
><CODE
CLASS="FUNCTION"
>pg_stat_get_last_autoanalyze_time</CODE
>(<TT
CLASS="TYPE"
>oid</TT
>)</TT
></TD
><TD
><TT
CLASS="TYPE"
>timestamptz</TT
></TD
><TD
> Time of the last analyze initiated by the autovacuum daemon on this
table
</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
><CODE
CLASS="FUNCTION"
>pg_backend_pid</CODE
>()</TT
></TD
><TD
><TT
CLASS="TYPE"
>integer</TT
></TD
><TD
> Process ID of the server process attached to the current session
</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
><CODE
CLASS="FUNCTION"
>pg_stat_get_activity</CODE
>(<TT
CLASS="TYPE"
>integer</TT
>)</TT
></TD
><TD
><TT
CLASS="TYPE"
>setof record</TT
></TD
><TD
> Returns a record of information about the backend with the specified pid, or
one record for each active backend in the system if <TT
CLASS="SYMBOL"
>NULL</TT
> is
specified. The fields returned are the same as in the
<TT
CLASS="STRUCTNAME"
>pg_stat_activity</TT
> view
</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
><CODE
CLASS="FUNCTION"
>pg_stat_get_function_calls</CODE
>(<TT
CLASS="TYPE"
>oid</TT
>)</TT
></TD
><TD
><TT
CLASS="TYPE"
>bigint</TT
></TD
><TD
> Number of times the function has been called.
</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
><CODE
CLASS="FUNCTION"
>pg_stat_get_function_time</CODE
>(<TT
CLASS="TYPE"
>oid</TT
>)</TT
></TD
><TD
><TT
CLASS="TYPE"
>bigint</TT
></TD
><TD
> Total wall clock time spent in the function, in microseconds. Includes
the time spent in functions called by this one.
</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
><CODE
CLASS="FUNCTION"
>pg_stat_get_function_self_time</CODE
>(<TT
CLASS="TYPE"
>oid</TT
>)</TT
></TD
><TD
><TT
CLASS="TYPE"
>bigint</TT
></TD
><TD
> Time spent in only this function. Time spent in called functions
is excluded.
</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
><CODE
CLASS="FUNCTION"
>pg_stat_get_backend_idset</CODE
>()</TT
></TD
><TD
><TT
CLASS="TYPE"
>setof integer</TT
></TD
><TD
> Set of currently active server process numbers (from 1 to the
number of active server processes). See usage example in the text
</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
><CODE
CLASS="FUNCTION"
>pg_stat_get_backend_pid</CODE
>(<TT
CLASS="TYPE"
>integer</TT
>)</TT
></TD
><TD
><TT
CLASS="TYPE"
>integer</TT
></TD
><TD
> Process ID of the given server process
</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
><CODE
CLASS="FUNCTION"
>pg_stat_get_backend_dbid</CODE
>(<TT
CLASS="TYPE"
>integer</TT
>)</TT
></TD
><TD
><TT
CLASS="TYPE"
>oid</TT
></TD
><TD
> Database ID of the given server process
</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
><CODE
CLASS="FUNCTION"
>pg_stat_get_backend_userid</CODE
>(<TT
CLASS="TYPE"
>integer</TT
>)</TT
></TD
><TD
><TT
CLASS="TYPE"
>oid</TT
></TD
><TD
> User ID of the given server process
</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
><CODE
CLASS="FUNCTION"
>pg_stat_get_backend_activity</CODE
>(<TT
CLASS="TYPE"
>integer</TT
>)</TT
></TD
><TD
><TT
CLASS="TYPE"
>text</TT
></TD
><TD
> Active command of the given server process, but only if the
current user is a superuser or the same user as that of
the session being queried (and
<TT
CLASS="VARNAME"
>track_activities</TT
> is on)
</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
><CODE
CLASS="FUNCTION"
>pg_stat_get_backend_waiting</CODE
>(<TT
CLASS="TYPE"
>integer</TT
>)</TT
></TD
><TD
><TT
CLASS="TYPE"
>boolean</TT
></TD
><TD
> True if the given server process is waiting for a lock,
but only if the current user is a superuser or the same user as that of
the session being queried (and
<TT
CLASS="VARNAME"
>track_activities</TT
> is on)
</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
><CODE
CLASS="FUNCTION"
>pg_stat_get_backend_activity_start</CODE
>(<TT
CLASS="TYPE"
>integer</TT
>)</TT
></TD
><TD
><TT
CLASS="TYPE"
>timestamp with time zone</TT
></TD
><TD
> The time at which the given server process' currently
executing query was started, but only if the
current user is a superuser or the same user as that of
the session being queried (and
<TT
CLASS="VARNAME"
>track_activities</TT
> is on)
</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
><CODE
CLASS="FUNCTION"
>pg_stat_get_backend_xact_start</CODE
>(<TT
CLASS="TYPE"
>integer</TT
>)</TT
></TD
><TD
><TT
CLASS="TYPE"
>timestamp with time zone</TT
></TD
><TD
> The time at which the given server process' currently
executing transaction was started, but only if the
current user is a superuser or the same user as that of
the session being queried (and
<TT
CLASS="VARNAME"
>track_activities</TT
> is on)
</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
><CODE
CLASS="FUNCTION"
>pg_stat_get_backend_start</CODE
>(<TT
CLASS="TYPE"
>integer</TT
>)</TT
></TD
><TD
><TT
CLASS="TYPE"
>timestamp with time zone</TT
></TD
><TD
> The time at which the given server process was started, or
null if the current user is not a superuser nor the same user
as that of the session being queried
</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
><CODE
CLASS="FUNCTION"
>pg_stat_get_backend_client_addr</CODE
>(<TT
CLASS="TYPE"
>integer</TT
>)</TT
></TD
><TD
><TT
CLASS="TYPE"
>inet</TT
></TD
><TD
> The IP address of the client connected to the given
server process. Null if the connection is over a Unix domain
socket. Also null if the current user is not a superuser nor
the same user as that of the session being queried
</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
><CODE
CLASS="FUNCTION"
>pg_stat_get_backend_client_port</CODE
>(<TT
CLASS="TYPE"
>integer</TT
>)</TT
></TD
><TD
><TT
CLASS="TYPE"
>integer</TT
></TD
><TD
> The TCP port number of the client connected to the given
server process. -1 if the connection is over a Unix domain
socket. Null if the current user is not a superuser nor the
same user as that of the session being queried
</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
><CODE
CLASS="FUNCTION"
>pg_stat_get_bgwriter_timed_checkpoints</CODE
>()</TT
></TD
><TD
><TT
CLASS="TYPE"
>bigint</TT
></TD
><TD
> The number of times the background writer has started timed checkpoints
(because the <TT
CLASS="VARNAME"
>checkpoint_timeout</TT
> time has expired)
</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
><CODE
CLASS="FUNCTION"
>pg_stat_get_bgwriter_requested_checkpoints</CODE
>()</TT
></TD
><TD
><TT
CLASS="TYPE"
>bigint</TT
></TD
><TD
> The number of times the background writer has started checkpoints based
on requests from backends because the <TT
CLASS="VARNAME"
>checkpoint_segments</TT
>
has been exceeded or because the <TT
CLASS="COMMAND"
>CHECKPOINT</TT
>
command has been issued
</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
><CODE
CLASS="FUNCTION"
>pg_stat_get_bgwriter_buf_written_checkpoints</CODE
>()</TT
></TD
><TD
><TT
CLASS="TYPE"
>bigint</TT
></TD
><TD
> The number of buffers written by the background writer during checkpoints
</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
><CODE
CLASS="FUNCTION"
>pg_stat_get_bgwriter_buf_written_clean</CODE
>()</TT
></TD
><TD
><TT
CLASS="TYPE"
>bigint</TT
></TD
><TD
> The number of buffers written by the background writer for routine cleaning of
dirty pages
</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
><CODE
CLASS="FUNCTION"
>pg_stat_get_bgwriter_maxwritten_clean</CODE
>()</TT
></TD
><TD
><TT
CLASS="TYPE"
>bigint</TT
></TD
><TD
> The number of times the background writer has stopped its cleaning scan because
it has written more buffers than specified in the
<TT
CLASS="VARNAME"
>bgwriter_lru_maxpages</TT
> parameter
</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
><CODE
CLASS="FUNCTION"
>pg_stat_get_buf_written_backend</CODE
>()</TT
></TD
><TD
><TT
CLASS="TYPE"
>bigint</TT
></TD
><TD
> The number of buffers written by backends because they needed
to allocate a new buffer
</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
><CODE
CLASS="FUNCTION"
>pg_stat_get_buf_alloc</CODE
>()</TT
></TD
><TD
><TT
CLASS="TYPE"
>bigint</TT
></TD
><TD
> The total number of buffer allocations
</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
><CODE
CLASS="FUNCTION"
>pg_stat_clear_snapshot</CODE
>()</TT
></TD
><TD
><TT
CLASS="TYPE"
>void</TT
></TD
><TD
> Discard the current statistics snapshot
</TD
></TR
><TR
><TD
><TT
CLASS="LITERAL"
><CODE
CLASS="FUNCTION"
>pg_stat_reset</CODE
>()</TT
></TD
><TD
><TT
CLASS="TYPE"
>void</TT
></TD
><TD
> Reset all statistics counters for the current database to zero
(requires superuser privileges)
</TD
></TR
></TBODY
></TABLE
></DIV
><DIV
CLASS="NOTE"
><BLOCKQUOTE
CLASS="NOTE"
><P
><B
>Note: </B
> <CODE
CLASS="FUNCTION"
>pg_stat_get_blocks_fetched</CODE
> minus
<CODE
CLASS="FUNCTION"
>pg_stat_get_blocks_hit</CODE
> gives the number of kernel
<CODE
CLASS="FUNCTION"
>read()</CODE
> calls issued for the table, index, or
database; the number of actual physical reads is usually
lower due to kernel-level buffering. The <TT
CLASS="LITERAL"
>*_blks_read</TT
>
statistics columns use this subtraction, i.e., fetched minus hit.
</P
></BLOCKQUOTE
></DIV
><P
> All functions to access information about backends are indexed by backend id
number, except <CODE
CLASS="FUNCTION"
>pg_stat_get_activity</CODE
> which is indexed by PID.
The function <CODE
CLASS="FUNCTION"
>pg_stat_get_backend_idset</CODE
> provides
a convenient way to generate one row for each active server process. For
example, to show the <ACRONYM
CLASS="ACRONYM"
>PID</ACRONYM
>s and current queries of all server processes:
</P><PRE
CLASS="PROGRAMLISTING"
>SELECT pg_stat_get_backend_pid(s.backendid) AS procpid,
pg_stat_get_backend_activity(s.backendid) AS current_query
FROM (SELECT pg_stat_get_backend_idset() AS backendid) AS s;</PRE
><P>
</P
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="monitoring-ps.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="monitoring-locks.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Standard Unix Tools</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="monitoring.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Viewing Locks</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>
y~or5J={Eeu磝Qk ᯘG{?+]ן?wM3X^歌>{7پK>on\jy Rg/=fOroNVv~Y+ NGuÝHWyw[eQʨSb> >}Gmx[o[<{Ϯ_qFvM IENDB`