📄 monitoring.sgml
字号:
<structname>pg_stat_all_indexes</>.<structfield>idx_tup_read</> count(s) for the index(es) it uses, and it increments the <structname>pg_stat_all_tables</>.<structfield>idx_tup_fetch</> count for the table, but it does not affect <structname>pg_stat_all_indexes</>.<structfield>idx_tup_fetch</>. </para> <note> <para> Before <productname>PostgreSQL</productname> 8.1, the <structfield>idx_tup_read</> and <structfield>idx_tup_fetch</> counts were essentially always equal. Now they can be different even without considering bitmap scans, because <structfield>idx_tup_read</> counts index entries retrieved from the index while <structfield>idx_tup_fetch</> 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. </para> </note> <para> The <structname>pg_statio_</> 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 <productname>PostgreSQL</> handles disk I/O, data that is not in the <productname>PostgreSQL</> buffer cache may still reside in the kernel's I/O cache, and may therefore still be fetched without requiring a physical read. Users interested in obtaining more detailed information on <productname>PostgreSQL</> I/O behavior are advised to use the <productname>PostgreSQL</> statistics collector in combination with operating system utilities that allow insight into the kernel's handling of I/O. </para> <para> 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 <xref linkend="monitoring-stats-funcs-table">. 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. (Note that only tables and indexes 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. </para> <table id="monitoring-stats-funcs-table"> <title>Statistics Access Functions</title> <tgroup cols="3"> <thead> <row> <entry>Function</entry> <entry>Return Type</entry> <entry>Description</entry> </row> </thead> <tbody> <row> <entry><literal><function>pg_stat_get_db_numbackends</function>(<type>oid</type>)</literal></entry> <entry><type>integer</type></entry> <entry> Number of active server processes for database </entry> </row> <row> <entry><literal><function>pg_stat_get_db_xact_commit</function>(<type>oid</type>)</literal></entry> <entry><type>bigint</type></entry> <entry> Transactions committed in database </entry> </row> <row> <entry><literal><function>pg_stat_get_db_xact_rollback</function>(<type>oid</type>)</literal></entry> <entry><type>bigint</type></entry> <entry> Transactions rolled back in database </entry> </row> <row> <entry><literal><function>pg_stat_get_db_blocks_fetched</function>(<type>oid</type>)</literal></entry> <entry><type>bigint</type></entry> <entry> Number of disk block fetch requests for database </entry> </row> <row> <entry><literal><function>pg_stat_get_db_blocks_hit</function>(<type>oid</type>)</literal></entry> <entry><type>bigint</type></entry> <entry> Number of disk block fetch requests found in cache for database </entry> </row> <row> <entry><literal><function>pg_stat_get_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 </entry> </row> <row> <entry><literal><function>pg_stat_get_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 </entry> </row> <row> <entry><literal><function>pg_stat_get_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 </entry> </row> <row> <entry><literal><function>pg_stat_get_tuples_inserted</function>(<type>oid</type>)</literal></entry> <entry><type>bigint</type></entry> <entry> Number of rows inserted into table </entry> </row> <row> <entry><literal><function>pg_stat_get_tuples_updated</function>(<type>oid</type>)</literal></entry> <entry><type>bigint</type></entry> <entry> Number of rows updated in table </entry> </row> <row> <entry><literal><function>pg_stat_get_tuples_deleted</function>(<type>oid</type>)</literal></entry> <entry><type>bigint</type></entry> <entry> Number of rows deleted from table </entry> </row> <row> <entry><literal><function>pg_stat_get_blocks_fetched</function>(<type>oid</type>)</literal></entry> <entry><type>bigint</type></entry> <entry> Number of disk block fetch requests for table or index </entry> </row> <row> <entry><literal><function>pg_stat_get_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 </entry> </row> <row> <entry><literal><function>pg_stat_get_backend_idset</function>()</literal></entry> <entry><type>setof integer</type></entry> <entry> Set of currently active server process numbers (from 1 to the number of active server processes). See usage example in the text </entry> </row> <row> <entry><literal><function>pg_backend_pid</function>()</literal></entry> <entry><type>integer</type></entry> <entry> Process ID of the server process attached to the current session </entry> </row> <row> <entry><literal><function>pg_stat_get_backend_pid</function>(<type>integer</type>)</literal></entry> <entry><type>integer</type></entry> <entry> Process ID of the given server process </entry> </row> <row> <entry><literal><function>pg_stat_get_backend_dbid</function>(<type>integer</type>)</literal></entry> <entry><type>oid</type></entry> <entry> Database ID of the given server process </entry> </row> <row> <entry><literal><function>pg_stat_get_backend_userid</function>(<type>integer</type>)</literal></entry> <entry><type>oid</type></entry> <entry> User ID of the given server process </entry> </row> <row> <entry><literal><function>pg_stat_get_backend_activity</function>(<type>integer</type>)</literal></entry> <entry><type>text</type></entry> <entry> Active command of the given server process (null if the current user is not a superuser nor the same user as that of the session being queried, or <varname>stats_command_string</varname> is not on) </entry> </row> <row> <entry><literal><function>pg_stat_get_backend_activity_start</function>(<type>integer</type>)</literal></entry> <entry><type>timestamp with time zone</type></entry> <entry> The time at which the given server process' currently executing query was started (null if the current user is not a superuser nor the same user as that of the session being queried, or <varname>stats_command_string</varname> is not on) </entry> </row> <row> <entry><literal><function>pg_stat_get_backend_start</function>(<type>integer</type>)</literal></entry> <entry><type>timestamp with time zone</type></entry> <entry> 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 </entry> </row> <row> <entry><literal><function>pg_stat_get_backend_client_addr</function>(<type>integer</type>)</literal></entry> <entry><type>inet</type></entry> <entry> 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 </entry> </row> <row> <entry><literal><function>pg_stat_get_backend_client_port</function>(<type>integer</type>)</literal></entry> <entry><type>integer</type></entry> <entry> The IP 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 </entry> </row> <row> <entry><literal><function>pg_stat_reset</function>()</literal></entry> <entry><type>boolean</type></entry> <entry> Reset all currently collected statistics </entry> </row> </tbody> </tgroup> </table> <note> <para> <function>blocks_fetched</function> minus <function>blocks_hit</function> gives the number of kernel <function>read()</> calls issued for the table, index, or database; but the actual number of physical reads is usually lower due to kernel-level buffering. </para> </note> <para> The function <function>pg_stat_get_backend_idset</function> provides a convenient way to generate one row for each active server process. For example, to show the <acronym>PID</>s and current queries of all server processes:<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;</programlisting> </para> </sect2> </sect1> <sect1 id="monitoring-locks"> <title>Viewing Locks</title> <indexterm zone="monitoring-locks"> <primary>lock</primary> <secondary>monitoring</secondary> </indexterm> <para> Another useful tool for monitoring database activity is the <structname>pg_locks</structname> system table. It allows the database administrator to view information about the outstanding locks in the lock manager. For example, this capability can be used to: <itemizedlist> <listitem> <para> View all the locks currently outstanding, all the locks on relations in a particular database, all the locks on a particular relation, or all the locks held by a particular <productname>PostgreSQL</productname> session. </para> </listitem> <listitem> <para> Determine the relation in the current database with the most ungranted locks (which might be a source of contention among database clients). </para> </listitem> <listitem> <para> Determine the effect of lock contention on overall database performance, as well as the extent to which contention varies with overall database traffic. </para> </listitem> </itemizedlist> Details of the <structname>pg_locks</structname> view appear in <xref linkend="view-pg-locks">. For more information on locking and managing concurrency with <productname>PostgreSQL</productname>, refer to <xref linkend="mvcc">. </para> </sect1></chapter><!-- Keep this comment at the end of the fileLocal variables:mode:sgmlsgml-omittag:nilsgml-shorttag:tsgml-minimize-attributes:nilsgml-always-quote-attributes:tsgml-indent-step:1sgml-indent-data:tsgml-parent-document:nilsgml-default-dtd-file:"./reference.ced"sgml-exposed-tags:nilsgml-local-catalogs:("/usr/lib/sgml/catalog")sgml-local-ecat-files:nilEnd:-->
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -