2013-04-29 50 views
0

我想知道是否可以在PostgreSQL中僅爲特定表啓用日誌記錄(即使用表級粒度進行日誌記錄)?在PostgreSQL中只爲特定表啓用日誌記錄

當前正在以下列方式打印日誌。如果我們啓用完整的日誌記錄,分配的硬盤空間將在不到30分鐘的時間內完成。

GMT_jbpm_LOG: 00000: duration: 0.104 ms bind <unnamed>: select instances0_.PROCESSINSTANCE_ as PROCESSI4_1_, instances0_.ID_ as ID1_1_, instances0_.NAME_ as NAME6_1_, instances0_.ID_ as ID1_54_0_, instances0_.VERSION_ as VERSION3_54_0_, instances0_.PROCESSINSTANCE_ as PROCESSI4_54_0_, instances0_.TASKMGMTDEFINITION_ as TASKMGMT5_54_0_, instances0_.CLASS_ as CLASS2_54_0_ from JBPM_MODULEINSTANCE instances0_ where instances0_.PROCESSINSTANCE_=$1 
2013-03-27 09:42:09.039 GMT_jbpm_DETAIL: parameters: $1 = '9646163' 
2013-03-27 09:42:09.039 GMT_jbpm_LOCATION: exec_bind_message, postgres.c:1784 
2013-03-27 09:42:09.039 GMT_amq_LOG: 00000: duration: 0.023 ms 
2013-03-27 09:42:09.039 GMT_amq_LOCATION: exec_execute_message, postgres.c:1988 
2013-03-27 09:42:09.039 GMT_jbpm_LOG: 00000: execute <unnamed>: select instances0_.PROCESSINSTANCE_ as PROCESSI4_1_, instances0_.ID_ as ID1_1_, instances0_.NAME_ as NAME6_1_, instances0_.ID_ as ID1_54_0_, instances0_.VERSION_ as VERSION3_54_0_, instances0_.PROCESSINSTANCE_ as PROCESSI4_54_0_, instances0_.TASKMGMTDEFINITION_ as TASKMGMT5_54_0_, instances0_.CLASS_ as CLASS2_54_0_ from JBPM_MODULEINSTANCE instances0_ where instances0_.PROCESSINSTANCE_=$1 
2013-03-27 09:42:09.039 GMT_jbpm_DETAIL: parameters: $1 = '9646163' 
2013-03-27 09:42:09.039 GMT_jbpm_LOCATION: exec_execute_message, postgres.c:1918 
2013-03-27 09:42:09.039 GMT_jbpm_LOG: 00000: duration: 0.053 ms 
2013-03-27 09:42:09.039 GMT_jbpm_LOCATION: exec_execute_message, postgres.c:1988 
2013-03-27 09:42:09.039 GMT_bnw_LOG: 00000: duration: 0.068 ms parse <unnamed>: select workflowde0_.workflow_definition_id as workflow1_14_0_, workflowde0_.created as created14_0_, workflowde0_.deleted as deleted14_0_, workflowde0_.name as name14_0_, workflowde0_.version as version14_0_, workflowde0_.workspace_id as workspace6_14_0_ from workflow_definition workflowde0_ where workflowde0_.workflow_definition_id=$1 
2013-03-27 09:42:09.039 GMT_bnw_LOCATION: exec_parse_message, postgres.c:1367 
2013-03-27 09:42:09.039 GMT_bnw_LOG: 00000: duration: 0.059 ms parse <unnamed>: update worker set created=$1, deleted=$2, name=$3, full_name=$4, worker_type=$5, max_jobs_in_progress=$6, max_jobs_queued=$7, jobs_queued=$8, workspace_id=$9 where worker_id=$10 
2013-03-27 09:42:09.039 GMT_bnw_LOCATION: exec_parse_message, postgres.c:1367 
2013-03-27 09:42:09.039 GMT_bnw_LOG: 00000: duration: 0.077 ms bind <unnamed>: select workflowde0_.workflow_definition_id as workflow1_14_0_, workflowde0_.created as created14_0_, workflowde0_.deleted as deleted14_0_, workflowde0_.name as name14_0_, workflowde0_.version as version14_0_, workflowde0_.workspace_id as workspace6_14_0_ from workflow_definition workflowde0_ where workflowde0_.workflow_definition_id=$1 
2013-03-27 09:42:09.039 GMT_bnw_DETAIL: parameters: $1 = '7089580' 

我希望做的是讓我的名爲worker表的表記錄,但是避免任何有關我的數據庫中的其他表的事件記錄。

重申 - 在PostgreSQL中有沒有辦法只記錄特定表的信息?

UPDATE worker SET created=$1, deleted=$2, name=$3; 

回答

1

在PostgreSQL中執行表級粒度記錄的唯一方法是使用觸發器。您可能會發現PostgreSQL wiki中的audit trigger是信息性的。如果您只想記錄語句文本,那麼使用語句文本執行RAISE NOTICE(或某個較低日誌級別)的語句級觸發器就足夠了。

可以只是SET log_statement = 'all'通過SQL之前訪問表,但我懷疑這不是你想要的。

或者,使用專用數據庫或專用用戶和SET用戶或數據庫上的參數。例如:

ALTER USER my_queue_user SET log_statement = 'all'; 

或:

ALTER DATABASE mydb SET log_statement = 'all'; 

注意,用戶可以只覆蓋這些與SETSET LOCAL,所以他們不適合審計。