From cb8b6618cefa1f87197390ae12709b46f5137a35 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Thu, 6 Oct 2005 02:29:23 +0000 Subject: Revise pgstats stuff to fix the problems with not counting accesses generated by bitmap index scans. Along the way, simplify and speed up the code for counting sequential and index scans; it was both confusing and inefficient to be taking care of that in the per-tuple loops, IMHO. initdb forced because of internal changes in pg_stat view definitions. --- doc/src/sgml/monitoring.sgml | 179 ++++++++++++++++++++++++++----------------- 1 file changed, 107 insertions(+), 72 deletions(-) (limited to 'doc/src') diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml index a5f9b41d926..9ddfc28ff49 100644 --- a/doc/src/sgml/monitoring.sgml +++ b/doc/src/sgml/monitoring.sgml @@ -1,5 +1,5 @@ @@ -185,11 +185,12 @@ postgres: user database host pgstat_stat_interval - milliseconds (500 by default). So the displayed information lags behind - actual activity. Current-query information is reported to the collector - immediately, but is still subject to the - pgstat_stat_interval delay before it becomes visible. + emits a new report at most once per PGSTAT_STAT_INTERVAL + milliseconds (500 unless altered while building the server). So the + displayed information lags behind actual activity. Current-query + information is reported to the collector immediately, but is still subject + to the PGSTAT_STAT_INTERVAL delay before it becomes + visible. @@ -220,10 +221,10 @@ postgres: user database host pg_stat_activity - One row per server process, showing process - ID, database, user, current query, the time at which - the current query began execution, the time at which the backend - was started and the client address and port number. The columns + One row per server process, showing database OID, database name, + process ID, user OID, user name, current query, time at + which the 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 only available if the parameter stats_command_string has been turned on. Furthermore, these columns read as null unless the @@ -235,114 +236,122 @@ postgres: user database host pg_stat_database - One row per database, showing the number of active backend server processes, - total transactions committed and total rolled back in that database, - total disk blocks read, and total number of buffer hits (i.e., block + 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, and total buffer hits (i.e., block read requests avoided by finding the block already in buffer cache). pg_stat_all_tables - For each table in the current database, total numbers of - sequential and index scans, total numbers of rows returned by - each type of scan, and totals of row insertions, updates, - and deletions. + 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, + and numbers of row insertions, updates, and deletions. pg_stat_sys_tables - Same as pg_stat_all_tables, except that only system tables - are shown. + Same as pg_stat_all_tables, except that only + system tables are shown. pg_stat_user_tables - Same as pg_stat_all_tables, except that only user tables - are shown. + Same as pg_stat_all_tables, except that only user + tables are shown. pg_stat_all_indexes - For each index in the current database, the total number - of index scans that have used that index, the number of index rows - read, and the number of successfully fetched heap rows. (This may - be less when there are index entries pointing to expired heap rows.) + 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. pg_stat_sys_indexes - Same as pg_stat_all_indexes, except that only indexes on - system tables are shown. + Same as pg_stat_all_indexes, except that only + indexes on system tables are shown. pg_stat_user_indexes - Same as pg_stat_all_indexes, except that only indexes on - user tables are shown. + Same as pg_stat_all_indexes, except that only + indexes on user tables are shown. pg_statio_all_tables - For each table in the current database, the total number of disk - blocks read from that table, the number of buffer hits, the numbers of - disk blocks read and buffer hits in all the indexes of that table, - the numbers of disk blocks read and buffer hits from the table's - auxiliary TOAST table (if any), and the numbers of disk blocks read + 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. pg_statio_sys_tables - Same as pg_statio_all_tables, except that only system tables - are shown. + Same as pg_statio_all_tables, except that only + system tables are shown. pg_statio_user_tables - Same as pg_statio_all_tables, except that only user tables - are shown. + Same as pg_statio_all_tables, except that only + user tables are shown. pg_statio_all_indexes - For each index in the current database, the numbers of - disk blocks read and buffer hits in that index. + 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. pg_statio_sys_indexes - Same as pg_statio_all_indexes, except that only indexes on - system tables are shown. + Same as pg_statio_all_indexes, except that only + indexes on system tables are shown. pg_statio_user_indexes - Same as pg_statio_all_indexes, except that only indexes on - user tables are shown. + Same as pg_statio_all_indexes, except that only + indexes on user tables are shown. pg_statio_all_sequences - For each sequence object in the current database, the numbers - of disk blocks read and buffer hits in that sequence. + 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. pg_statio_sys_sequences - Same as pg_statio_all_sequences, except that only system - sequences are shown. (Presently, no system sequences are defined, + Same as pg_statio_all_sequences, except that only + system sequences are shown. (Presently, no system sequences are defined, so this view is always empty.) pg_statio_user_sequences - Same as pg_statio_all_sequences, except that only user - sequences are shown. + Same as pg_statio_all_sequences, except that only + user sequences are shown. @@ -353,6 +362,32 @@ postgres: user database host + + Beginning in PostgreSQL 8.1, indexes can be + used either directly or via bitmap scans. 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 + pg_stat_all_indexes.idx_tup_read + count(s) for the index(es) it uses, and it increments the + pg_stat_all_tables.idx_tup_fetch + count for the table, but it does not affect + pg_stat_all_indexes.idx_tup_fetch. + + + + + Before PostgreSQL 8.1, the + idx_tup_read and idx_tup_fetch counts + were essentially always equal. Now they can be different even without + considering bitmap scans, because idx_tup_read counts + index entries retrieved from the index while 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. + + + The pg_statio_ views are primarily useful to determine the effectiveness of the buffer cache. When the number @@ -379,9 +414,9 @@ postgres: user database host @@ -401,7 +436,7 @@ postgres: user database host pg_stat_get_db_numbackends(oid) integer - Number of active backend processes for database + Number of active server processes for database @@ -451,7 +486,7 @@ postgres: user database host bigint Number of rows read by sequential scans when argument is a table, - or number of index rows read when argument is an index + or number of index entries returned when argument is an index @@ -459,8 +494,8 @@ postgres: user database host pg_stat_get_tuples_fetched(oid) bigint - Number of valid (unexpired) table rows fetched by sequential scans - when argument is a table, or fetched by index scans using this index + 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 @@ -507,10 +542,10 @@ postgres: user database host pg_stat_get_backend_idset() - set of integer + setof integer - Set of currently active backend process IDs (from 1 to the - number of active backend processes). See usage example in the text + Set of currently active server process numbers (from 1 to the + number of active server processes). See usage example in the text @@ -518,7 +553,7 @@ postgres: user database host pg_backend_pid() integer - Process ID of the backend process attached to the current session + Process ID of the server process attached to the current session @@ -526,7 +561,7 @@ postgres: user database host pg_stat_get_backend_pid(integer) integer - Process ID of the given backend process + Process ID of the given server process @@ -534,7 +569,7 @@ postgres: user database host pg_stat_get_backend_dbid(integer) oid - Database ID of the given backend process + Database ID of the given server process @@ -542,7 +577,7 @@ postgres: user database host pg_stat_get_backend_userid(integer) oid - User ID of the given backend process + User ID of the given server process @@ -550,7 +585,7 @@ postgres: user database host pg_stat_get_backend_activity(integer) text - Active command of the given backend process (null if the + 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 stats_command_string is not on) @@ -561,7 +596,7 @@ postgres: user database host pg_stat_get_backend_activity_start(integer) timestamp with time zone - The time at which the given backend process' currently + 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 @@ -573,7 +608,7 @@ postgres: user database host pg_stat_get_backend_start(integer) timestamp with time zone - The time at which the given backend process was started, or + 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 @@ -584,7 +619,7 @@ postgres: user database host inet The IP address of the client connected to the given - backend. Null if the connection is over a Unix domain + 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 @@ -595,7 +630,7 @@ postgres: user database host integer The IP port number of the client connected to the given - backend. -1 if the connection is over a Unix domain + 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 @@ -614,8 +649,8 @@ postgres: user database host - pg_stat_get_db_blocks_fetched minus - pg_stat_get_db_blocks_hit gives the number of kernel + blocks_fetched minus + blocks_hit gives the number of kernel read() calls issued for the table, index, or database; but the actual number of physical reads is usually lower due to kernel-level buffering. @@ -624,8 +659,8 @@ postgres: user database host The function pg_stat_get_backend_idset provides - a convenient way to generate one row for each active backend process. For - example, to show the PIDs and current queries of all backend processes: + a convenient way to generate one row for each active server process. For + example, to show the PIDs and current queries of all server processes: SELECT pg_stat_get_backend_pid(s.backendid) AS procpid, -- cgit v1.2.3