checkpoint_write_time, checkpoint_sync_time will added in pg_stat_bgwriter

来源:互联网 发布:linux crontab java 编辑:程序博客网 时间:2024/06/13 09:25
PostgreSQL的统计信息视图pg_stat_bgwriter中包含如下列的信息 :

pg_stat_bgwriter view

ColumnTypeDescriptioncheckpoints_timedbigintNumber of scheduled checkpoints. This value can also be returned by directly calling thepg_stat_get_bgwriter_timed_checkpoints function.checkpoints_requestedbigintNumber of requested checkpoints. This value can also be returned by directly calling thepg_stat_get_bgwriter_requested_checkpoints function.checkpoint_write_timebigintTotal amount of time that has been spent in the portion of checkpoint processing where files are written to disk, in milliseconds. This value can also be returned by directly calling thepg_stat_get_checkpoint_write_time function.checkpoint_sync_timebigintTotal amount of time that has been spent in the portion of checkpoint processing where files are synchronized to disk, in milliseconds. This value can also be returned by directly calling thepg_stat_get_checkpoint_sync_time function.buffers_checkpointbigintNumber of buffers written during checkpoints. This value can also be returned by directly calling thepg_stat_get_bgwriter_buf_written_checkpointsfunction.buffers_cleanbigintNumber of buffers written by the background writer. This value can also be returned by directly calling thepg_stat_get_bgwriter_buf_written_clean function.maxwritten_cleanbigintNumber of times the background writer stopped a cleaning scan because it had written too many buffers. This value can also be returned by directly calling thepg_stat_get_bgwriter_maxwritten_clean function.buffers_backendbigintNumber of buffers written directly by a backend. This value can also be returned by directly calling thepg_stat_get_buf_written_backend function.buffers_backend_fsyncbigintNumber of times a backend had to execute its own fsync call (normally the background writer handles those even when the backend does its own write)buffers_allocbigintNumber of buffers allocated. This value can also be returned by directly calling thepg_stat_get_buf_alloc function.stats_resetbigintThe last time these statistics were reset. This value can also be returned by directly calling thepg_stat_get_bgwriter_stat_reset_time function.
来自SQL

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;


其中
checkpoint_write_time和checkpoint_sync_time是PostgreSQL 9.2新增的, 用来记录累计的checkpoint时写文件到磁盘的时间和 累计的同步时间.
在postgresql.conf中配置log_checkpoints=on的话, 这两项统计会记录到log文件中. 并且log记录的是每次checkpoint后的统计信息, 不是累计的.
log 文件中截取一段如下 :

2012-04-12 10:51:07.635 CST,,,21703,,4f864226.54c7,26,,2012-04-12 10:47:02 CST,,0,LOG,00000,"checkpoint complete: wrote 3466 buffers (84.6%); 0 transaction log file(s) added, 0 removed, 3 recycled; write=102.725 s, sync=0.103 s, total=102.829 s; sync files=1, longest=0.103 s, average=0.103 s",,,,,,,,,""

由于我这里配置的 shared_buffers = 32MB
wrote 3466 buffers (84.6%) 也可以反推出来 shared_buffers =block_size*(3466/84.6%) .
其中write=102.725 s, sync=0.103 s 指的就是checkpoint_write_time, checkpoint_sync_time.
pg_stat_bgwriter中这两项的统计信息与log_checkpoints无关, 例如 :

