pg_activity —— PostgreSQL 服务器活动监控
pg_activity 是一个用于 PostgreSQL 服务器活动监视的命令行工具。 使用 pg_activity可以在本地或远程工作。在本地工作的情况下,为了获得足够的权限来显示系统信息,运行 pg_activity 的系统用户必须是运行 postgresql 服务器的同一用户(默认是 postgres),或者拥有更多权限的用户,比如root。否则,pg_activity 就会回退到退化模式而不显示系统信息。同样的,用来连接数据库的 PostgreSQL 用户必须是超级用户。 sudo -u postgres pg_activity -U postgres 注意事项 pg_activity 报告的 SQL 查询文本的长度依赖于 PostgreSQL 参数 track_activity_query_size,默认值是 1024 (以字节表示)。如果你的 SQL 查询文本看起来很短,你应该增加 track_activity_query_size。 选项 pg_activity [options] Options: --version Show program's version number and exit -U USERNAME, --username=USERNAME Database user name (default: "postgres"). -p PORT, --port=PORT Database server port (default: "5432"). -h HOSTNAME, --host=HOSTNAME Database server host or socket directory (default: "localhost"). -d DBNAME, --dbname=DBNAME Database name to connect to (default: "postgres"). --blocksize=BLOCKSIZE Filesystem blocksize (default: 4096). --rds Enable support for AWS RDS. --output=FILEPATH Store running queries as CSV. --help Show this help message and exit. --no-db-size Skip total size of DB. --min-duration Don't display queries with smaller than specified duration (in seconds). --verbose-mode=VERBOSE_MODE Queries display mode. Values: 1-TRUNCATED, 2-FULL(default), 3-INDENTED --duration-mode=DURATION_MODE Duration mode. Values: 1-QUERY(default), 2-TRANSACTION, 3-BACKEND Display options, you can exclude some columns by using them : --no-database Disable DATABASE. --no-user Disable USER. --no-client Disable CLIENT. --no-cpu Disable CPU%. --no-mem Disable MEM%. --no-read Disable READ/s. --no-write Disable WRITE/s. --no-time Disable TIME+. --no-wait Disable W. --no-app-name Disable App.