译者简介

晏杰宏,任职于上海新炬网络信息技术股份有限公司,Oracle DBA。负责数据库、中间件、大数据等基础软件建设、优化和业务保障工作。具有10年以上电信与银行企业一线/二线数据库运维管理经验。目前专注研究云计算、开源软件和国产化数据库等领域技术研究。

校对者简介

朱君鹏,博士研究生。主要研究方向为数据库管理系统,尤其是内存数据库、事务处理系统、软硬件协同设计、日志系统。个人github https://github.com/EthanZhu-DB

Enterprise DB的团队很高兴的宣布了它的Postgres和EDB Postgres高级服务器的新系统统计扩展的发布。

什么是system_stats扩展?

system_stats扩展是一个存储过程库,允许用户访问用于监控Postgres活动的系统级统计信息。这些过程向数据库服务器显示各种系统度量。

通过使用system stats,可以在数据库监控过程中查看有关系统性能的信息,而无需添加单独的第三方应用程序。EDB已将该扩展开源,并根据PostgreSQL许可证发布了该扩展。

为什么要监控PostgreSQL数据库活动?

主动监控数据库活动原因有很多,特别是在资源可用性受限制或无法避免失败风险的情况下。

监控对于优化数据库性能以及保证可用性和安全性至关重要。例如,磁盘使用量的突然增加可能表明日志文件中记录的错误异常增加,或者缓存配置出现问题。类似地,内存使用量的增加可能表示需要调整配置参数,如共享缓冲区或分配可用内存的工作内存,以继续平稳运行。高效的监视允许您在这些问题变得失控或数据库发生故障之前捕捉到这些问题。

Postgres提供了一系列标准的本地监控工具,比如Statistics Collector子系统。

PostgreSQL数据库中的Statistics Collector是什么?

Statistics Collector是一个工具,可提供非常有用的洞察数据库活动的信息,例如跟踪对表的访问,每个表中的行数,执行用户定义函数所花的时间,有关清理和分析操作的信息等。

这些统计数据主要与监控数据的大小和数据的处理有关。system_stats扩展可以解锁有价值的附加系统指标,特别是有关内存、网络、CPU使用率、磁盘空间等的信息。

什么是system_stats函数?

sytem_stats扩展包括许多有用的函数,可以让您查看系统信息和资源的利用情况。每个函数返回参数,详细说明函数监控器的特定组件的各个方面。

下面为每个函数提供的示例中列出了这些参数。

· #1 pg_sys_os_info()

此过程为用户提供关于操作系统的统计信息。

postgres=# SELECT * FROM pg_sys_os_info();
-[ RECORD 1 ]-------+--------------------------------------------------------------------------------------------------
name                | Darwin
version             | Darwin Kernel Version 19.4.0: Wed Mar  4 22:28:40 PST 2020; root:xnu-6153.101.6~15/RELEASE_X86_64
host_name           | hal.local
domain_name         | 
handle_count        | 
process_count       | 531
thread_count        | 
architecture        | x86_64
last_bootup_time    | 
os_up_since_seconds | 281466

#2 pg_sys_cpu_info()

此过程为用户提供关于CPU的信息。

postgres=# SELECT * FROM pg_sys_cpu_info();
-[ RECORD 1 ]------+---------------
vendor             | 
description        | 
model_name         | MacBookPro15,1
processor_type     | 
logical_processor  | 12
physical_processor | 6
no_of_cores        | 12
architecture       | x86_64
clock_speed_hz     | 2900000000
cpu_type           | 7
cpu_family         | 260141638
byte_order         | 1234
l1dcache_size      | 32
l1icache_size      | 32
l2cache_size       | 256
l3cache_size       | 12288

· #3 pg_sys_cpu_usage_info()

此过程为用户提供有关CPU使用情况的信息。给出的值是cpu在所有操作上花费的时间的百分比。

postgres=# SELECT * FROM pg_sys_cpu_usage_info();
-[ RECORD 1 ]-------------------+----------
usermode_normal_process_percent | 1.6806724
usermode_niced_process_percent  | 0
kernelmode_process_percent      | 0
idle_mode_percent               | 98.31933
io_completion_percent           | 
servicing_irq_percent           | 
servicing_softirq_percent       | 
user_time_percent               | 
processor_time_percent          | 
privileged_time_percent         | 
interrupt_time_percent          |

