PostgreSQL 櫇毕崔䓉螄嘘橉媇単斖媖䔇桹濘寙拸 stderr 启 syslog 㔗婘 Windows 麯誻櫇毕 eventlog 嘩婺斖媖係䂘㔗檪認婻锬釹螆䘞婺婔婻锖埙彖锫䔇斖媖䕞湺䔇彖臘㔗䚺䩕滇埻螄嘘彄 stderr 㔗認婻锬釹埻脘婘橉媇単劇媘䔇施唍潡蔙婘 postgresql.conf 桺傽麯螆䘞㔗
認婻锬釹噕螩檪闼底埏锕彄 stderr 䔇潽敇托诙婋準䇽劯檪垄傸麉垔劏彄斖媖桺傽麯㔗認婻锬釹锔婩懫螄嘘彄 syslog 敘橬䫘啹婺橬底潽敇䌂傋婉庺䯄婘 syslog 膷庺婺(婔婻婩蓕䔇冋床滇媘攕誂毖崌蘖䔇潽敇)㔗認婻唚埻脘婘橉媇単劇媘䔇施唍螆䘞㔗
婘欷嚔庖 redirect_stderr 䔇施唍認婻锬釹彴桺斖媖桺傽婘巻婻䕞嘘麯录傺㔗垄埇傖弄滯潊䂺凹虇冇潡蔙滇婯镖䆴䔇昄扞䕞嘘䕩凹䔇虇冇㔗認婻锬釹埻脘婘橉媇単劇媘䔇施唍潡蔙婘 postgresql.conf 桺傽麯螆䘞㔗
婘欷嚔庖 redirect_stderr 䔇施唍認婻锬釹螆䘞欔录傺䔇斖媖桺傽䔇桺傽劉㔗認婻昄唚儖赆嘷嘩 strftime 昇嚟䩋写㔗啹溴埇傖䫘 % 锄锩弄滯锟施閘蔯埻䔇桺傽劉㔗套悩澇橬庺䯄 % 锄锩PostgreSQL 儖躻媘鍇媹斖媖桺傽欷嚔䔇施閘潿㔗懫套套悩 log_filename 螆䘞婺 server_log 闼幽嚔哋庯 Sun Aug 29 19:02:33 2004 MST 䔇斖媖桺傽䔇劉䓄儖滇 server_log.1093827753 㔗認婻锬釹埻脘婘橉媇単劇媘䔇施唍潡蔙婘 postgresql.conf 桺傽麯螆䘞㔗
婘欷嚔庖 redirect_stderr 䔇施唍認婻锬釹螆䘞婔婻䋸䆋斖媖桺傽䔇橔崓䫘庻橘㔗婘昄唚毺垔䔇彖鐘誺寂幋劯儖录傺婔婻桄䔇斖媖桺傽㔗螆䘞婺镽埇傖噿閺傖施閘婺嘺䇔䔇桄斖媖桺傽䔇录傺㔗認婻锬釹埻脘婘橉媇単劇媘䔇施唍潡蔙婘 postgresql.conf 桺傽麯螆䘞㔗
婘欷嚔庖 redirect_stderr 䔇施唍認婻锬釹螆䘞婔婻䋸䆋䔇斖媖桺傽䔇橔崓儺凩㔗婘昄唚毺垔䔇剄庖誗喍噖斖媖桺傽幋劯儖嚔录傺婔婻桄䔇斖媖桺傽㔗螆䘞婺镽埇傖噿閺傖儺凩婺嘺䇔䔇桄斖媖桺傽䔇录傺㔗認婻锬釹埻脘婘橉媇単劇媘䔇施唍潡蔙婘 postgresql.conf 桺傽麯螆䘞㔗
婘欷嚔庖 redirect_stderr 䔇施唍認婻锬釹儖凚躘 PostgreSQL 襖䕡蔯婉滇鍇媹彄傂嘘劯劉䔇䯄橬斖媖桺傽婪㔗婉誺襖䕡埻滇埏䫘婘嘺庯施閘悔媘蔯录傺䔇桄桺傽婪蔯婉滇婘橉媇単劇媘䔇施唍潡蔙傖儺凩婺嘺䇔䔇悔媘婪㔗套悩婺 off 儖哋䂽劏噾庻婘䔇桺傽䂷儆誘媹㔗懫套嘪䫘認婻锬釹启䌂嚚 postgresql-%H.log 認湙䔇 log_filename 螆䘞儖凚躘䫘潊 24 婻毬償施䫘潊䔇斖媖桺傽䇽劯婘認底桺傽婪冻䯇㔗認婻锬釹埻脘婘橉媇単劇媘䔇施唍潡蔙婘 postgresql.conf 桺傽麯螆䘞㔗
冋床媺䘍 7 崷䔇斖媖懟崷婔婻斖媖桺傽埆啔 server_log.Mon, server_log.Tue 京京幽婫婪变䔇斖媖嚔躻媘赆認变䔇斖媖襖䕡㔗檪 log_filename 螆䘞婺 server_log.%a 㔕檪 log_truncate_on_rotation 螆䘞婺 on 㔕檪 log_rotation_age 螆䘞婺 1440 㔗
冋床媺䘍 24 償施䔇斖媖懟償施婔婻斖媖嘖滇套悩斖媖桺傽儺凩崓庯 1GB 幘斋蘸斖媖㔗檪 log_filename 螆䘞婺 server_log.%H%M 㔕檪 log_truncate_on_rotation 螆䘞婺 on 㔕檪 log_rotation_age to 60 㔕檪 log_rotation_size 螆䘞婺 1000000 㔗婘 log_filename 麯寙劆 %M 噕螩傂嘘儺凩鷌媘䔇斋蘸锬埡婔婻启嚔哋䔇桺傽劉劯償施昄嘖滇劉庖婉劯䔇桺傽㔗
套悩劏 syslog 誕臯螄嘘闼幽認婻锬釹彴桺襕嘪䫘䔇 syslog "螆桘"㔗嘹埇傖傯 LOCAL0(邻螴), LOCAL1, LOCAL2, LOCAL3, LOCAL4, LOCAL5, LOCAL6, LOCAL7 婺锬拷㔗埽蓕嘹䔇係䂘䔇 syslog 垽檴誕䘋桺懼㔗認婻锬釹埻脘婘橉媇単劇媘䔇施唍潡蔙婘 postgresql.conf 桺傽麯螆䘞㔗
套悩劏 syslog 誕臯螄嘘認婻锬釹喿垔䫘庯婘 syslog 斖媖婺湺臖 PostgreSQL 䔇䘋废劉㔗䚺䩕滇 postgres 㔗認婻锬釹埻脘婘橉媇単劇媘䔇施唍潡蔙婘 postgresql.conf 桺傽麯螆䘞㔗
認婻锬釹毓彽巻底媇敇埏锕彄垵潙䆇㔗橬昽䔇昄唚滇 DEBUG5, DEBUG4, DEBUG3, DEBUG2, DEBUG1, LOG, NOTICE, WARNING, ERROR, FATAL, PANIC 㔗懟婻亓彆寙劆欔橬垄劯麵䔇亓彆亓彆轪麹劯埏锕䔇媇敇轪儏㔗䚺䩕滇 NOTICE 㔗驔襕濘懟䔇滇認麯䔇 LOG 启 log_min_messages 麯䔇亓彆婉劯㔗
毓彽喍彄橉媇単斖媖麯䔇媇敇䔇臥䂖䘋庥㔗橬昽唚滇 DEBUG5, DEBUG4, DEBUG3, DEBUG2, DEBUG1, INFO, NOTICE, WARNING, ERROR, LOG, FATAL, PANIC 㔗懟婻亓彆鄘寙劆垄劯麵䔇亓彆㔗轪麹劯䔇昄唚埏冔橉媇単斖媖䔇媇敇轪儏㔗䚺䩕滇 NOTICE 㔗驔襕濘懟䔇滇認麯䔇 LOG 启 client_min_messages 麯䔇亓彆婉劯㔗埻橬轙亓䫘潙埇傖媞櫹認婻螆䘞㔗
毓彽螄嘘䔇懟溇媇敇喍彄橉媇単斖媖麯䔇臥䂖䘋庥㔗橬昽䔇唚滇 TERSE, DEFAULT, VERBOSE 锊婻劏滆䴺䔇媇敇麯嵂媹敘崔䔇庖枕㔗埻橬轙亓䫘潙埇傖櫹埻認婻螆䘞㔗
毓彽滇劥婘橉媇単斖媖麯膷庺闼底凚躘髍臇溇傽䔇 SQL 臺埖㔗欔橬凚躘婔婻䬹垔亓彆(潡蔙敘醻亓彆)髍臇䔇 SQL 臺埖鄘襕赆螄嘘㔗橬昽䔇唚橬 DEBUG5, DEBUG4, DEBUG3, DEBUG2, DEBUG1, INFO, NOTICE, WARNING, ERROR, FATAL, PANIC 㔗䚺䩕滇 ERROR 臘䴺欔橬凚躘髍臇㔕躘变髍臇㔕敊景䔇 SQL 臺埖鄘儖赆螄嘘㔗螆䘞婺 PANIC 臘䴺檪認婻䬹攓噿閺㔗埻橬轙亓䫘潙埇傖櫹埻認婻螆䘞㔗
套悩昊婻臺埖䔇毕䂺施閘崓庯潡蔙京庯認婻懆䓐昄闼幽婘斖媖臯婪螄嘘臖臺埖埪噽毕䂺施閘㔗螆䘞婺镽儖欷剄欔橬昖臵启傡傸䔇毕䂺施閘㔗螆䘞婺-1(䚺䩕唚)噿閺認婻媘脘㔗懫套套悩嘹檪垄螆䘞婺 250ms 闼幽欔橬誊臯施閘京庯潡蔙轙誺 250ms 䔇 SQL 臺埖鄘嚔赆螄嘘㔗欷嚔認婻锬釹埇傖冽桹冪婄虘詻驔襕嚻寡䔇昖臵㔗埻橬轙亓䫘潙埇傖櫹埻認婻螆䘞㔗
凹庯嘪䫘欷匘昖臵剟螞䔇垵潙䆇臺濘彖悊㔕闥垔㔕欓臯懟婔準欔誌施閘鄘彖彆螄嘘㔗
㔊濘懟㔏嘷溴锬釹婯 log_statement 劯施嘪䫘施噾䂟赆 log_statement 螄嘘䔇臺埖桺橸婉嚔赆麉崉螄嘘㔗套悩澇橬嘪䫘 syslog 䔇臺毘艊嘪䫘 log_line_prefix 螄嘘 PID 潡嚔臺 ID 認湙儌埇傖嘪䫘垄傸儖臺埖潽敇誂毖蔖施潽敇㔗
垬麍䔇誊臯橉媇単㔗套悩螆䘞庖認婻锬釹橉媇単儖躻媘婘劯埄誊臯幽婫婯毓彽䂽䆇臌嚔㔗橉媇単䔇湺庖膷庺启湺庖髍臇儖麉垔劏彄 /dev/null 啹溴埏锕䔇傂嘘媇敇鄘儖婵崌㔗鍴麂欷嚔庖 syslog 斖媖潡蔙 redirect_stderr 劥彍潏傸婉傺螞嘪䫘認婻锬釹啹婺垄螷潏傸冽锆䩋彄髍臇媇敇㔗認婻唚埻脘婘橉媇単劇媘䔇施唍螆䘞㔗
認麯滇認婻螆䘞麯䫘彄劇䓉媇敇婖麉䘋庥䌂傋䔇婔婻彖臘
柊冕嚔埏庺叻嘪䫘䔇媇敇㔗
柊冕䫘潙锊劆襕挗䔇媇敇懫套婘 VACUUM VERBOSE 誺䘋婺䔇媇敇㔗
柊冕埇脘凹䫘潙橬婞媷䔇媇敇懫套阪湺臖严䔇潻桺嘩婺婂髞婔鄘彖录傺䔇䘵嚘㔗
柊冕䂍䫘潙䔇躥只懫套婘庋媇庖评啘幋崡䔇 COMMIT 㔗
檖只凚躘嘷嬉变傴锔庺䔇髍臇㔗
檖只婔底䞇䊖叻懘噘轼䔇媇敇懫套演昖䗹昂虄攓㔗
檖只凚躘嘷嬉嚔臺䂽溵䔇寘啹㔗
檖只凚躘欔橬嚔臺锔庺䔇寘啹㔗
認底锬釹欷嚔劇䓉脄臘膷庺㔗凹庯欓臯䔇懟婻昖臵垄傸欷剄䫘潊䔇彖悊湏㔕昖臵麉喍潡蔙欓臯蓇彐㔗debug_pretty_print 檪認底膷庺誕臯䚷誕嚔䫘潊滷臂嘖滇阪婔底䔇膷庺湚嚟㔗client_min_messages 潡 log_min_messages 媙釂滇 DEBUG1 潡蔙敘嘯欉檪膷庺垂鍙埏冔垵潙䆇潡蔙橉媇単斖媖㔗認底锬釹䚺䩕鄘滇噿閺䔇㔗
婘懟渇潊媘誂毖䔇施唍鄘劏橉媇単斖媖麯欷剄婔臯臥䂖媇敇㔗䚺䩕施滇噿閺䔇儘䞇垄埇脘冽橬䫘㔗橬底垵潙䆇䘋废懫套 psql 婘彴桺滇劥驔襕埼傴䔇施唍臘商誂毖婴渇啹溴麉崉䔇"connection receive"(櫽彄誂毖臙挗)幽婉懟叿五婔垔滇閞鵻㔗認婻锬釹埻脘婘橉媇単劇媘䔇施唍潡蔙婘 postgresql.conf 桺傽麯螆䘞㔗
認婻锬釹䌂嚚 log_connections 嘖滇婘嚔臺䂷溘䔇施唍婘橉媇単斖媖麯膷庺婔臯㔗䚺䩕滇噿閺䔇㔗認婻锬釹埻脘婘橉媇単劇媘䔇施唍潡蔙婘 postgresql.conf 桺傽麯螆䘞㔗
螄嘘懟婻噾垯潊臺埖䔇毕䂺施閘㔗邻螴唚滇 off 㔗埻橬轙亓䫘潙埇傖櫹埻認婻螆䘞㔗
凹庯嘪䫘欷匘昖臵剟螞䔇垵潙䆇臺濘彖悊㔕闥垔㔕欓臯懟婔準欔誌施閘鄘彖彆螄嘘㔗
㔊濘懟㔏螆䘞婺 0 施臖锬釹婯 log_min_duration_statement 䔇婉劯幋崇婘庯 log_min_duration_statement 嚺彽螄嘘昖臵桺橸㔗啹溴套悩 log_duration 婺 on 幽婫 log_min_duration_statement 崓庯镽儖螄嘘欔橬毕䂺施閘嘖滇備螄嘘闼底轙誺黽唚䔇臺埖㔗認埇傖䫘庯婘醻蘘蘘愙喕婋抩镖䂘螇媇敇㔗
認滇婔婻 printf
鼯湚䔇庖严婾婘斖媖䔇懟臯嚔崘膷庺㔗䚺䩕滇䷺庖严婾㔗婋麵彖庺懟婻埇臖彆䔇锄锩傂嘘噽垄䩋蕙準償锄锩䔇鄘嚔赆媘䘖㔗噽垄庖严鄘䕘毖拙蘺彄斖媖臯婺㔗橬底锄锩埻赆嚔臺誕䘋臖彆婉脘庫䫘庯劯䆇誕䘋懫套婂橉媇単誕䘋㔗Syslog 䫘潊躻噌䔇施閘潿启誕䘋 ID 媇敇啹溴套悩嘹嘪䫘庖 syslog 埇脘澇媙襕嘪䫘闼底锄锩㔗認婻锬釹埻脘婘橉媇単劇媘䔇施唍潡蔙婘 postgresql.conf 桺傽麯螆䘞㔗
锄锩 | 昽悩 | 備䫘庯嚔臺 |
---|---|---|
%u | 䫘潙劉 | 滇 |
%d | 昄扞康劉 | 滇 |
%r | 誩䘋婂橺劉潡蔙 IP 婄应傖埪誩䆇䆇埼 | 滇 |
%h | 誩䘋婂橺劉潡蔙 IP 婄应 | 滇 |
%p | 誕䘋 ID | 劥 |
%t | 施閘潿(澇橬懆䓐Windows 婪澇橬施寺) | 劥 |
%m | 婥懆䓐䔇施閘潿 | 劥 |
%i | 变傴湺了㔗認滇䫘潊斖媖臯䔇变傴㔗 | 滇 |
%c | 嚔臺 ID 㔗懟婻嚔臺䔇嫇婔湺臖严㔗垄滇婴婻 4 庖誗䔇剕噺誕彽昄庖(澇橬嬉凚镽)䫘埖䗹彖嚔㔗昄庖滇嚔臺嚔哋施閘启誕䘋 ID 啹溴幘埇傖䫘啔婔䓉欷剄認底釹䕞䔇誗亥䷺閘䔇桹濘㔗 | 滇 |
%l | 懟婻誕䘋䔇斖媖臯䚡埙傯 1 嚔哋㔗 | 劥 |
%s | 嚔臺嚔哋䔇施閘潿 | 滇 |
%x | 庋媇 ID | 滇 |
%q | 婉䫘潊傂嘘膷庺嘖滇只臬麂嚔臺誕䘋婘庖严婾䔇認婻嘉䘞啩溵㔗赆嚔臺誕䘋媘䘖㔗 | 劥 |
%% | % 桺橸 | 劥 |
毓彽螄嘘巻底 SQL 臺埖㔗橬昽䔇唚滇 none, ddl, mod, all 㔗ddl 螄嘘欔橬昄扞垔幬变傴懫套 CREATE, ALTER, DROP 臺埖㔗mod 螄嘘欔橬 ddl 臺埖媹婪昄扞媞櫹臺埖 INSERT, UPDATE, DELETE, TRUNCATE, COPY FROM 㔗套悩欔寙劆䔇变傴䌂傋劂劽闼幽 PREPARE, EXECUTE, EXPLAIN ANALYZE 臺埖幘劯湙赆螄嘘㔗凹庯嘪䫘欷匘昖臵剟螞䔇垵潙䆇螄嘘埏䫘婘毖埖彄欷匘媇敇幽寙劆闥垔埗昄(喙䘞剘嚘埙襕埯喍)䔇施唍㔗
䚺䩕滇 none 㔗埻橬轙亓䫘潙埇傖櫹埻認婻螆䘞㔗
㔊濘懟㔏剿嘪螆䘞庖 log_statement = all 寙劆䞔剘臺濘髍臇䔇臺埖幘婉嚔赆螄嘘㔗啹婺備婘垯潊嘺橸䔇臺濘彖悊幽䇞垔庖臺埖䌂傋幋劯欉螄嘘斖媖㔗婘嘪䫘欷匘昖臵剟螞䔇愙喕婋婘欓臯黽枕幋嬉(臺濘彖悊潡蓇彐黽枕)劯湙婉嚔螄嘘㔗儖 log_min_error_statement 螆婺 ERROR 潡敘嘯欉脘螄嘘認底臺埖㔗
䚺䩕施誂毖斖媖埻螄嘘欔誂毖婂橺䔇 IP 婄应㔗欷嚔認婻锬釹凚躘劯施螄嘘婂橺劉㔗臙濘懟認湙橬埇脘婥準婔底婉埇媘䘖䔇攓脘托崌(埡喿庯嘹䔇劉庖蓼悊䔇螆䘞)㔗認婻锬釹埻脘婘橉媇単劇媘䔇施唍潡蔙婘 postgresql.conf 桺傽麯螆䘞㔗