PostgreSQL一站式插件推荐 -- pg_enterprise_views

打印 上一主题 下一主题

主题 851|帖子 851|积分 2553

    近日发现PG官方插件列表中新收录了一款插件 pg_enterprise_views,因为官方已经数年未添新的插件了很是新奇,找了台设备测试过后果断上了生产,得空分享给大家。
    该插件提供了数十张系统表及一个GUI工具,用以监控从操作系统到数据库方方面面的性能情况,并支持对任意时段历史数据的回溯,基本等同于以往所有监控类插件整合后的超集。
1. 系统表

本质上而言,官方有意提供GUI工具意在降低学习成本,一般运维人员无需关注系统表内容,了解GUI工具的使用即可,在此仅作简要说明。
    完成安装后,所有相关结构会被安放在 postgres 库下,这正是其优秀之处,PG的数据库之间是相对独立的,并不提供跨库的数据访问,因此大部分的插件作用域仅为单库,而 PEV(即 pg_enterprise_views,后文简称 PEV)从单库即可完成对整个数据库簇的实例级监控。先来看看提供了哪些表与视图,由名称可见其内容应包含负载指标、活跃会话、等待事件、超时锁、长事务、SQL及执行计划、SQL统计信息、数据库、表、索引、序列、函数、后台写进程及归档进程,可以说是相当全面的。
  1. postgres=# \dt pev.*
  2.                  List of relations
  3. Schema |          Name          | Type  |  Owner   
  4. --------+------------------------+-------+----------
  5. pev    | pev_active_session_his | table | postgres
  6. pev    | pev_archiver_his       | table | postgres
  7. pev    | pev_bgwriter_his       | table | postgres
  8. pev    | pev_database_his       | table | postgres
  9. pev    | pev_functions_his      | table | postgres
  10. pev    | pev_indexes_his        | table | postgres
  11. pev    | pev_long_locks_his     | table | postgres
  12. pev    | pev_long_trxs_his      | table | postgres
  13. pev    | pev_metrics_his        | table | postgres
  14. pev    | pev_sequences_his      | table | postgres
  15. pev    | pev_setting            | table | postgres
  16. pev    | pev_sql                | table | postgres
  17. pev    | pev_sql_plan           | table | postgres
  18. pev    | pev_sql_stats_his      | table | postgres
  19. pev    | pev_tables_his         | table | postgres
  20. pev    | pev_wait_events_his    | table | postgres
  21. ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  22. postgres=# \dv pev.*
  23.                List of relations
  24. Schema |        Name        | Type |  Owner   
  25. --------+--------------------+------+----------
  26. pev    | pev_active_session | view | postgres
  27. pev    | pev_long_locks     | view | postgres
  28. pev    | pev_long_trxs      | view | postgres
  29. pev    | pev_metrics        | view | postgres
  30. pev    | pev_sql_stats      | view | postgres
  31. pev    | pev_wait_events    | view | postgres
