代码拉取完成,页面将自动刷新
只有拥有AUDITADMIN属性的用户才可以查看审计记录。有关数据库用户及创建用户的办法请参见用户。
审计查询命令是数据库提供的sql函数pg_query_audit,其原型为:
pg_query_audit(timestamptz startime,timestamptz endtime,audit_log)
参数startime和endtime分别表示审计记录的开始时间和结束时间,audit_log表示所查看的审计日志信息所在的物理文件路径,当不指定audit_log时,默认查看连接当前实例的审计日志信息。
说明: startime和endtime的差值代表要查询的时间段,其有效值为从startime日期中的00:00:00开始到endtime日期中的23:59:59之间的任何值。请正确指定这两个参数,否则将查不到需要的审计信息。
以操作系统用户omm登录数据库主节点。
使用如下命令连接数据库。
gsql -d postgres -p 8000
postgres为需要连接的数据库名称,8000为数据库主节点的端口号。
连接成功后,系统显示类似如下信息:
gsql ((openGauss x.x.x build 50dc16a6) compiled at 2020-11-29 05:49:21 commit 1071 last mr 1373)
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.
postgres=#
查询审计记录。
postgres=# select * from pg_query_audit('2021-03-04 08:00:00','2021-03-04 17:00:00');
查询结果如下:
time | type | result | userid | username | database | client_conninfo | object_name | detail_info | node_name | thread_id | local_port | remote_port
------------------------+----------------+--------+--------+-----------+-----------+-------------------------+-------------------+--------------+-------------------+---------------------------------+------------+-------------
2021-03-04 08:00:08+08 | login_success | ok | 10 | omm | postgres | gsql@::1 | postgres | login db(postgres) success,the current user is:omm | dn_6001_6002_6003 | 140477687527168@668131208211425 | 17778 | 46946
该条记录表明,用户omm在time字段标识的时间点登录数据库postgres。其中client_conninfo字段在log_hostname启动且IP连接时,字符@后显示反向DNS查找得到的主机名。
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。