· #4 pg_sys_memory_info()

此过程为用户提供有关内存使用情况的信息。所有的值都以字节为单位。

postgres=# SELECT * FROM pg_sys_memory_info();
-[ RECORD 1 ]----+------------
total_memory     | 34359738368
used_memory      | 31668727808
free_memory      | 2691010560
swap_total       | 3221225472
swap_used        | 2672033792
swap_free        | 549191680
cache_total      | 
kernel_total     | 
kernel_paged     | 
kernel_non_paged | 
total_page_file  | 
avail_page_file  |

· #5 pg_sys_io_analysis_info()

此过程为用户提供块设备的I / O分析。

postgres=# SELECT * FROM pg_sys_io_analysis_info();
-[ RECORD 1 ]-+-------------
device_name   | disk0
total_reads   | 9044867
total_writes  | 6688535
read_bytes    | 127989366784
write_bytes   | 127197491200
read_time_ms  | 3270007
write_time_ms | 3959392
-[ RECORD 2 ]-+-------------
device_name   | disk2
total_reads   | 2222011
total_writes  | 3213728
read_bytes    | 25915008512
write_bytes   | 99796177408
read_time_ms  | 22302918
write_time_ms | 65947889

· #6 pg_sys_disk_info()

此过程为用户提供磁盘信息,例如总量、已使用空间和空闲空间。

postgres=# SELECT * FROM pg_sys_disk_info();
-[ RECORD 1 ]----+---------------------
mount_point      | /
file_system      | apfs
drive_letter     | 
drive_type       | 
file_system_type | /dev/disk1s5
total_space      | 2000796545024
used_space       | 11124047872
free_space       | 1328550260736
total_inodes     | 19539028760
used_inodes      | 487630
free_inodes      | 19538541130
-[ RECORD 2 ]----+---------------------
mount_point      | /System/Volumes/Data
file_system      | apfs
drive_letter     | 
drive_type       | 
file_system_type | /dev/disk1s1
total_space      | 2000796545024
used_space       | 11124047872
free_space       | 1328550260736
total_inodes     | 19539028760
used_inodes      | 487630
free_inodes      | 19538541130
-[ RECORD 3 ]----+---------------------
mount_point      | /private/var/vm
file_system      | apfs
drive_letter     | 
drive_type       | 
file_system_type | /dev/disk1s4
total_space      | 2000796545024
used_space       | 11124047872
free_space       | 1328550260736
total_inodes     | 19539028760
used_inodes      | 487630
free_inodes      | 19538541130
-[ RECORD 4 ]----+---------------------
mount_point      | /Volumes/Backup
file_system      | hfs
drive_letter     | 
drive_type       | 
file_system_type | /dev/disk3
total_space      | 2000796545024
used_space       | 11124047872
free_space       | 1328550260736
total_inodes     | 19539028760
used_inodes      | 487630
free_inodes      | 19538541130

· #7 pg_sys_load_avg_info()

此过程允许用户查看1、5、10和15分钟间隔内的系统平均负载。

postgres=# SELECT * FROM pg_sys_load_avg_info();
-[ RECORD 1 ]------------+----------
load_avg_one_minute      | 1.4116211
load_avg_five_minutes    | 1.5273438
load_avg_ten_minutes     | 
load_avg_fifteen_minutes | 1.5668945

· #8 pg_sys_process_info()

此过程为用户提供有关进程的信息。

postgres=# SELECT * FROM pg_sys_process_info();
-[ RECORD 1 ]------+----
total_processes    | 531
running_processes  | 528
sleeping_processes | 0
stopped_processes  | 0
zombie_processes   | 2

· #9 pg_sys_network_info()

此过程为用户提供了网络接口信息。