复制代码
1.1. pev_metrics && pev_metrics_his

  视图 pev_metrics 提供数十项从操作系统到数据库的实时负载指标,表 pev_metrics_his 周期性拍摄指标快照并计算增量。
  这极大的弥补了 PG 在这方面的缺陷,如 Oracle、SQL Server 等商业数据库甚至是 MySQL 这种同样的开源产品都内置有丰富的性能视图,而 PG 迭代的侧重点可能更多的聚焦于功能层面。
  1. postgres=# \d pev.pev_metrics
  2.               View "pev.pev_metrics"
  3.     Column    |          Type          | Modifiers
  4. --------------+------------------------+-----------
  5. metric_group | text                   |
  6. metric_id    | text                   |
  7. metric_name  | text                   |
  8. value        | character varying(200) |
  9. units        | text                   |
  10. desp         | text                   |
  11. ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  12. postgres=# \d pev.pev_metrics_his
  13.               Table "pev.pev_metrics_his"
  14.     Column    |            Type             | Modifiers
  15. --------------+-----------------------------+-----------
  16. snap_id      | bigint                      |
  17. sample_time  | timestamp without time zone |
  18. metric_group | character varying(2000)     |
  19. metric_id    | integer                     |
  20. metric_name  | character varying(2000)     |
  21. value        | character varying(2000)     |
  22. value_ps     | double precision            |
  23. units        | character varying(2000)     |
  24. desp         | character varying(2000)     |
  25. ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  26. postgres=# select * from pev.pev_metrics;
  27. metric_group | metric_id |     metric_name      |                   value                   | units  |                                                     desp                                                     
  28. --------------+-----------+----------------------+-------------------------------------------+--------+--------------------------------------------------------------------------------------------------------------
  29. OS(CPU)      | 1001      | CPU_USER_NORMAL_PCT  | 0                                         | %      | Percentage of CPU time spent processing user-mode processes
  30. OS(CPU)      | 1002      | CPU_USER_NICED_PCT   | 0                                         | %      | Percentage of time spent by CPU processing the priority of user-mode scheduling process
  31. OS(CPU)      | 1003      | CPU_KERNEL_PCT       | 0                                         | %      | Percentage of CPU time spent processing kernel processes
  32. OS(CPU)      | 1004      | CPU_IDLE_PCT         | 100                                       | %      | Percentage of CPU idle time
  33. OS(CPU)      | 1005      | CPU_IO_PCT           | 0                                         | %      | Percentage of time spent by CPU processing I/O
  34. OS(CPU)      | 1006      | CPU_MODEL            | Intel(R) Xeon(R) CPU E5-2640 v4 @ 2.40GHz | -      | CPU model name
  35. OS(CPU)      | 1007      | CPU_PRO_LOGICAL_CNT  | 0                                         | number | Number of CPU logical processors
  36. OS(CPU)      | 1008      | CPU_PRO_PHYSICAL_CNT | 8                                         | number | Number of CPU physical processors
  37. OS(CPU)      | 1009      | CPU_CORE_CNT         | 1                                         | number | Number of CPU cores
  38. OS(CPU)      | 1010      | CPU_ARCH             | x86_64                                    | -      | CPU architecture
  39. OS(CPU)      | 1011      | CPU_L1D_CACHE_SIZE   | 32                                        | KB     | CPU L1 data cache size
  40. OS(CPU)      | 1012      | CPU_L1I_CACHE_SIZE   | 32                                        | KB     | CPU L1 instruction cache size
  41. OS(CPU)      | 1013      | CPU_L2_CACHE_SIZE    | 256                                       | KB     | CPU L2 cache size
  42. OS(CPU)      | 1014      | CPU_L3_CACHE_SIZE    | 25600                                     | KB     | CPU L3 cache size
  43. OS(MEMORY)   | 1015      | MEM_TOTAL_MB         | 15773.6                                   | MB     | Total memory capacity size
  44. OS(MEMORY)   | 1016      | MEM_USED_MB          | 798.37                                    | MB     | Current memory capacity usage
  45. OS(MEMORY)   | 1017      | MEM_FREE_MB          | 14975.2                                   | MB     | Current memory capacity free size
  46. OS(MEMORY)   | 1018      | MEM_SWAP_TOTAL_MB    | 32768                                     | MB     | Swap partition size
  47. OS(MEMORY)   | 1019      | MEM_SWAP_USED_MB     | 0                                         | MB     | Used size of swap partition
  48. OS(MEMORY)   | 1020      | MEM_SWAP_FREE_MB     | 32768                                     | MB     | Free size of swap partition
  49. OS(DISK)     | 1021      | DISK_TOTAL_MB        | 205714                                    | MB     | Total disk capacity
  50. OS(DISK)     | 1022      | DISK_USED_MB         | 17995.5                                   | MB     | Disk used size
  51. OS(DISK)     | 1023      | DISK_FREE_MB         | 187719                                    | MB     | Disk free size
  52. OS(DISK)     | 1024      | DISK_RD_CNT          | 90                                        | number | Number of disk reads, ps means per seconed of delta
  53. OS(DISK)     | 1025      | DISK_WT_CNT          | 0                                         | number | Number of disk writes, ps means per seconed of delta
  54. OS(DISK)     | 1026      | DISK_RD_KB           | 544249                                    | KB     | Disk read data size, ps means per seconed of delta
  55. OS(DISK)     | 1027      | DISK_WT_KB           | 55032636                                  | KB     | Disk write data size, ps means per seconed of delta
  56. OS(PROCESS)  | 1028      | PRO_TOTAL_CNT        | 230                                       | number | Total number of current processes
  57. OS(PROCESS)  | 1029      | PRO_ACTIVE_CNT       | 1                                         | number | Total number of current active processes
  58. OS(PROCESS)  | 1030      | PRO_SLEEP_CNT        | 115                                       | number | Total number of current sleep processes
  59. OS(PROCESS)  | 1031      | PRO_STOPPED_CNT      | 0                                         | number | Total number of current stopped processes
  60. OS(PROCESS)  | 1032      | PRO_ZOMBIE_CNT       | 0                                         | number | Total number of current zombiz processes
  61. OS(NETWORK)  | 1033      | NET_DATA_SEND_KB     | 0                                         | KB     | Network data transmission size, ps means per seconed of delta
  62. OS(NETWORK)  | 1034      | NET_PACKAGES_SEND    | 0                                         | number | Number of network packets sent, ps means per seconed of delta
  63. OS(NETWORK)  | 1035      | NET_ERR_SEND         | 0                                         | number | Number of network data transmission errors, ps means per seconed of delta
  64. OS(NETWORK)  | 1036      | NET_PACKAGES_SDROP   | 0                                         | number | Number of packets lost in network data transmission, ps means per seconed of delta
  65. OS(NETWORK)  | 1037      | NET_DATA_RECEIVE_KB  | 0                                         | KB     | Network data receive size, ps means per seconed of delta
  66. OS(NETWORK)  | 1038      | NET_PACKAGES_RECEIVE | 0                                         | number | Number of network packets receive, ps means per seconed of delta
  67. OS(NETWORK)  | 1039      | NET_ERR_RECEIVE      | 0                                         | number | Number of network data receive errors, ps means per seconed of delta
  68. OS(NETWORK)  | 1040      | NET_PACKAGES_RDROP   | 0                                         | number | Number of packets lost in network data receive, ps means per seconed of delta
  69. DB           | 2001      | CONN_TOTAL           | 4                                         | number | Total current connections
  70. DB           | 2002      | CONN_ACTIVE          | 1                                         | number | Current active connections
  71. DB           | 2003      | SESS_BG_TOTAL        | 3                                         | number | Number of current background sessions
  72. DB           | 2004      | SESS_BG_ACTIVE       | 1                                         | number | Number of current background active sessions
  73. DB           | 2005      | TX_CNT               | 2581359                                   | number | Total number of transactions since the server was started, ps means per seconed of delta
  74. DB           | 2006      | TX_COMMIT_CNT        | 2581321                                   | number | Total number of transactions submitted since the server was started, ps means per seconed of delta
  75. DB           | 2007      | TX_ROLLBACK_CNT      | 38                                        | number | Total number of transactions rollbacked since the server was started, ps means per seconed of delta
  76. DB           | 2008      | TEMP_KB              | 0.00                                      | KB     | Total size of temporary space occupation size since the server was started
  77. DB           | 2009      | FETCHED_CNT          | 16423761                                  | number | Total number of rows scanned since the server was started, ps means per seconed of delta
  78. DB           | 2010      | INSERT_CNT           | 3081659                                   | number | Total number of rows inserted since the server was started, ps means per seconed of delta
  79. DB           | 2011      | UPDATE_CNT           | 411174                                    | number | Total number of rows updated since the server was started, ps means per seconed of delta
  80. DB           | 2012      | DELETE_CNT           | 3092713                                   | number | Total number of rows deleted since the server was started, ps means per seconed of delta
  81. DB           | 2013      | WAL_KB               | 81920.00                                  | KB     | The size of the WAL generated since the server was started, ps means per seconed of delta
  82. DB           | 2014      | LOGICAL_RD_CNT       | 66268944                                  | number | Number of logical reads since server startup, ps means per seconed of delta
  83. DB           | 2015      | PHYSICAL_RD_CNT      | 14919                                     | number | Number of physical reads since server startup, ps means per seconed of delta
  84. DB           | 2016      | DBSIZE_MB            | 144.70                                    | MB     | Total size of the current databases
  85. DB           | 2017      | CONFLICTS_CNT        | 0                                         | number | The number of queries cancelled in this database due to conflicts with recovery since the server was started
  86. DB           | 2018      | DEADLOCKS_CNT        | 0                                         | number | Number of deadlocks since the server was started
