数据仓库服务 GAUSSDB(DWS)-安全函数:create_audit_csv_foregion_table()

时间:2024-09-24 15:54:38

create_audit_csv_foregion_table()

描述:创建读审计日志的分区外表。用户调用该函数生成审计日志外表pgxc_audit_logs,通过读取pgxc_audit_logs可以读取放在obs上的审计日志信息。该函数仅8.2.1.300及以上集群支持。

入参:

  • obs_server:text类型,obs server名称
  • file_path:text类型,obs文件路径

返回值类型:record

示例:

--创建obs server
CREATE SERVER obs_server FOREIGN DATA WRAPPER DFS_FDW OPTIONS (
   address 'obs.example.xxx:xxx',
   encrypt 'true',
   access_key 'xxxxxxxxx',
   secret_access_key 'xxxxxxxxxxxxxx',
   type 'obs' );
--调用该函数生成审计日志外表
SELECT * FROM pg_catalog.create_audit_csv_foregion_table('obs_server','/obs-audit/test/');
 create_audit_csv_foregion_table
---------------------------------
 t
(1 row)
--读取放在obs上的审计日志信息
SELECT * FROM pgxc_audit_logs where year=2023 and month=7 and date=24;
 year | month | date |         begintime          |          endtime           | operation_type |    audit_type     | result | username | database | client_conninfo |          object_name           | object_details |command_text| detail_info | transaction_xid |      query_id      | node_name |             session_id             | local_port | remote_port | result_rows | error_code
------+-------+------+----------------------------+----------------------------+----------------+-------------------+--------+----------+----------+-----------------+--------------------------------+----------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-------------+-----------------+--------------------+-----------+------------------------------------+------------+-------------+-------------+------------
 2023 | 7     | 24   | 2023-07-24 09:56:40.727+08 | 2023-07-24 09:56:42.215+08 | dml            | dml_action_select | ok     | dbadmin  | gaussdb  | gsql@[local]    | public.pgxc_audit_logs         |                | select * f
rom pgxc_audit_logs where year=2023 and date=24 and month=7;
support.huaweicloud.com/sqlreference-910-dws/dws_06_0048.html