postgres=# SELECT * FROM pg_sys_network_info();
-[ RECORD 1 ]---+-------------
interface_name  | lo0
ip_address      | 127.0.0.1
tx_bytes        | 281804800
tx_packets      | 882164
tx_errors       | 0
tx_dropped      | 0
rx_bytes        | 281804800
rx_packets      | 882164
rx_errors       | 0
rx_dropped      | 0
link_speed_mbps | 0
-[ RECORD 2 ]---+-------------
interface_name  | en0
ip_address      | 192.168.0.2
tx_bytes        | 3770546176
tx_packets      | 13311181
tx_errors       | 1164
tx_dropped      | 0
rx_bytes        | 7829563392
rx_packets      | 9070534
rx_errors       | 0
rx_dropped      | 0
link_speed_mbps | 0
-[ RECORD 3 ]---+-------------
interface_name  | utun4
ip_address      | 172.24.64.89
tx_bytes        | 5830656
tx_packets      | 27350
tx_errors       | 0
tx_dropped      | 0
rx_bytes        | 75328512
rx_packets      | 124340
rx_errors       | 0
rx_dropped      | 0
link_speed_mbps | 0

· #10 pg_sys_cpu_memory_by_process()

此接口为用户提供每个进程ID的CPU和内存信息。(注意:macOS不允许其他用户访问进程信息。只获取用户拥有的进程的信息。将包括其他进程,但只显示名称和进程ID。)

postgres=# SELECT * FROM pg_sys_cpu_memory_by_process();
-[ RECORD 1 ]---------+-----------------
pid                   | 62633
name                  | postgres
running_since_seconds | 
cpu_usage             | 4.48
memory_usage          | 0.02
memory_bytes          | 6848512
-[ RECORD 2 ]---------+-----------------
pid                   | 62632
name                  | psql
running_since_seconds | 
cpu_usage             | 0
memory_usage          | 0.01
memory_bytes          | 2453504
-[ RECORD 3 ]---------+-----------------
pid                   | 62594
name                  | Google Chrome He
running_since_seconds | 
cpu_usage             | 0
memory_usage          | 0.09
memory_bytes          | 31694848
...
...

system_stats扩展的安全性

由于信息的潜在敏感性质,这些函数可用,它们的使用仅限于超级用户和monitor_system_stats角色的成员,该角色是在安装扩展时创建的。要允许超级用户以外的用户访问扩展,只需将monitor_system_stats角色授予他们即可。

例如:GRANT monitor_system_stats TO user;

安装system_stats扩展

Linux、macOS和Windows当前支持该扩展。请注意,并非所有的统计数据都在所有平台上可用或相关;如果是这样,您可能会看到返回一些空值。

