psql -h 10.6.8.3 -p 5432 -U user001 -d db001
安装
可以下载后编译安装,也可以直接yum 安装
yum install -y pgaudit15_13.x86_64
修改配置文件
vim /var/lib/pgsql/13/data/postgresql.conf
shared_preload_libraries = ‘pgaudit’;
shared_preload_libraries参数修改一定要重启服务,热加载是不可以的
select * from pg_available_extensions;
create extension pgaudit;
select name,setting from pg_settings where name like '%audit%';
设置会话级别的
set pgaudit.log = 'all';
set pgaudit.log_relation = on;
set pgaudit.log_client=on;
select name,setting,source from pg_settings where name like 'pgaudit%';
测试效果
2022-08-02 07:02:41.386 UTC [109722] LOG: database system is ready to accept connections
2022-08-02 07:05:51.266 UTC [109884] LOG: AUDIT: SESSION,1,1,MISC,SET,,,set pgaudit.log = 'all';,<not logged>
2022-08-02 07:05:54.301 UTC [109884] LOG: AUDIT: SESSION,2,1,READ,SELECT,,,"select name,setting,source from pg_settings where name like 'pgaudit%';",<not logged>
2022-08-02 07:08:46.470 UTC [109884] ERROR: syntax error at or near "select" at character 52
2022-08-02 07:08:46.470 UTC [109884] STATEMENT: select * from information_schema.role_table_grants
select * from information_schema.role_table_grants;