复制代码
 1.2. pev_active_session && pev_active_session_his

  视图 pev_active_session 提供实时的会话信息,表 pev_active_session_his 周期性拍摄会话快照。
  其结构大致等同与内置视图 pg_stat_activity 但附加了 queryid、planid 及 ssl 信息,这也就意味着对于系统内的任意会话都可实时获取其 SQL 及执行计划文本,并支持在对任意时段进行故障溯源时定位到具体的 SQL、执行计划、客户端等。
  1. postgres=# \d pev.pev_active_session
  2.               View "pev.pev_active_session"
  3.       Column      |           Type           | Modifiers
  4. ------------------+--------------------------+-----------
  5. datid            | oid                      |
  6. datname          | name                     |
  7. pid              | integer                  |
  8. usesysid         | oid                      |
  9. application_name | text                     |
  10. backend_type     | text                     |
  11. backend_start    | timestamp with time zone |
  12. state            | text                     |
  13. state_change     | timestamp with time zone |
  14. backend_xid      | xid                      |
  15. backend_xmin     | xid                      |
  16. queryid          | bigint                   |
  17. planid           | bigint                   |
  18. query            | text                     |
  19. query_start      | timestamp with time zone |
  20. xact_start       | timestamp with time zone |
  21. wait_event_type  | text                     |
  22. wait_event       | text                     |
  23. client_addr      | inet                     |
  24. client_port      | bigint                   |
  25. client_hostname  | text                     |
  26. ssl              | boolean                  |
  27. sslcompression   | boolean                  |
  28. sslversion       | text                     |
  29. sslcipher        | text                     |
  30. sslbits          | bigint                   |
  31. sslclientdn      | text                     |
  32. ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  33. postgres=# \d pev.pev_active_session_his
  34.              Table "pev.pev_active_session_his"
  35.       Column      |            Type             | Modifiers
  36. ------------------+-----------------------------+-----------
  37. snap_id          | bigint                      |
  38. sample_time      | timestamp without time zone |
  39. datid            | oid                         |
  40. datname          | character varying(2000)     |
  41. pid              | integer                     |
  42. usesysid         | oid                         |
  43. application_name | character varying(2000)     |
  44. client_addr      | character varying(2000)     |
  45. client_hostname  | character varying(2000)     |
  46. client_port      | integer                     |
  47. backend_type     | character varying(2000)     |
  48. backend_start    | timestamp with time zone    |
  49. backend_xid      | xid                         |
  50. backend_xmin     | xid                         |
  51. xact_start       | timestamp with time zone    |
  52. query_start      | timestamp with time zone    |
  53. queryid          | bigint                      |
  54. planid           | bigint                      |
  55. state            | character varying(2000)     |
  56. state_change     | timestamp with time zone    |
  57. wait_event_type  | character varying(2000)     |
  58. wait_event       | character varying(2000)     |
  59. ssl              | boolean                     |
  60. sslcompression   | boolean                     |
  61. sslversion       | text                        |
  62. sslcipher        | text                        |
  63. sslbits          | bigint                      |
  64. sslclientdn      | text                        |
