微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Postgresql审计:pgaudit安装使用

Postgresql:10
pgaudit:v1.2

文章目录

编译安装

1、clone插件

git clone https://github.com/pgaudit/pgaudit.git

2、Change to pgAudit directory:

cd pgaudit

3、Checkout postgresql 10 branch

git checkout REL_10_STABLE

4、编译安装

make install USE_PGXS=1 PG_CONfig=/usr/lib/postgresql/10/bin/pg_config

备注:PG_CONfig路径

在这里插入图片描述

5、修改postgresql.conf配置

修改添加:shared_preload_libraries = 'pgaudit'

6、重启postgresql

systemctl restart postgresql@10-main.service

7、create extension

postgres=# create extension pgaudit;

参数配置说明

可配置参数

postgres=# select name,setting from pg_settings where name like 'pgaudit%';

在这里插入图片描述

pgaudit.log:

配置审计包括类型

  • READ: SELECT and copY when the source is a relation or a query.
  • WRITE: INSERT, UPDATE, DELETE, TruncATE, and copY when the
    destination is a relation.
  • FUNCTION: Function calls and DO blocks.
  • ROLE: Statements related to roles and privileges: GRANT, REVOKE,
    CREATE/ALTER/DROP ROLE.
  • DDL: All DDL that is not included in the ROLE class.
  • MISC: Miscellaneous commands, e.g. disCARD, FETCH, CHECKPOINT,
    VACUUM, SET.
  • MISC_SET: Miscellaneous SET commands, e.g. SET ROLE.
  • ALL: Include all of the above.
postgres=# set pgaudit.log = READ,DDL;

在这里插入图片描述pgaudit.log显示如下:

在这里插入图片描述

pgaudit.log_client:

客户端打印审计日志,例如psql

在这里插入图片描述

pgaudit.log_level:

日志级别:Postgresql Log Level,与pgaudit.log_client配合使用。

pgaudit.log_parameter:

指定审计日志记录应包括与语句一起传递的参数。当参数存在时,它们将包含在CSV语句文本之后的格式中,认值为off。

pgaudit.role:

配置日志审计主角色,可以通过配置多个角色,分别负责不通对象的审计。

set pgaudit.role = 'postgresq,nexttao';

grant select
   on public.test
   to nexttao;

在这里插入图片描述

参考

https://github.com/pgaudit/pgaudit

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