2013-10-29 85 views
2

每次我調用參數化查詢時,都會在日誌文件中獲得太多輸出。例如,將3個用戶到表中時,我得到以下日誌輸出:減少postgresql日誌冗長度

2013-10-29 06:01:43 EDT LOG: duration: 0.000 ms parse <unnamed>: INSERT INTO users (login,role,password) VALUES 
    ($1,$2,$3) 
    ,($4,$5,$6) 
    ,($7,$8,$9) 
2013-10-29 06:01:43 EDT LOG: duration: 0.000 ms bind <unnamed>: INSERT INTO users (login,role,password) VALUES 
    ($1,$2,$3) 
    ,($4,$5,$6) 
    ,($7,$8,$9) 
2013-10-29 06:01:43 EDT DETAIL: parameters: $1 = 'guest', $2 = 'user', $3 = '123', $4 = 'admin', $5 = 'admin', $6 = '123', $7 = 'mark', $8 = 'power user', $9 = '123' 
2013-10-29 06:01:43 EDT LOG: execute <unnamed>: INSERT INTO users (login,role,password) VALUES 
    ($1,$2,$3) 
    ,($4,$5,$6) 
    ,($7,$8,$9) 
2013-10-29 06:01:43 EDT DETAIL: parameters: $1 = 'guest', $2 = 'user', $3 = '123', $4 = 'admin', $5 = 'admin', $6 = '123', $7 = 'mark', $8 = 'power user', $9 = '123' 
2013-10-29 06:01:43 EDT LOG: duration: 4.000 ms 

注意,整個查詢出現三次 - 用於解析,對地結合和執行。整套參數出現兩次 - 用於綁定和執行。

請注意,只有在運行參數化查詢時纔會出現這種冗餘性。

這裏是我的配置:

C:\Program Files\PostgreSQL\9.2\data>findstr log_ postgresql.conf 
# "postgres -c log_connections=on". Some parameters can be changed at run time 
log_destination = 'stderr'    # Valid values are combinations of 
log_directory = 'pg_log'    # directory where log files are written, 
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log' # log file name pattern, 
log_file_mode = 0600     # creation mode for log files, 
#log_truncate_on_rotation = off   # If on, an existing log file with the 
#log_rotation_age = 1d     # Automatic rotation of logfiles will 
#log_rotation_size = 10MB    # Automatic rotation of logfiles will 
#syslog_facility = 'LOCAL0' 
#syslog_ident = 'postgres' 
log_min_messages = notice    # values in order of decreasing detail: 
log_min_error_statement = error # values in order of decreasing detail: 
log_min_duration_statement = 0 # -1 is disabled, 0 logs all statements 
#log_checkpoints = off 
#log_connections = off 
#log_disconnections = off 
#log_duration = off 
#log_error_verbosity = default   # terse, default, or verbose messages 
#log_hostname = off 
log_line_prefix = '%t '     # special values: 
#log_lock_waits = off     # log lock waits >= deadlock_timeout 
log_statement = 'all'     # none, ddl, mod, all 
#log_temp_files = -1     # log temporary files equal or larger 
log_timezone = 'US/Eastern' 
#log_parser_stats = off 
#log_planner_stats = off 
#log_executor_stats = off 
#log_statement_stats = off 
#log_autovacuum_min_duration = -1  # -1 disables, 0 logs all actions and 

C:\Program Files\PostgreSQL\9.2\data> 

所以,我的問題是如何減少日誌參數化查詢的詳細程度而不會影響其他查詢?理想情況下,我希望查詢SQL及其參數只記錄一次。

+0

哦,純粹主義者... – mark

+0

你的問題是什麼? –

+0

糟糕。現在加入。 – mark

回答

1

我不認爲這是可能的開箱即用。你可以編寫一個日誌鉤子和過濾日誌條目。