pg_auth_mon

监控每个用户的连接尝试

概览

扩展包名版本分类许可证语言
pg_auth_mon3.0SECMITC
ID扩展名BinLibLoadCreateTrustReloc模式
7150pg_auth_mon-
相关扩展passwordcheck_cracklib pgaudit pgauditlogtofile login_hook auth_delay credcheck logerrors set_user

版本

类型仓库版本PG 大版本包名依赖
EXTMIXED3.01817161514pg_auth_mon-
RPMPGDG3.01817161514pg_auth_mon_$v-
DEBPIGSTY3.01817161514postgresql-$v-pg-auth-mon-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
PGDG 2.0
el8.aarch64
PGDG 2.0
el9.x86_64
PGDG 2.0
PGDG 2.0
el9.aarch64
PGDG 2.0
el10.x86_64
el10.aarch64
d12.x86_64
PIGSTY 3.0
PIGSTY 3.0
PIGSTY 3.0
PIGSTY 3.0
PIGSTY 3.0
d12.aarch64
PIGSTY 3.0
PIGSTY 3.0
PIGSTY 3.0
PIGSTY 3.0
PIGSTY 3.0
d13.x86_64
PIGSTY 3.0
PIGSTY 3.0
PIGSTY 3.0
PIGSTY 3.0
PIGSTY 3.0
d13.aarch64
PIGSTY 3.0
PIGSTY 3.0
PIGSTY 3.0
PIGSTY 3.0
PIGSTY 3.0
u22.x86_64
PIGSTY 3.0
PIGSTY 3.0
PIGSTY 3.0
PIGSTY 3.0
PIGSTY 3.0
u22.aarch64
PIGSTY 3.0
PIGSTY 3.0
PIGSTY 3.0
PIGSTY 3.0
PIGSTY 3.0
u24.x86_64
PIGSTY 3.0
PIGSTY 3.0
PIGSTY 3.0
PIGSTY 3.0
PIGSTY 3.0
u24.aarch64
PIGSTY 3.0
PIGSTY 3.0
PIGSTY 3.0
PIGSTY 3.0
PIGSTY 3.0

构建

您可以使用 pig build 命令构建 pg_auth_mon 扩展的 DEB 包:

pig build pkg pg_auth_mon         # 构建 DEB 包

安装

您可以直接安装 pg_auth_mon 扩展包的预置二进制包,首先确保 PGDGPIGSTY 仓库已经添加并启用:

pig repo add pgsql -u          # 添加仓库并更新缓存

使用 pig 或者是 apt/yum/dnf 安装扩展:

pig install pg_auth_mon;          # 当前活跃 PG 版本安装
pig ext install -y pg_auth_mon -v 18  # PG 18
pig ext install -y pg_auth_mon -v 17  # PG 17
pig ext install -y pg_auth_mon -v 16  # PG 16
pig ext install -y pg_auth_mon -v 15  # PG 15
pig ext install -y pg_auth_mon -v 14  # PG 14
dnf install -y pg_auth_mon_18       # PG 18
dnf install -y pg_auth_mon_17       # PG 17
dnf install -y pg_auth_mon_16       # PG 16
dnf install -y pg_auth_mon_15       # PG 15
dnf install -y pg_auth_mon_14       # PG 14
apt install -y postgresql-18-pg-auth-mon   # PG 18
apt install -y postgresql-17-pg-auth-mon   # PG 17
apt install -y postgresql-16-pg-auth-mon   # PG 16
apt install -y postgresql-15-pg-auth-mon   # PG 15
apt install -y postgresql-14-pg-auth-mon   # PG 14

预加载配置

shared_preload_libraries = 'pg_auth_mon';

创建扩展

CREATE EXTENSION pg_auth_mon;

用法

pg_auth_mon: 监控认证尝试

pg_auth_mon 按用户存储认证尝试统计信息,跟踪成功和失败的登录及其时间戳。

CREATE EXTENSION pg_auth_mon;

配置

postgresql.conf 中添加:

shared_preload_libraries = 'pg_auth_mon'

可选 GUC 参数:

参数默认值描述
pg_auth_mon.log_period0每 N 分钟将统计信息转储到 Postgres 日志(0=关闭)

查询认证统计

SELECT * FROM pg_auth_mon;

pg_auth_mon 视图提供每用户信息:

描述
uid用户 OID(0 表示无效/不存在的用户名)
successful_auth_count成功登录总次数
last_successful_auth最近一次成功登录的时间戳
failed_auth_count失败认证总次数
last_failed_auth最近一次失败登录的时间戳
hba_conflicts_countHBA 文件冲突次数

所有使用无效用户名的登录尝试被聚合到一个 OID 为 0 的行中。


最后修改 2026-03-14: update extension metadata (953cbd0)