postgres=# show log_checkpoints;
-[ RECORD 1 ]---+----
log_checkpoints | off
postgres=# select pg_stat_reset_shared('bgwriter');
-[ RECORD 1 ]--------+-
pg_stat_reset_shared |
postgres=# select * from pg_stat_bgwriter;
-[ RECORD 1 ]---------+------------------------------
checkpoints_timed | 0
checkpoints_req | 0
checkpoint_write_time | 0
checkpoint_sync_time | 0
buffers_checkpoint | 0
buffers_clean | 0
maxwritten_clean | 0
buffers_backend | 0
buffers_backend_fsync | 0
buffers_alloc | 1
stats_reset | 2012-04-12 11:06:00.737366+08
postgres=# insert into test select generate_series(1,5000000);
INSERT 0 5000000
postgres=# select * from pg_stat_bgwriter;
-[ RECORD 1 ]---------+------------------------------
checkpoints_timed | 1
checkpoints_req | 6
checkpoint_write_time | 118778
checkpoint_sync_time | 673
buffers_checkpoint | 22262
buffers_clean | 1125
maxwritten_clean | 0
buffers_backend | 22165
buffers_backend_fsync | 0
buffers_alloc | 22130
stats_reset | 2012-04-12 11:06:00.737366+08

最后附一个查询统计信息的函数列表  :