复制代码
1.3. pev_wait_events && pev_wait_events_his 

  视图 pev_wait_events 提供实时的等待事件汇总信息,表 pev_wait_events_his 周期性拍摄等待事件快照。
  使运维人员或DBA能清晰的观测到数据库实时及历史的时间分配情况。
  1. postgres=# \d pev.pev_wait_events
  2.       View "pev.pev_wait_events"
  3.      Column      |  Type   | Modifiers
  4. -----------------+---------+-----------
  5. wait_event_type | text    |
  6. wait_event      | text    |
  7. wait_count      | bigint  |
  8. dura_ms         | numeric |
  9. ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  10. postgres=# \d pev.pev_wait_events_his
  11.               Table "pev.pev_wait_events_his"
  12.      Column      |            Type             | Modifiers
  13. -----------------+-----------------------------+-----------
  14. snap_id         | bigint                      |
  15. sample_time     | timestamp without time zone |
  16. wait_event_type | character varying(2000)     |
  17. wait_event      | character varying(2000)     |
  18. wait_count      | integer                     |
  19. dura_ms         | bigint                      |
  20. dura_ms_delta   | bigint                      |
复制代码
1.4. pev_sql_stats && pev_sql_stats_his

  视图 pev_sql_stats 提供实时的 SQL 统计信息,表 pev_sql_stats_his 周期性拍摄 SQL 统计信息快照。
  能够清晰的洞察任意 SQL 于指定时段内的统计信息变化趋势,而如原生拓展 pg_stat_statements 仅包含实时信息其实并不直观,也不具备很强的参考价值。
  1. postgres=# \d pev.pev_sql_stats
  2.          View "pev.pev_sql_stats"
  3.        Column        |  Type   | Modifiers
  4. ---------------------+---------+-----------
  5. userid              | oid     |
  6. dbid                | oid     |
  7. queryid             | bigint  |
  8. calls               | bigint  |
  9. total_time_ms       | numeric |
  10. min_time_ms         | numeric |
  11. max_time_ms         | numeric |
  12. mean_time_ms        | numeric |
  13. stddev_time_ms      | numeric |
  14. rows                | bigint  |
  15. shared_blks_hit     | bigint  |
  16. shared_blks_read    | bigint  |
  17. shared_blks_dirtied | bigint  |
  18. shared_blks_written | bigint  |
  19. local_blks_hit      | bigint  |
  20. local_blks_read     | bigint  |
  21. local_blks_dirtied  | bigint  |
  22. local_blks_written  | bigint  |
  23. temp_blks_read      | bigint  |
  24. temp_blks_written   | bigint  |
  25. blk_read_time_ms    | numeric |
  26. blk_write_time_ms   | numeric |
  27. ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  28. postgres=# \d pev.pev_sql_stats_his
  29.                     Table "pev.pev_sql_stats_his"
  30.           Column           |            Type             | Modifiers
  31. ---------------------------+-----------------------------+-----------
  32. snap_id                   | bigint                      |
  33. sample_time               | timestamp without time zone |
  34. userid                    | oid                         |
  35. dbid                      | oid                         |
  36. queryid                   | bigint                      |
  37. calls                     | bigint                      |
  38. total_time_ms             | double precision            |
  39. min_time_ms               | double precision            |
  40. max_time_ms               | double precision            |
  41. mean_time_ms              | double precision            |
  42. stddev_time_ms            | double precision            |
  43. rows                      | bigint                      |
  44. shared_blks_hit           | bigint                      |
  45. shared_blks_read          | bigint                      |
  46. shared_blks_dirtied       | bigint                      |
  47. shared_blks_written       | bigint                      |
  48. local_blks_hit            | bigint                      |
  49. local_blks_read           | bigint                      |
  50. local_blks_dirtied        | bigint                      |
  51. local_blks_written        | bigint                      |
  52. temp_blks_read            | bigint                      |
  53. temp_blks_written         | bigint                      |
  54. blk_read_time_ms          | double precision            |
  55. blk_write_time_ms         | double precision            |
  56. calls_delta               | bigint                      |
  57. total_time_ms_delta       | double precision            |
  58. min_time_ms_delta         | double precision            |
  59. max_time_ms_delta         | double precision            |
  60. mean_time_ms_delta        | double precision            |
  61. stddev_time_ms_delta      | double precision            |
  62. rows_delta                | bigint                      |
  63. shared_blks_hit_delta     | bigint                      |
  64. shared_blks_read_delta    | bigint                      |
  65. shared_blks_dirtied_delta | bigint                      |
  66. shared_blks_written_delta | bigint                      |
  67. local_blks_hit_delta      | bigint                      |
  68. local_blks_read_delta     | bigint                      |
  69. local_blks_dirtied_delta  | bigint                      |
  70. local_blks_written_delta  | bigint                      |
  71. temp_blks_read_delta      | bigint                      |
  72. temp_blks_written_delta   | bigint                      |
  73. blk_read_time_ms_delta    | double precision            |
  74. blk_write_time_ms_delta   | double precision            |
