os: centos 7.9.2009
db: postgresql 14.7
监控脚本
su - pgsql
touch tmp_pg_top_status.sh
chmod 777 tmp_pg_top_status.sh
tmp_pg_top_status.sh 内容如下
#!/bin/sh
while true ;
do/data/pgsql/14/bin/pg_top -p 5432 -U dba -d rdsdb -b -R -Xsleep 2s;done
临时 service
sudo systemd-run --unit pgtop-192-168-56-28.service --slice pgtop --uid pgsql --gid pgsql /home/pgsql/tmp_pg_top_status.shsudo journalctl -u pgtop-192-168-56-28.service --vacuum-time=3dayssudo systemctl daemon-reloadsudo systemctl status pgtop-192-168-56-28.servicesudo systemctl restart pgtop-192-168-56-28.servicesudo systemctl status pgtop-192-168-56-28.service
出错时处理
sudo systemctl stop pgtop-192-168-56-28.service
sudo systemctl --failed
sudo systemctl reset-failed pgtop-192-168-56-28.service
导出临时service 日志
sudo journalctl -u pgtop-192-168-56-28.service > /tmp/pgtop-192-168-56-28.log