PostgreSQL 10.0 preview 功能增强 - 新增数十个IO等待事件监控
背景
PostgreSQL 10.0新增了数十个IO等待事件,描述系统调用的等待。
Hi All,
Attached is the patch, which extend the existing wait event infrastructure
to
implement the wait events for the disk I/O. Basically pg_stat_activity's
wait
event information to show data about disk I/O as well as IPC primitives.
Implementation details:
- Added PG_WAIT_IO to pgstat.h and a new enum WaitEventIO
- Added a wait_event_info argument to FileRead, FileWrite, FilePrefetch,
FileWriteback, FileSync, and FileTruncate. Set this wait event just before
performing the file system operation and clear it just after.
- Pass down an appropriate wait event from caller of any of those
functions.
- Also set and clear a wait event around standalone calls to read(),
write(), fsync() in other parts of the system.
- Added documentation for all newly added wait event.
Open issue:
- Might missed few standalone calls to read(), write(), etc which need
to pass the wait_event_info.
Thanks to my colleague Robert Haas for his help in design.
Please let me know your thought, and thanks for reading.
Thanks,
Rushabh Lathia
www.EnterpriseDB.com
IO等待事件如下
/* ----------
+ * Wait Events - IO
+ *
+ * Use this category when a process is waiting for a IO.
+ * ----------
+ */
+typedef enum
+{
+ WAIT_EVENT_READ_DATA_BLOCK,
+ WAIT_EVENT_WRITE_DATA_BLOCK,
+ WAIT_EVENT_SYNC_DATA_BLOCK,
+ WAIT_EVENT_EXTEND_DATA_BLOCK,
+ WAIT_EVENT_FLUSH_DATA_BLOCK,
+ WAIT_EVENT_PREFETCH_DATA_BLOCK,
+ WAIT_EVENT_WRITE_REWRITE_DATA_BLOCK,
+ WAIT_EVENT_SYNC_REWRITE_DATA_BLOCK,
+ WAIT_EVENT_TRUNCATE_RELATION_DATA_BLOCKS,
+ WAIT_EVENT_SYNC_RELATION,
+ WAIT_EVENT_SYNC_IMMED_RELATION,
+ WAIT_EVENT_READ_BUFFILE,
+ WAIT_EVENT_WRITE_BUFFILE,
+ /* Wait event for XLOG */
+ WAIT_EVENT_READ_XLOG,
+ WAIT_EVENT_READ_COPY_XLOG,
+ WAIT_EVENT_WRITE_XLOG,
+ WAIT_EVENT_WRITE_INIT_XLOG_FILE,
+ WAIT_EVENT_WRITE_COPY_XLOG_FILE,
+ WAIT_EVENT_WRITE_BOOTSTRAP_XLOG,
+ WAIT_EVENT_SYNC_INIT_XLOG_FILE,
+ WAIT_EVENT_SYNC_COPY_XLOG_FILE,
+ WAIT_EVENT_SYNC_BOOTSTRAP_XLOG,
+ WAIT_EVENT_SYNC_ASSIGN_XLOG_SYNC_METHOD,
+ /* Wait event for CONTROL_FILE */
+ WAIT_EVENT_WRITE_CONTROL_FILE,
+ WAIT_EVENT_WRITE_UPDATE_CONTROL_FILE,
+ WAIT_EVENT_SYNC_WRITE_CONTROL_FILE,
+ WAIT_EVENT_SYNC_UPDATE_CONTROL_FILE,
+ WAIT_EVENT_READ_CONTROL_FILE,
+ /* Wait event for REORDER BUFFER */
+ WAIT_EVENT_READ_REORDER_BUFFER,
+ WAIT_EVENT_WRITE_REORDER_BUFFER,
+ /* Wait event for LOGICAL MAPPING */
+ WAIT_EVENT_READ_APPLY_LOGICAL_MAPPING,
+ WAIT_EVENT_WRITE_LOGICAL_MAPPING_REWRITE,
+ WAIT_EVENT_SYNC_LOGICAL_MAPPING_REWRITE,
+ WAIT_EVENT_SYNC_LOGICAL_MAPPING_REWRITE_HEAP,
+ WAIT_EVENT_TRUNCATE_LOGICAL_MAPPING_REWRITE,
+ /* Wait event for SNAPBUILD */
+ WAIT_EVENT_WRITE_SNAPBUILD_SERIALIZE,
+ WAIT_EVENT_READ_SNAPBUILD_RESTORE,
+ WAIT_EVENT_SYNC_SNAPBUILD_SERIALIZE,
+ /* Wait event for SNRU */
+ WAIT_EVENT_READ_SLRU_PAGE,
+ WAIT_EVENT_WRITE_SLRU_PAGE,
+ WAIT_EVENT_SYNC_SLRU_FLUSH,
+ WAIT_EVENT_SYNC_SLRU_WRITE_PAGE,
+ /* Wait event for TIMELINE HISTORY */
+ WAIT_EVENT_READ_TIMELINE_HISTORY_WALSENDER,
+ WAIT_EVENT_READ_TIMELINE_HISTORY_WRITE,
+ WAIT_EVENT_WRITE_TIMELINE_HISTORY,
+ WAIT_EVENT_WRITE_TIMELINE_HISTORY_FILE,
+ WAIT_EVENT_SYNC_TIMELINE_HISTORY_WRITE,
+ WAIT_EVENT_SYNC_TIMELINE_HISTORY_FILE,
+ /* Wait event for TWOPHASE FILE */
+ WAIT_EVENT_READ_TWOPHASE_FILE,
+ WAIT_EVENT_WRITE_RECREATE_TWOPHASE_FILE,
+ WAIT_EVENT_SYNC_RECREATE_TWOPHASE_FILE,
+ /* Wait event for SYSLOGGER */
+ WAIT_EVENT_READ_SYSLOGGER_FILE,
+ WAIT_EVENT_WRITE_SYSLOGGER_FILE,
+ /* Wait event for REPLSLOT */
+ WAIT_EVENT_READ_RESTORE_REPLSLOT,
+ WAIT_EVENT_WRITE_REPLSLOT,
+ WAIT_EVENT_SYNC_RESTORE_REPLSLOT,
+ WAIT_EVENT_SYNC_SAVE_REPLSLOT,
+ /* Wait event for copydir */
+ WAIT_EVENT_READ_COPY_FILE,
+ WAIT_EVENT_WRITE_COPY_FILE,
+ /* Wait event RELMAP FILE */
+ WAIT_EVENT_READ_LOAD_RELMAP_FILE,
+ WAIT_EVENT_WRITE_RELMAP_FILE,
+ WAIT_EVENT_SYNC_WRITE_RELMAP_FILE,
+ /* Wait event for LOCK FILE */
+ WAIT_EVENT_READ_CREATE_LOCK_FILE,
+ WAIT_EVENT_READ_ADDTODATEDIR_LOCK_FILE,
+ WAIT_EVENT_READ_RECHECKDATADIR_LOCK_FILE,
+ WAIT_EVENT_WRITE_CREATE_LOCK_FILE,
+ WAIT_EVENT_WRITE_ADDTODATEDIR_LOCK_FILE,
+ WAIT_EVENT_SYNC_ADDTODATEDIR_LOCK_FILE,
+ WAIT_EVENT_SYNC_CREATE_LOCK_FILE
+} WaitEventIO;
对于判断系统瓶颈,又多了一个有力信息。
这个patch的讨论,详见邮件组,本文末尾URL。
PostgreSQL社区的作风非常严谨,一个patch可能在邮件组中讨论几个月甚至几年,根据大家的意见反复的修正,patch合并到master已经非常成熟,所以PostgreSQL的稳定性也是远近闻名的。
参考
https://commitfest.postgresql.org/13/975/
https://www.postgresql.org/message-id/flat/CAGPqQf0LsYHXREPAZqYGVkDqHSyjf=KsD=k0GTVPAuzyThh-VQ@mail.gmail.com#CAGPqQf0LsYHXREPAZqYGVkDqHSyjf=KsD=k0GTVPAuzyThh-VQ@mail.gmail.com