复制代码
1.5. pev_long_locks & pev_long_locks_his

  视图 pev_long_locks 提供实时的超20秒的锁等待信息,表 pev_long_locks_his 周期性拍摄超时锁快照。
  PG原生的锁信息相关系统表非常晦涩,不具备易用性,而通过 PEV 的锁等待视图可以轻松查看到阻塞者以及被阻塞者的进程、客户端、SQL、执行计划、被锁定的目标结构等等,更加贴合实际的运维需求。
  1. postgres=# \d pev.pev_long_locks
  2.         View "pev.pev_long_locks"
  3.       Column      |   Type   | Modifiers
  4. ------------------+----------+-----------
  5. blocker_pid      | integer  |
  6. blocker_user     | name     |
  7. blocker_client   | text     |
  8. blocker_queryid  | bigint   |
  9. blocker_planid   | bigint   |
  10. blocker_state    | text     |
  11. blocked_pid      | integer  |
  12. blocked_user     | name     |
  13. blocked_client   | text     |
  14. blocked_queryid  | bigint   |
  15. blocked_planid   | bigint   |
  16. blocked_state    | text     |
  17. blocked_dura_sec | bigint   |
  18. lock_type        | text     |
  19. lock_db          | name     |
  20. lock_table       | regclass |
  21. lock_row_num     | smallint |
  22. ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  23. postgres=# \d pev.pev_long_locks_his
  24.                Table "pev.pev_long_locks_his"
  25.       Column      |            Type             | Modifiers
  26. ------------------+-----------------------------+-----------
  27. snap_id          | bigint                      |
  28. sample_time      | timestamp without time zone |
  29. blocker_pid      | integer                     |
  30. blocker_user     | character varying(2000)     |
  31. blocker_client   | character varying(2000)     |
  32. blocker_queryid  | bigint                      |
  33. blocker_planid   | bigint                      |
  34. blocked_pid      | integer                     |
  35. blocked_user     | character varying(2000)     |
  36. blocked_client   | character varying(2000)     |
  37. blocked_queryid  | bigint                      |
  38. blocked_planid   | bigint                      |
  39. blocked_dura_sec | bigint                      |
  40. lock_type        | character varying(2000)     |
  41. lock_db          | character varying(2000)     |
  42. lock_table       | character varying(2000)     |
  43. lock_row_num     | bigint                      |
复制代码
1.6. pev_long_trxs && pev_long_trxs_his

  视图 pev_long_trxs 提供实时的超20秒的长事务信息,表pev_long_trxs_his 周期性拍摄长事务快照。
  事务往往没有锁更加引人重视,因为所等待将直接导致业务阻塞,而事务则不会。其实不然,当事务长时间不释放时将影响到 auto vacuum 进程回收元组,对系统的性能影响是潜移默化的,运维人员有必要实时关注超长事务并进行必要的处理。
  1. postgres=# \d pev.pev_long_trxs
  2.                   View "pev.pev_long_trxs"
  3.       Column      |            Type             | Modifiers
  4. ------------------+-----------------------------+-----------
  5. datname          | name                        |
  6. pid              | integer                     |
  7. usesysid         | oid                         |
  8. application_name | text                        |
  9. client_addr      | inet                        |
  10. client_port      | bigint                      |
  11. backend_start    | timestamp without time zone |
  12. state            | text                        |
  13. xact_start       | timestamp without time zone |
  14. query_start      | timestamp without time zone |
  15. state_dura_ms    | bigint                      |
  16. trx_dura_ms      | bigint                      |
  17. query_dura_ms    | bigint                      |
  18. wait_event_type  | text                        |
  19. wait_event       | text                        |
  20. queryid          | bigint                      |
  21. planid           | bigint                      |
  22. ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  23. postgres=# \d pev.pev_long_trxs_his
  24.                Table "pev.pev_long_trxs_his"
  25.       Column      |            Type             | Modifiers
  26. ------------------+-----------------------------+-----------
  27. snap_id          | bigint                      |
  28. sample_time      | timestamp without time zone |
  29. datname          | character varying(2000)     |
  30. pid              | integer                     |
  31. usesysid         | oid                         |
  32. application_name | character varying(2000)     |
  33. client_addr      | character varying(2000)     |
  34. client_port      | integer                     |
  35. backend_start    | timestamp without time zone |
  36. state            | character varying(2000)     |
  37. xact_start       | timestamp without time zone |
  38. query_start      | timestamp without time zone |
  39. state_dura_ms    | bigint                      |
  40. trx_dura_ms      | bigint                      |
  41. query_dura_ms    | bigint                      |
  42. wait_event_type  | character varying(2000)     |
  43. wait_event       | character varying(2000)     |
  44. queryid          | bigint                      |
  45. planid           | bigint                      |