select pg_catalog.obj_description(p.oid, 'pg_proc') as desc,proname,proargnames from pg_proc p where pg_catalog.obj_description(p.oid, 'pg_proc') ~ 'statistics' order by proname;
-[ RECORD 1 ]-----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: current backend PID
proname | pg_backend_pid
proargnames |
-[ RECORD 2 ]-----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: discard current transaction's statistics snapshot
proname | pg_stat_clear_snapshot
proargnames |
-[ RECORD 3 ]-----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: information about currently active backends
proname | pg_stat_get_activity
proargnames | {pid,datid,procpid,usesysid,application_name,current_query,waiting,xact_start,query_start,backend_start,client_addr,cl
ient_hostname,client_port}
-[ RECORD 4 ]-----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: number of manual analyzes for a table
proname | pg_stat_get_analyze_count
proargnames |
-[ RECORD 5 ]-----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: number of auto analyzes for a table
proname | pg_stat_get_autoanalyze_count
proargnames |
-[ RECORD 6 ]-----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: number of auto vacuums for a table
proname | pg_stat_get_autovacuum_count
proargnames |
-[ RECORD 7 ]-----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: current query of backend
proname | pg_stat_get_backend_activity
proargnames |
-[ RECORD 8 ]-----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: start time for current query of backend
proname | pg_stat_get_backend_activity_start
proargnames |
-[ RECORD 9 ]-----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: address of client connected to backend
proname | pg_stat_get_backend_client_addr
proargnames |
-[ RECORD 10 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: port number of client connected to backend
proname | pg_stat_get_backend_client_port
proargnames |
-[ RECORD 11 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: database ID of backend
proname | pg_stat_get_backend_dbid
proargnames |
-[ RECORD 12 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: currently active backend IDs
proname | pg_stat_get_backend_idset
proargnames |
-[ RECORD 13 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: PID of backend
proname | pg_stat_get_backend_pid
proargnames |
-[ RECORD 14 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: start time for current backend session
proname | pg_stat_get_backend_start
proargnames |
-[ RECORD 15 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: user ID of backend
proname | pg_stat_get_backend_userid
proargnames |
-[ RECORD 16 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: is backend currently waiting for a lock
proname | pg_stat_get_backend_waiting
proargnames |
-[ RECORD 17 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: start time for backend's current transaction
proname | pg_stat_get_backend_xact_start
proargnames |
-[ RECORD 18 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: number of buffers written by the bgwriter during checkpoints
proname | pg_stat_get_bgwriter_buf_written_checkpoints
proargnames |
-[ RECORD 19 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: number of buffers written by the bgwriter for cleaning dirty buffers
proname | pg_stat_get_bgwriter_buf_written_clean
proargnames |
-[ RECORD 20 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: number of times the bgwriter stopped processing when it had written too many buffers while cleaning
proname | pg_stat_get_bgwriter_maxwritten_clean
proargnames |
-[ RECORD 21 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: number of backend requested checkpoints started by the bgwriter
proname | pg_stat_get_bgwriter_requested_checkpoints
proargnames |
-[ RECORD 22 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: last reset for the bgwriter
proname | pg_stat_get_bgwriter_stat_reset_time
proargnames |
-[ RECORD 23 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: number of timed checkpoints started by the bgwriter
proname | pg_stat_get_bgwriter_timed_checkpoints
proargnames |
-[ RECORD 24 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: number of blocks fetched
proname | pg_stat_get_blocks_fetched
proargnames |
-[ RECORD 25 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: number of blocks found in cache
proname | pg_stat_get_blocks_hit
proargnames |
-[ RECORD 26 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: number of buffer allocations
proname | pg_stat_get_buf_alloc
proargnames |
-[ RECORD 27 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: number of backend buffer writes that did their own fsync
proname | pg_stat_get_buf_fsync_backend
proargnames |
-[ RECORD 28 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: number of buffers written by backends
proname | pg_stat_get_buf_written_backend
proargnames |
-[ RECORD 29 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: blocks fetched for database
proname | pg_stat_get_db_blocks_fetched
proargnames |
-[ RECORD 30 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: blocks found in cache for database
proname | pg_stat_get_db_blocks_hit
proargnames |
-[ RECORD 31 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: recovery conflicts in database
proname | pg_stat_get_db_conflict_all
proargnames |
-[ RECORD 32 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: recovery conflicts in database caused by shared buffer pin
proname | pg_stat_get_db_conflict_bufferpin
proargnames |
-[ RECORD 33 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: recovery conflicts in database caused by relation lock
proname | pg_stat_get_db_conflict_lock
proargnames |
-[ RECORD 34 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: recovery conflicts in database caused by snapshot expiry
proname | pg_stat_get_db_conflict_snapshot
proargnames |
-[ RECORD 35 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: recovery conflicts in database caused by buffer deadlock
proname | pg_stat_get_db_conflict_startup_deadlock
proargnames |
-[ RECORD 36 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: recovery conflicts in database caused by drop tablespace
proname | pg_stat_get_db_conflict_tablespace
proargnames |
-[ RECORD 37 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: number of backends in database
proname | pg_stat_get_db_numbackends
proargnames |
-[ RECORD 38 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: last reset for a database
proname | pg_stat_get_db_stat_reset_time
proargnames |
-[ RECORD 39 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: tuples deleted in database
proname | pg_stat_get_db_tuples_deleted
proargnames |
-[ RECORD 40 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: tuples fetched for database
proname | pg_stat_get_db_tuples_fetched
proargnames |
-[ RECORD 41 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: tuples inserted in database
proname | pg_stat_get_db_tuples_inserted
proargnames |
-[ RECORD 42 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: tuples returned for database
proname | pg_stat_get_db_tuples_returned
proargnames |
-[ RECORD 43 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: tuples updated in database
proname | pg_stat_get_db_tuples_updated
proargnames |
-[ RECORD 44 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: transactions committed
proname | pg_stat_get_db_xact_commit
proargnames |
-[ RECORD 45 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: transactions rolled back
proname | pg_stat_get_db_xact_rollback
proargnames |
-[ RECORD 46 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: number of dead tuples
proname | pg_stat_get_dead_tuples
proargnames |
-[ RECORD 47 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: number of function calls
proname | pg_stat_get_function_calls
proargnames |
-[ RECORD 48 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: self execution time of function
proname | pg_stat_get_function_self_time
proargnames |
-[ RECORD 49 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: execution time of function
proname | pg_stat_get_function_time
proargnames |
-[ RECORD 50 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: last manual analyze time for a table
proname | pg_stat_get_last_analyze_time
proargnames |
-[ RECORD 51 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: last auto analyze time for a table
proname | pg_stat_get_last_autoanalyze_time
proargnames |
-[ RECORD 52 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: last auto vacuum time for a table
proname | pg_stat_get_last_autovacuum_time
proargnames |
-[ RECORD 53 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: last manual vacuum time for a table
proname | pg_stat_get_last_vacuum_time
proargnames |
-[ RECORD 54 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: number of live tuples
proname | pg_stat_get_live_tuples
proargnames |
-[ RECORD 55 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: number of scans done for table/index
proname | pg_stat_get_numscans
proargnames |
-[ RECORD 56 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: number of tuples deleted
proname | pg_stat_get_tuples_deleted
proargnames |
-[ RECORD 57 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: number of tuples fetched by idxscan
proname | pg_stat_get_tuples_fetched
proargnames |
-[ RECORD 58 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: number of tuples hot updated
proname | pg_stat_get_tuples_hot_updated
proargnames |
-[ RECORD 59 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: number of tuples inserted
proname | pg_stat_get_tuples_inserted
proargnames |
-[ RECORD 60 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: number of tuples read by seqscan
proname | pg_stat_get_tuples_returned
proargnames |
-[ RECORD 61 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: number of tuples updated
proname | pg_stat_get_tuples_updated
proargnames |
-[ RECORD 62 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: number of manual vacuums for a table
proname | pg_stat_get_vacuum_count
proargnames |
-[ RECORD 63 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: information about currently active replication
proname | pg_stat_get_wal_senders
proargnames | {procpid,state,sent_location,write_location,flush_location,replay_location,sync_priority,sync_state}
-[ RECORD 64 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: number of blocks fetched in current transaction
proname | pg_stat_get_xact_blocks_fetched
proargnames |
-[ RECORD 65 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: number of blocks found in cache in current transaction
proname | pg_stat_get_xact_blocks_hit
proargnames |
-[ RECORD 66 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: number of function calls in current transaction
proname | pg_stat_get_xact_function_calls
proargnames |
-[ RECORD 67 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: self execution time of function in current transaction
proname | pg_stat_get_xact_function_self_time
proargnames |
-[ RECORD 68 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: execution time of function in current transaction
proname | pg_stat_get_xact_function_time
proargnames |
-[ RECORD 69 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: number of scans done for table/index in current transaction
proname | pg_stat_get_xact_numscans
proargnames |
-[ RECORD 70 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: number of tuples deleted in current transaction
proname | pg_stat_get_xact_tuples_deleted
proargnames |
-[ RECORD 71 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: number of tuples fetched by idxscan in current transaction
proname | pg_stat_get_xact_tuples_fetched
proargnames |
-[ RECORD 72 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: number of tuples hot updated in current transaction
proname | pg_stat_get_xact_tuples_hot_updated
proargnames |
-[ RECORD 73 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: number of tuples inserted in current transaction
proname | pg_stat_get_xact_tuples_inserted
proargnames |
-[ RECORD 74 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: number of tuples read by seqscan in current transaction
proname | pg_stat_get_xact_tuples_returned
proargnames |
-[ RECORD 75 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: number of tuples updated in current transaction
proname | pg_stat_get_xact_tuples_updated
proargnames |
-[ RECORD 76 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: reset collected statistics for current database
proname | pg_stat_reset
proargnames |
-[ RECORD 77 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: reset collected statistics shared across the cluster
proname | pg_stat_reset_shared
proargnames |
-[ RECORD 78 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: reset collected statistics for a single function in the current database
proname | pg_stat_reset_single_function_counters
proargnames |
-[ RECORD 79 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics: reset collected statistics for a single table or index in the current database
proname | pg_stat_reset_single_table_counters
proargnames |
-[ RECORD 80 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics of tsvector column
proname | ts_stat
proargnames | {query,word,ndoc,nentry}
-[ RECORD 81 ]----------------------------------------------------------------------------------------------------------------------
--------------------------
desc | statistics of tsvector column
proname | ts_stat
proargnames | {query,weights,word,ndoc,nentry}


【参考】
https://commitfest.postgresql.org/action/patch_view?id=794
原创粉丝点击