[英]Postgres Audit - How to get information on who is performing the DDL operation?
我正在嘗試在 Azure Postgres 單服務器中啟用pgaudit
。 我遵循了 Microsoft 提供的說明以及 Postgres 的文檔。
這些是我的設置(下圖中選擇的2個是DDL和ROLE)
日志參數
然后我使用存儲帳戶為文件配置了一個目的地。 到目前為止,一切都很好。 我運行了這個測試用例
postgres=> create table test_audit ( c1 integer ) ;
CREATE TABLE
postgres=> \dt test_audit
List of relations
Schema | Name | Type | Owner
--------+------------+-------+------------
public | test_audit | table | posadmn001
(1 row)
postgres=> insert into test_audit values ( 1 ) ;
INSERT 0 1
postgres=> insert into test_audit values ( 2 ) ;
INSERT 0 1
postgres=> alter table test_audit add c2 integer ;
ALTER TABLE
postgres=> drop table test_audit ;
DROP TABLE
所以我應該只期望 DDL 操作的條目,而不是 DML 的條目,並且工作正常。
創建表
"message": "*AUDIT: SESSION,1,1,DDL,CREATE TABLE,TABLE,public.test_audit,create table test_audit ( c1 integer ) ;,<none>","detail": "","errorLevel": "LOG","domain": "postgres-11","schemaName": "","tableName": "","columnName": "","datatypeName"
改變表
"message": "AUDIT: SESSION,2,1,DDL,ALTER TABLE,TABLE,public.test_audit,alter table test_audit add c2 integer ;,<none>","detail": "","errorLevel": "LOG","domain": "postgres-11","schemaName": "","tableName": "","columnName": "","datatypeName"
刪除表
"message": "AUDIT: SESSION,1,1,DDL,DROP TABLE,TABLE,public.test_audit,drop table test_audit ;,<none>","detail": "","errorLevel": "LOG","domain": "postgres-11","schemaName": "","tableName": "","columnName": "","datatypeName"
但是,審計跟蹤不會顯示誰執行了此類操作。 我的意思是,如果我逐行查看日志,顯然管理員用戶有一個連接本身的條目,但與 AUDIT 本身無關。 有什么方法可以將審計線索中的用戶與DDL
操作一起收集起來嗎? 這樣當我查找帶有單詞AUDIT
的消息時,我可以獲得命令和執行該命令的用戶。
謝謝您的幫助
您可以通過將%u
添加到log_line_prefix
來獲取日志行前綴中的用戶名。 一個有用的設置可能是
log_line_prefix = '%m [%p] %q%u@%d (%h) '
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.