复制代码
1.7. pev_database_his

  表 pev_database_his 周期性拍摄全数据库簇的数据库统计信息快照并进行增量计算。
  1. postgres=# \d pev.pev_database_his
  2.                    Table "pev.pev_database_his"
  3.          Column          |            Type             | Modifiers
  4. -------------------------+-----------------------------+-----------
  5. snap_id                 | bigint                      |
  6. sample_time             | timestamp without time zone |
  7. database_oid            | oid                         |
  8. database_name           | character varying(2000)     |
  9. current_backends        | bigint                      |
  10. xact_commit             | bigint                      |
  11. xact_rollback           | bigint                      |
  12. blks_read               | bigint                      |
  13. blks_hit                | bigint                      |
  14. tup_returned            | bigint                      |
  15. tup_fetched             | bigint                      |
  16. tup_inserted            | bigint                      |
  17. tup_updated             | bigint                      |
  18. tup_deleted             | bigint                      |
  19. conflicts               | bigint                      |
  20. temp_files              | bigint                      |
  21. temp_bytes              | bigint                      |
  22. deadlocks               | bigint                      |
  23. blk_read_time_ms        | bigint                      |
  24. blk_write_time_ms       | bigint                      |
  25. current_backends_delta  | bigint                      |
  26. xact_commit_delta       | bigint                      |
  27. xact_rollback_delta     | bigint                      |
  28. blks_read_delta         | bigint                      |
  29. blks_hit_delta          | bigint                      |
  30. tup_returned_delta      | bigint                      |
  31. tup_fetched_delta       | bigint                      |
  32. tup_inserted_delta      | bigint                      |
  33. tup_updated_delta       | bigint                      |
  34. tup_deleted_delta       | bigint                      |
  35. conflicts_delta         | bigint                      |
  36. temp_files_delta        | bigint                      |
  37. temp_bytes_delta        | bigint                      |
  38. deadlocks_delta         | bigint                      |
  39. blk_read_time_ms_delta  | bigint                      |
  40. blk_write_time_ms_delta | bigint                      |
复制代码
1.8. pev_tables_his

  表 pev_tables_his 周期性拍摄全数据库簇的表统计信息快照并进行增量计算。
  1. postgres=# \d pev.pev_tables_his
  2.                      Table "pev.pev_tables_his"
  3.           Column           |            Type             | Modifiers
  4. ---------------------------+-----------------------------+-----------
  5. snap_id                   | bigint                      |
  6. sample_time               | timestamp without time zone |
  7. dbname                    | character varying(2000)     |
  8. table_oid                 | oid                         |
  9. schema_name               | character varying(2000)     |
  10. table_name                | character varying(2000)     |
  11. seq_scan                  | bigint                      |
  12. seq_tup_read              | bigint                      |
  13. idx_scan                  | bigint                      |
  14. idx_tup_fetch             | bigint                      |
  15. n_tup_ins                 | bigint                      |
  16. n_tup_upd                 | bigint                      |
  17. n_tup_del                 | bigint                      |
  18. n_tup_hot_upd             | bigint                      |
  19. n_live_tup                | bigint                      |
  20. n_dead_tup                | bigint                      |
  21. n_mod_since_analyze       | bigint                      |
  22. heap_blks_read            | bigint                      |
  23. heap_blks_hit             | bigint                      |
  24. idx_blks_read             | bigint                      |
  25. idx_blks_hit              | bigint                      |
  26. toast_blks_read           | bigint                      |
  27. toast_blks_hit            | bigint                      |
  28. tidx_blks_read            | bigint                      |
  29. tidx_blks_hit             | bigint                      |
  30. vacuum_count              | bigint                      |
  31. autovacuum_count          | bigint                      |
  32. analyze_count             | bigint                      |
  33. autoanalyze_count         | bigint                      |
  34. last_vacuum               | timestamp without time zone |
  35. last_autovacuum           | timestamp without time zone |
  36. last_analyze              | timestamp without time zone |
  37. last_autoanalyze          | timestamp without time zone |
  38. seq_scan_delta            | bigint                      |
  39. seq_tup_read_delta        | bigint                      |
  40. idx_scan_delta            | bigint                      |
  41. idx_tup_fetch_delta       | bigint                      |
  42. n_tup_ins_delta           | bigint                      |
  43. n_tup_upd_delta           | bigint                      |
  44. n_tup_del_delta           | bigint                      |
  45. n_tup_hot_upd_delta       | bigint                      |
  46. n_live_tup_delta          | bigint                      |
  47. n_dead_tup_delta          | bigint                      |
  48. n_mod_since_analyze_delta | bigint                      |
  49. heap_blks_read_delta      | bigint                      |
  50. heap_blks_hit_delta       | bigint                      |
  51. idx_blks_read_delta       | bigint                      |
  52. idx_blks_hit_delta        | bigint                      |
  53. toast_blks_read_delta     | bigint                      |
  54. toast_blks_hit_delta      | bigint                      |
  55. tidx_blks_read_delta      | bigint                      |
  56. tidx_blks_hit_delta       | bigint                      |
  57. vacuum_count_delta        | bigint                      |
  58. autovacuum_count_delta    | bigint                      |
  59. analyze_count_delta       | bigint                      |
  60. autoanalyze_count_delta   | bigint                      |
复制代码
1.9. pev_indexes_his

  表 pev_indexes_his 周期性拍摄全数据库簇的索引统计信息快照并进行增量计算。
  1. postgres=# \d pev.pev_indexes_his
  2.                   Table "pev.pev_indexes_his"
  3.        Column        |            Type             | Modifiers
  4. ---------------------+-----------------------------+-----------
  5. snap_id             | bigint                      |
  6. sample_time         | timestamp without time zone |
  7. table_oid           | oid                         |
  8. index_oid           | oid                         |
  9. schema_name         | character varying(2000)     |
  10. table_name          | character varying(2000)     |
  11. index_name          | character varying(2000)     |
  12. idx_scan            | bigint                      |
  13. idx_tup_read        | bigint                      |
  14. idx_tup_fetch       | bigint                      |
  15. idx_blks_read       | bigint                      |
  16. idx_blks_hit        | bigint                      |
  17. idx_scan_delta      | bigint                      |
  18. idx_tup_read_delta  | bigint                      |
  19. idx_tup_fetch_delta | bigint                      |
  20. idx_blks_read_delta | bigint                      |
  21. idx_blks_hit_delta  | bigint                      |
