pgauditlogtofile

pgAudit 子扩展,将审计日志写入单独的文件中

概览

扩展包名版本分类许可证语言
pgauditlogtofile1.8.3SECPostgreSQLC
ID扩展名BinLibLoadCreateTrustReloc模式
7120pgauditlogtofile-
相关扩展pgaudit pg_auth_mon logerrors pg_permissions login_hook set_user pg_drop_events table_log

版本

类型仓库版本PG 大版本包名依赖
EXTPGDG1.8.31817161514pgauditlogtofile-
RPMPGDG1.8.31817161514pgauditlogtofile_$v-
DEBPGDG1.8.31817161514postgresql-$v-pgauditlogtofile-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
PGDG 1.8.4
el8.x86_64.pg14 : pgauditlogtofile_14
pgauditlogtofile_14-1.8.4-1PGDG.rhel8.10.x86_64.rpm PGDG · 1.8.4 · 34.0KiB pgauditlogtofile_14-1.8.3-1PGDG.rhel8.10.x86_64.rpm PGDG · 1.8.3 · 33.3KiB pgauditlogtofile_14-1.8.2-1PGDG.rhel8.10.x86_64.rpm PGDG · 1.8.2 · 33.2KiB pgauditlogtofile_14-1.8.1-1PGDG.rhel8.10.x86_64.rpm PGDG · 1.8.1 · 30.7KiB pgauditlogtofile_14-1.8.0-1PGDG.rhel8.10.x86_64.rpm PGDG · 1.8.0 · 30.8KiB pgauditlogtofile_14-1.7.7-2PGDG.rhel8.10.x86_64.rpm PGDG · 1.7.7 · 28.1KiB pgauditlogtofile_14-1.7.6-1PGDG.rhel8.x86_64.rpm PGDG · 1.7.6 · 27.5KiB pgauditlogtofile_14-1.7.5-1PGDG.rhel8.x86_64.rpm PGDG · 1.7.5 · 27.4KiB pgauditlogtofile_14-1.7.4-1PGDG.rhel8.x86_64.rpm PGDG · 1.7.4 · 27.2KiB pgauditlogtofile_14-1.6.4-1PGDG.rhel8.x86_64.rpm PGDG · 1.6.4 · 24.3KiB pgauditlogtofile_14-1.6.3-1PGDG.rhel8.x86_64.rpm PGDG · 1.6.3 · 24.2KiB pgauditlogtofile_14-1.6.2-1PGDG.rhel8.x86_64.rpm PGDG · 1.6.2 · 24.0KiB pgauditlogtofile_14-1.6.0-1PGDG.rhel8.x86_64.rpm PGDG · 1.6.0 · 23.2KiB pgauditlogtofile_14-1.5.12-2PGDG.rhel8.x86_64.rpm PGDG · 1.5.12 · 19.7KiB pgauditlogtofile_14-1.5.12-1PGDG.rhel8.x86_64.rpm PGDG · 1.5.12 · 19.6KiB pgauditlogtofile_14-1.5.10-1.rhel8.x86_64.rpm PGDG · 1.5.10 · 19.2KiB pgauditlogtofile_14-1.5.6-1.rhel8.x86_64.rpm PGDG · 1.5.6 · 17.9KiB pgauditlogtofile_14-1.5.5-1.rhel8.x86_64.rpm PGDG · 1.5.5 · 32.9KiB pgauditlogtofile_14-1.5.1-1.rhel8.x86_64.rpm PGDG · 1.5.1 · 32.3KiB pgauditlogtofile_14-1.4-1.rhel8.x86_64.rpm PGDG · 1.4 · 31.5KiB pgauditlogtofile_14-1.3-1.rhel8.x86_64.rpm PGDG · 1.3 · 32.8KiB
el8.aarch64
el9.x86_64
el9.aarch64
el10.x86_64
el10.aarch64
d12.x86_64
d12.aarch64
d13.x86_64
d13.aarch64
u22.x86_64
u22.aarch64
u24.x86_64
u24.aarch64

安装

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

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

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

pig install pgauditlogtofile;          # 当前活跃 PG 版本安装
pig ext install -y pgauditlogtofile -v 18  # PG 18
pig ext install -y pgauditlogtofile -v 17  # PG 17
pig ext install -y pgauditlogtofile -v 16  # PG 16
pig ext install -y pgauditlogtofile -v 15  # PG 15
pig ext install -y pgauditlogtofile -v 14  # PG 14
dnf install -y pgauditlogtofile_18       # PG 18
dnf install -y pgauditlogtofile_17       # PG 17
dnf install -y pgauditlogtofile_16       # PG 16
dnf install -y pgauditlogtofile_15       # PG 15
dnf install -y pgauditlogtofile_14       # PG 14
apt install -y postgresql-18-pgauditlogtofile   # PG 18
apt install -y postgresql-17-pgauditlogtofile   # PG 17
apt install -y postgresql-16-pgauditlogtofile   # PG 16
apt install -y postgresql-15-pgauditlogtofile   # PG 15
apt install -y postgresql-14-pgauditlogtofile   # PG 14

预加载配置

shared_preload_libraries = 'pgauditlogtofile';

创建扩展

CREATE EXTENSION pgauditlogtofile;

用法

pgauditlogtofile: 将 pgAudit 日志重定向到独立文件

pgauditlogtofile 是 pgAudit 的附加组件,会将审计日志行重定向到独立文件,而不是 PostgreSQL 服务器日志,并支持自动轮转。

CREATE EXTENSION pgauditlogtofile;

配置参数

参数默认值描述
pgaudit.log_formatcsv输出格式:csvjson
pgaudit.log_directorylog审计文件目录,留空则禁用
pgaudit.log_filenameaudit-%Y%m%d_%H%M.log文件名模式,支持时间格式
pgaudit.log_file_mode0600审计日志文件权限
pgaudit.log_rotation_age1440轮转间隔,单位分钟,1 天
pgaudit.log_connectionsoff记录连接事件,需要 log_connections = on
pgaudit.log_disconnectionsoff记录断开事件,需要 log_disconnections = on
pgaudit.log_autoclose_minutes0空闲 N 分钟后自动关闭文件句柄
pgaudit.log_execution_timeoff统计语句执行时间
pgaudit.log_execution_memoryoff统计语句内存占用

设置

添加到 postgresql.conf

shared_preload_libraries = 'pgaudit, pgauditlogtofile'
pgaudit.log_directory = 'log'
pgaudit.log_filename = 'audit-%Y%m%d_%H%M.log'
pgaudit.log_rotation_age = 1440

审计条目会写入独立文件,服务器日志保持整洁。


最后修改 2026-04-14: update extension catalog (fa7cf58)