云数据库 GAUSSDB-查看审计结果:操作步骤

时间:2024-01-23 20:09:27

操作步骤

  1. 连接数据库。
  2. 查询审计记录。

    1
    postgres=# SELECT * FROM pg_query_audit('2021-03-03 21:30:00', '2021-03-03 22:00:00') where type = 'login_success' and username = 'user1';
    
    查询结果如下:
              time          |     type      | result | userid | username | database | client_conninfo | object_name |                     detail_info                      | node_name |
              thread_id            | local_port | remote_port
    ------------------------+---------------+--------+--------+----------+----------+-----------------+-------------+------------------------------------------------------+-----------+--
    -------------------------------+------------+-------------
     2021-03-03 21:30:31+08 | login_success | ok     | 16398  | user1    | postgres | gsql@[local]    | postgres    | login db(postgres) success,the current user is:user1 | cn_5001   | 1
    39634608699136@668093431256149 | 18000      | null
    (1 row)

    该条记录表明,用户user1在2021-03-03 21:30:31+08登录数据库postgres。其中client_conninfo字段在log_hostname启动且IP连接时,字符@后显示反向DNS查找得到的主机名。

  3. 查询所有CN节点审计记录。

    1
    postgres=# SELECT * FROM pgxc_query_audit('2021-03-03 21:30:00', '2021-03-03 22:00:00') where type = 'login_success' and username = 'user1';
    

    查询结果如下:

              time          |     type      | result | userid | username | database | client_conninfo | object_name |                     detail_info                      | node_name |
              thread_id            | local_port | remote_port
    ------------------------+---------------+--------+--------+----------+----------+-----------------+-------------+------------------------------------------------------+-----------+--
    -------------------------------+------------+-------------
     2021-03-03 21:30:31+08 | login_success | ok     | 16398  | user1    | postgres | gsql@[local]    | postgres    | login db(postgres) success,the current user is:user1 | cn_5001   | 1
    39634608699136@668093431256149 | 18000      | null
     2021-03-03 21:36:09+08 | login_success | ok     | 16398  | user1    | postgres | gsql@[local]    | postgres    | login db(postgres) success,the current user is:user1 | cn_5003   | 1
    39779716937472@668093769836394 | 18000      | null
    (2 rows)

    查询结果显示,用户user1在cn_5001和cn_5003的成功登录记录。

support.huaweicloud.com/devg-v1-gaussdb/gaussdb_devg_0178.html