复制代码
1.10. pev_sequences_his

  表 pev_sequences_his 周期性拍摄全数据库簇的序列统计信息快照并进行增量计算。
  1. postgres=# \d pev.pev_sequences_his
  2.                Table "pev.pev_sequences_his"
  3.      Column      |            Type             | Modifiers
  4. -----------------+-----------------------------+-----------
  5. snap_id         | bigint                      |
  6. sample_time     | timestamp without time zone |
  7. sequence_oid    | oid                         |
  8. schema_name     | character varying(2000)     |
  9. sequence_name   | character varying(2000)     |
  10. blks_read       | bigint                      |
  11. blks_hit        | bigint                      |
  12. blks_read_delta | bigint                      |
  13. blks_hit_delta  | bigint                      |
复制代码
1.11. pev_functions_his

  表 pev_functions_his 周期性拍摄全数据库簇的函数统计信息快照并进行增量计算。
  1. postgres=# \d pev.pev_functions_his
  2.                  Table "pev.pev_functions_his"
  3.        Column        |            Type             | Modifiers
  4. ---------------------+-----------------------------+-----------
  5. snap_id             | bigint                      |
  6. sample_time         | timestamp without time zone |
  7. function_oid        | oid                         |
  8. schema_name         | character varying(2000)     |
  9. function_name       | character varying(2000)     |
  10. calls               | bigint                      |
  11. total_time_ms       | bigint                      |
  12. self_time_ms        | bigint                      |
  13. calls_delta         | bigint                      |
  14. total_time_ms_delta | bigint                      |
  15. self_time_ms_delta  | bigint                      |
复制代码
1.12. pev_bgwriter_his

  表 pev_bgwriter_his 周期性拍摄后台写进程统计信息快照并进行增量计算。
  1. postgres=# \d pev.pev_bgwriter_his
  2.                        Table "pev.pev_bgwriter_his"
  3.              Column             |            Type             | Modifiers
  4. --------------------------------+-----------------------------+-----------
  5. snap_id                        | bigint                      |
  6. sample_time                    | timestamp without time zone |
  7. checkpoints_timed              | bigint                      |
  8. checkpoints_req                | bigint                      |
  9. checkpoint_write_time_ms       | bigint                      |
  10. checkpoint_sync_time_ms        | bigint                      |
  11. buffers_checkpoint             | bigint                      |
  12. buffers_clean                  | bigint                      |
  13. maxwritten_clean               | bigint                      |
  14. buffers_backend                | bigint                      |
  15. buffers_backend_fsync          | bigint                      |
  16. buffers_alloc                  | bigint                      |
  17. checkpoints_timed_delta        | bigint                      |
  18. checkpoints_req_delta          | bigint                      |
  19. checkpoint_write_time_ms_delta | bigint                      |
  20. checkpoint_sync_time_ms_delta  | bigint                      |
  21. buffers_checkpoint_delta       | bigint                      |
  22. buffers_clean_delta            | bigint                      |
  23. maxwritten_clean_delta         | bigint                      |
  24. buffers_backend_delta          | bigint                      |
  25. buffers_backend_fsync_delta    | bigint                      |
  26. buffers_alloc_delta            | bigint                      |
复制代码
1.13. pev_archiver_his

  表 pev_archiver_his 周期性拍摄归档进程统计信息快照并进行增量计算。
  1. postgres=# \d pev.pev_archiver_his
  2.                   Table "pev.pev_archiver_his"
  3.         Column        |            Type             | Modifiers
  4. ----------------------+-----------------------------+-----------
  5. snap_id              | bigint                      |
  6. sample_time          | timestamp without time zone |
  7. archived_count       | bigint                      |
  8. last_archived_wal    | character varying(2000)     |
  9. last_archived_time   | timestamp without time zone |
  10. failed_count         | bigint                      |
  11. last_failed_wal      | character varying(2000)     |
  12. last_failed_time     | timestamp without time zone |
  13. archived_count_delta | bigint                      |
  14. failed_count_delta   | bigint                      |
复制代码
1.14. pev_sql && pev_sql_plan

  表 pev_sql 及 pev_sql_plan 记录了所有执行过的 SQL 及其执行计划信息,用于关联使用。
  1. postgres=# \d pev.pev_sql
  2.       Table "pev.pev_sql"
  3. Column  |  Type   | Modifiers
  4. ---------+---------+-----------
  5. queryid | bigint  |
  6. dbid    | integer |
  7. query   | text    |
  8. iftemp  | boolean |
  9. ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  10. postgres=# \d pev.pev_sql_plan
  11.    Table "pev.pev_sql_plan"
  12. Column  |  Type  | Modifiers
  13. ---------+--------+-----------
  14. queryid | bigint |
  15. planid  | bigint |
  16. plan    | text   |