代码(https://github.com/EnterpriseDB/system_stats/blob/master/README.md)和源代码(https://github.com/EnterpriseDB/system_stats/releases/tag/v1.0)可以在Github上找到;有关更多信息和详细说明,请参阅自述文件。RPM也可在yum.postgresql.org.

如何在Linux和macOS中安装system_stats扩展

该模块可以使用PGXS框架构建,即PostgreSQL的扩展构建基础设施:

· 在合适的目录中下载并解压文件归档文件。

· 请确保PATH环境变量包含要根据其生成的PostgreSQL安装的pg_config二进制文件的目录。

· 编译并安装代码。

例如:

tar -zxvf system_stats-1.0.tar.gz
cd system_stats-1.0
PATH="/usr/local/pgsql/bin:$PATH" make USE_PGXS=1
sudo PATH="/usr/local/pgsql/bin:$PATH" make install USE_PGXS=1

如何在Windows中安装system_stats扩展

可以使用Visual Studio项目文件来构建该模块:将扩展文件解压缩到$ PGSRC / contrib / system_stats中。

· 设置PG_INCLUDE_DIR和PG_LIB_DIR环境变量,以确保可以找到PostgreSQL include和lib目录进行编译。例如:

PG_INCLUDE_DIR=C:\Program Files\PostgreSQL\12\include
PG_LIB_DIR=C:\Program Files\PostgreSQL\12\lib

· 打开Visual Studio项目文件“ system_stats.vcxproj”并生成项目。

一旦构建并安装代码之后,只需运行SQL命令:

CREATE EXTENSION system_stats;

现在,该扩展应该已安装在您的数据库中。

原文链接:https://www.enterprisedb.com/blog/monitoring-postgresql-database-system-activities-performance-system-stats-extension

CENTER_PostgreSQL_Community

请在登录后发表评论,否则无法保存。
1楼 xcvxcvsdf
2025-01-01 23:10:12+08

https://youhaonongchang.tiancebbs.cn/ http://taiying.njtcbmw.cn/danzhou/ http://huilong.sctcbmw.cn/shan-xi/ http://gx.lztcxxw.cn/xiamen/ http://nalei.zjtcbmw.cn/jzjz/ http://xinguang.sctcbmw.cn/bazhong/ http://yz.cqtcxxw.cn/xjhm/ https://tianma.tiancebbs.cn/ http://tuiguang.hntcxxw.cn/hezhou/ http://wutai.cqtcxxw.cn/xicang/ http://taiying.njtcbmw.cn/sbwx/ http://wogao.ahtcbmw.cn/xinyang/ http://shengshun.njtcbmw.cn/zhabeish/ https://jixilinchang.tiancebbs.cn/ http://gx.lztcxxw.cn/fwyqz/ http://shenghuo.china-bbs.com/sxyl/ http://shimai.zjtcbmw.cn/aboutus/

2楼 xcvxcvsdf
2024-10-13 14:39:54+08

https://sddy.tiancebbs.cn/qths/462971.html https://www.tiancebbs.cn/ershoufang/469331.html https://taicang.tiancebbs.cn/hjzl/465193.html https://aihuishou.tiancebbs.cn/sh/2016.html https://www.tiancebbs.cn/ershoufang/470349.html https://lechang.tiancebbs.cn/qths/466005.html https://zulin.tiancebbs.cn/sh/196.html https://www.tiancebbs.cn/ershouwang/468814.html https://aihuishou.tiancebbs.cn/sh/2266.html https://taicang.tiancebbs.cn/hjzl/456822.html https://aihuishou.tiancebbs.cn/sh/2584.html https://aihuishou.tiancebbs.cn/sh/3644.html https://aihuishou.tiancebbs.cn/sh/2526.html https://www.tiancebbs.cn/ershoufang/472724.html https://zulin.tiancebbs.cn/sh/4261.html https://aihuishou.tiancebbs.cn/sh/4388.html https://aihuishou.tiancebbs.cn/sh/3866.html

3楼 xiaowu
2024-04-24 10:50:29+08

信息技术工作总结:https://www.nanss.com/gongzuo/20543.html c位是什么意思:https://www.nanss.com/wenti/19775.html 期末评语:https://www.nanss.com/xuexi/20367.html 年级组工作总结:https://www.nanss.com/gongzuo/18638.html 四年级上册语文第八单元作文:https://www.nanss.com/xuexi/20501.html 小学三年级语文总结:https://www.nanss.com/gongzuo/18748.html 黑巧克力的作用和功效:https://www.nanss.com/shenghuo/19720.html 毛豆的营养价值:https://www.nanss.com/yinshi/19515.html 招商引资调研报告:https://www.nanss.com/gongzuo/20047.html 适合穷人翻身的10个行业:https://www.nanss.com/shenghuo/20704.html 电是谁发明的:https://www.nanss.com/shenghuo/20210.html 蚯蚓的日记:https://www.nanss.com/xuexi/xiezuo/20732.html 窗外作文800字初二:https://www.nanss.com/gongzuo/zhuanti/20755.html 小买卖创业项目推荐:https://www.nanss.com/shenghuo/20699.html 父母催婚:https://www.nanss.com/shenghuo/20407.html 卯时是几点到几点:https://www.nanss.com/jiaju/20561.html 学术研讨会方案:https://www.nanss.com/gongzuo/20523.html 加纳是哪个国家:https://www.nanss.com/shenghuo/18511.html 一度等于多少分:https://www.nanss.com/xuexi/18962.html 20尺集装箱内尺寸:https://www.nanss.com/shenghuo/20393.html 股东协议:https://www.nanss.com/gongzuo/20516.html 教研室主任述职报告:https://www.nanss.com/gongzuo/20549.html 学哲学用哲学:https://www.nanss.com/xuexi/19632.html 什么叫绿色食品:https://www.nanss.com/shenghuo/18468.html 关于亲情的作文600字:https://www.nanss.com/xuexi/20650.html 一千零一夜读后感:https://www.nanss.com/xuexi/19687.html tomato的复数:https://www.nanss.com/xuexi/20150.html 晚自习申请书:https://www.nanss.com/xuexi/18760.html 工作能力自我评价:https://www.nanss.com/gongzuo/19226.html 梦见假花:https://www.nanss.com/xingzuo/19763.html

© 2010 PostgreSQL中文社区