暂无图片
暂无图片
1
暂无图片
暂无图片
暂无图片

PostgreSQL实时监控工具之pgcenter

一、功能概述

PostgreSQL提供了关于其运行时各种活动统计数据,如连接、语句、数据库操作、复制、资源使用等。这些统计数据的通用目的是帮助数据库管理员(DBA)监控和解决PostgreSQL的问题。然而,这些以文本形式从SQL函数和视图中检索的统计数据,PostgreSQL并不提供原生工具来处理统计视图。pgCenter的主要目标是帮助Postgres数据库管理员(DBA)处理统计数据,并提供一种方便的方式来实时观察Postgres的运行情况。

主要特点:

  • 顶部样式的界面,允许您在操作过程中监控统计数据的变化 。
  • 配置管理功能允许查看和编辑当前配置文件,并在需要时重新加载服务。
  • 日志文件功能允许您在不停止统计监控的情况下快速检查Postgres日志。
  • 收集Postgres统计数据到文件中,并在稍后生成报告。
  • 等待事件分析器允许查看查询执行期间发生的等待事件。

二、下载及安装


2.1、官网地址

https://github.com/lesovsky/pgcenter

2.2、下载

[postgres@Node1 install]$ wget https://github.com/lesovsky/pgcenter/releases/download/v0.9.2/pgcenter_0.9.2_linux_amd64.tar.gz
--2024-09-04 20:31:29--  https://github.com/lesovsky/pgcenter/releases/download/v0.9.2/pgcenter_0.9.2_linux_amd64.tar.gz
Resolving github.com (github.com)... 20.205.243.166
Connecting to github.com (github.com)|20.205.243.166|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://objects.githubusercontent.com/github-production-release-asset-2e65be/41038664/b9a8ed8a-7402-43d6-a120-5c5a029f717f?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=releaseassetproduction%2F20240904%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20240904T123128Z&X-Amz-Expires=300&X-Amz-Signature=dc9f5dfcab16a0e5401cc9754cd24fef9d2d622b366f564c54f2b8971116a787&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=41038664&response-content-disposition=attachment%3B%20filename%3Dpgcenter_0.9.2_linux_amd64.tar.gz&response-content-type=application%2Foctet-stream [following]
--2024-09-04 20:31:30--  https://objects.githubusercontent.com/github-production-release-asset-2e65be/41038664/b9a8ed8a-7402-43d6-a120-5c5a029f717f?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=releaseassetproduction%2F20240904%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20240904T123128Z&X-Amz-Expires=300&X-Amz-Signature=dc9f5dfcab16a0e5401cc9754cd24fef9d2d622b366f564c54f2b8971116a787&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=41038664&response-content-disposition=attachment%3B%20filename%3Dpgcenter_0.9.2_linux_amd64.tar.gz&response-content-type=application%2Foctet-stream
Resolving objects.githubusercontent.com (objects.githubusercontent.com)... 185.199.109.133, 185.199.111.133, 185.199.108.133, ...
Connecting to objects.githubusercontent.com (objects.githubusercontent.com)|185.199.109.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 5860166 (5.6M) [application/octet-stream]
Saving to: ‘pgcenter_0.9.2_linux_amd64.tar.gz’

100%[==============================================================================>] 5,860,166   12.4KB/s   in 8m 5s

2024-09-04 20:39:36 (11.8 KB/s) - ‘pgcenter_0.9.2_linux_amd64.tar.gz’ saved [5860166/5860166]

[postgres@Node1 install]$

2.3、创建工具存放目录

sudo mkdir -p /postgres/pgcenter

sudo chmod -R 777 /postgres/pgcenter

sudo chown -R postgres:postgres /postgres/pgcenter

2.4、解压安装包

[postgres@Node1 install]$ tar xzvf pgcenter_0.9.2_linux_amd64.tar.gz  -C /postgres/pgcenter/
README.md
Pgcenter
[postgres@Node1 install]$ 

2.5、检查pgCenter版本

[postgres@Node1 install]$ cd /postgres/pgcenter/
[postgres@Node1 pgcenter]$ ./pgcenter --version
pgcenter v0.9.2 7ebd54847cbbf72a98cbde39e9afc3845cba9839-release
[postgres@Node1 pgcenter]$

三、使用方法

3.1、查看帮助信息

[postgres@Node1 pgcenter]$ ./pgcenter --help
pgCenter is a command line admin tool for PostgreSQL.

Usage:
  pgcenter [flags]
  pgcenter [command] [command-flags] [args]

Available commands:
  config        installs or uninstalls pgcenter stats schema to Postgres
  profile       wait events profiler
  record        record stats to file
  report        make report based on previously saved statistics
  top           top-like stats viewer

Flags:
  -?, --help            show this help and exit
      --version         show version information and exit

Use "pgcenter [command] --help" for more information about a command.

Report bugs to <https://github.com/lesovsky/pgcenter/issues>.
[postgres@Node1 pgcenter]$

3.2、使用方法

语法:

Pgcenter top -h 127.0.0.1 -d database -U user

示例:

[postgres@Node1 pgcenter]$ ./pgcenter top -h 127.0.0.1 -d repmgr -U repmgr

image.png

3.3、功能使用

3.3.1、检查主机磁盘信息

image.png

3.3.2、查看数据库连接信息

4fb1ae56489deafbd02d08e27a9343ef_tRYlkAWWmyIAAAAASUVORK5CYII=.png

3.3.3、查看表统计信息

image.png

四、注意事项

4.1、管理用户

建议在管理数据库的用户的账户下操作,便于维护。

五、使用说明

pgCenter是一个用于观察和排除PostgreSQL故障的命令行管理工具。以下是一些基本的使用方法:

  • 安装pgCenter:您可以通过克隆GitHub上的仓库来获取pgCenter的源代码,并按照提供的安装说明进行编译和安装。或者,您可以下载预编译的二进制文件,并将其放置在系统的可执行文件路径下。
  • 运行pgCenter:使用pgcenter命令启动pgCenter。您可以通过添加不同的参数和子命令来执行不同的操作,例如查看实时统计信息、配置pgCenter与PostgreSQL的交互等。
  • 查看实时统计信息:使用pgcenter top命令可以查看类似于top工具的实时数据库活动视图。您可以通过添加-h(主机名)、-p(端口)、-U(用户名)和-d(数据库名)等参数来指定连接信息。
  • 配置和编辑:您可以使用pgcenter命令的配置管理功能来查看和编辑PostgreSQL的配置文件。
  • 日志浏览:pgCenter提供了查看和浏览PostgreSQL日志文件的功能。数据记录:pgCenter可以记录数据库的统计信息并存档,以便后期分析。
  • 等待事件分析器:工具还包括等待事件分析器,可以帮助诊断查询执行期间发生的等待事件。
  • 退出pgCenter:您可以通过按h或F1键查看帮助信息,或者按q、ESC或Ctrl+Q退出pgCenter。

请参考pgCenter的官方文档或最新的博客文章以获取详细的安装和使用指南,因为工具的功能和接口可能会随着版本的更新而变化。

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

文章被以下合辑收录

评论