复制代码
1.15. pev_setting

  表 pev_setting 用于进行整个模块的参数配置,修改后10秒内自动生效。
  1. postgres=# select * from pev.pev_setting;
  2.            name            | value |  unit   |                                                                     desp                                                                     
  3. ---------------------------+-------+---------+-----------------------------------------------------------------------------------------------------------------------------------------------
  4. PEV_MAX_SQL               | 10000 | NUMBER  | Max sql stats info to hold, the value should not be less than 1000
  5. PEV_MAX_SIZE              |  5120 | MB      | Maximum data size held by pev module, automatic cleaning when exceeding, the value should not be less than 1024
  6. PEV_TRACK_UTILITY_SQL     |     0 | -       | Whether the PEV module tracks utility SQL, Non-0 means yes
  7. PEV_SQL_TRACK_LEVEL       |     1 | -       | PEV module track level of SQL statements, 0: no tracking, 1: track top level SQL, 2 track all SQL, including inner nested statements
  8. PEV_ASH_FREQUENCY         |    30 | SECONED | PEV_ACTIVE_SESSION_HIS gather interval, normal value should not be less than 10 when opening, -1 for close
  9. PEV_METRICS_FREQUENCY     |    60 | SECONED | PEV_METRICS_HIS gather interval, normal value should not be less than 10 when opening, -1 for close
  10. PEV_WAIT_EVENTS_FREQUENCY |    60 | SECONED | PEV_WAIT_EVENTS_HIS gather interval, normal value should not be less than 10 when opening, -1 for close
  11. PEV_LONG_TRXS_FREQUENCY   |    60 | SECONED | PEV_LONG_TRXS_HIS gather interval, normal value should not be less than 10 when opening, -1 for close
  12. PEV_LONG_LOCKS_FREQUENCY  |    60 | SECONED | PEV_LONG_LOCKS_HIS gather interval, normal value should not be less than 10 when opening, -1 for close
  13. PEV_DATABASE_FREQUENCY    |   600 | SECONED | PEV_DATABASE_HIS gather interval, normal value should not be less than 60 when opening, -1 for close
  14. PEV_TABLES_FREQUENCY      |   600 | SECONED | PEV_TABLES_HIS gather interval, normal value should not be less than 60 when opening, -1 for close
  15. PEV_INDEXES_FREQUENCY     |   600 | SECONED | PEV_INDEXES_HIS gather interval, normal value should not be less than 60 when opening, -1 for close
  16. PEV_SEQUENCES_FREQUENCY   |   600 | SECONED | PEV_SEQUENCES_HIS gather interval, normal value should not be less than 60 when opening, -1 for close
  17. PEV_FUNCTIONS_FREQUENCY   |   600 | SECONED | PEV_FUNCTIONS_HIS gather interval, normal value should not be less than 60 when opening, -1 for close
  18. PEV_BGWRITER_FREQUENCY    |   600 | SECONED | PEV_BGWRITER_HIS gather interval, normal value should not be less than 60 when opening, -1 for close
  19. PEV_ARCHIVER_FREQUENCY    |   600 | SECONED | PEV_ARCHIVER_HIS gather interval, normal value should not be less than 60 when opening, -1 for close
  20. PEV_SQL_STATS_FREQUENCY   |   600 | SECONED | PEV_SQL_STATS_HIS gather interval, normal value should not be less than 60 when opening, -1 for close
  21. PEV_MIN_TIME              |     1 | DAY     | Minimum data dwell time held by the PEV module, priority is higher than PEV_MAX_SIZE in garbage cleaning, the value should not be less than 1
复制代码
2. GUI工具

  官方提供了名为 pev.exe 的客户端 GUI 工具,对上述系统表的使用方法进行了封装,这也是最方便快捷的使用方式。在一台可连接到数据库的 windows 设备上可直接运行使用。
  可见其涵盖了所有需要关注的重点信息,从上至下分别是:负载指标、历史等待事件、实时等待事件、活跃进程信息(可切换超时锁、长事务、TOP SQL、TOP 客户端、历史超时锁、历史长事务、TOP 数据库、TOP 表、TOP 索引、写进程状态、归档进程状态等)以及曲线图。

  • 双击 QUERYID 或 PLANID 进入 SQL 详情页,可查看其于指定时段所使用的执行计划、等待事件、客户端信息。
  • 双击 PID 进入进程详情页,可查看其当前的具体动作及状态,并可一键 KILL 该进程。
  • 双击任意蓝色项可在底部曲线图处显示其在指定时间段内的变化曲线




3. 安装方式

下载链接:
    官方通道:pev@catinfo.com.cn
    PG官网通道:https://www.postgresql.org/download/products/6-postgresql-extensions/
安装步骤:
    1. 下载对应自身PG版本的压缩包并解压(如 pg_enterprise_views_pg10.x_v20230423_linux_x64(64-bit).zip)
    2. 将 pg_enterprise_views.so 文件放入PG安装目录的 lib 目录下(一般为:/usr/local/pgsql/lib/)
    3. 将 pg_enterprise_views--1.0.sql 及 pg_enterprise_views.control 文件放置于PG安装目录的 extension 目录下(一般为:/usr/local/pgsql/share/extension)
    4. 修改配置文件 postgresql.conf:shared_preload_libraries = 'pg_enterprise_views'
    5. 重启 PG 数据库
    6. psql 执行命令(必须是 postgres 库):create extension pg_enterprise_views;
免费许可:
    免费许可至2024年5月1日(支持24小时历史数据回溯)。
    查看许可信息:select pev.pev_register_info();
    企业版激活(需激活码):select pev.pev_register('Activation Code');

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

冬雨财经

金牌会员
这个人很懒什么都没写!
快速回复 返回顶部 返回列表