Postgresql鏃ュ織鏀堕泦

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Postgresql鏃ュ織鏀堕泦相关的知识,希望对你有一定的参考价值。

鏍囩锛?/p>

PG瀹夎瀹屾垚鍚庨粯璁や笉浼氳褰曟棩蹇楋紝蹇呴』淇敼瀵瑰簲鐨勶紙${PGDATA}/postgresql.conf锛夐厤缃墠鍙互锛岃繖閲屽彧浠嬬粛甯哥敤鐨勬棩蹇楅厤缃€?/span>

1.logging_collector = on/off  ----  鏄惁灏嗘棩蹇楅噸瀹氬悜鑷虫枃浠朵腑锛岄粯璁ゆ槸off锛?span style="color: #ff0000;">璇ラ厤缃慨鏀瑰悗锛岄渶瑕侀噸鍚疍B鏈嶅姟锛?/span>

DB瀹夎瀹屾垚锛屽惎鍔ㄧ殑鏈嶅姟杩涚▼濡備笅

[[email protected] ~]# ps -elf | grep postgres
0 S postgres  2385     1  0  80   0 - 66829 poll_s 12:41 ?        00:00:00 /opt/pg9.6/bin/postgres -D /mnt/pgdata
1 S postgres  2387  2385  0  80   0 - 66829 ep_pol 12:41 ?        00:00:00 postgres: checkpointer process        
1 S postgres  2388  2385  0  80   0 - 66829 ep_pol 12:41 ?        00:00:00 postgres: writer process              
1 S postgres  2389  2385  0  80   0 - 66870 ep_pol 12:41 ?        00:00:00 postgres: wal writer process          
1 S postgres  2390  2385  0  80   0 - 66952 ep_pol 12:41 ?        00:00:00 postgres: autovacuum launcher process   
1 S postgres  2391  2385  0  80   0 - 29643 ep_pol 12:41 ?        00:00:00 postgres: stats collector process

灏嗘閰嶇疆淇敼涓簅n锛屽苟閲嶅惎DB鏈嶅姟锛孌B鍚姩杩囩▼涓細鎻愮ず灏嗘棩蹇楅噸瀹氬悜${PGDATA}/pg_log涓€?/span>

[[email protected] ~]# su -l postgres -c 鈥?/span>/opt/pg9.6/bin/pg_ctl -D /mnt/pgdata start鈥?/span>
server starting
LOG:  redirecting log output to logging collector process
HINT:  Future log output will appear in directory "pg_log".

 姝ゆ椂鍦ㄨ繍琛岀殑杩涚▼濡備笅锛屼笌涔嬪墠鐩告瘮锛屽浜嗕竴涓猯ogger杩涚▼銆?/span>

[[email protected] ~]# ps -elf | grep postgres
0 S postgres  2448     1  0  80   0 - 66830 poll_s 12:50 ?        00:00:00 /opt/pg9.6/bin/postgres -D /mnt/pgdata
1 S postgres  2449  2448  0  80   0 - 29645 ep_pol 12:50 ?        00:00:00 postgres: logger process              
1 S postgres  2451  2448  0  80   0 - 66830 ep_pol 12:50 ?        00:00:00 postgres: checkpointer process        
1 S postgres  2452  2448  0  80   0 - 66830 ep_pol 12:50 ?        00:00:00 postgres: writer process              
1 S postgres  2453  2448  0  80   0 - 66871 ep_pol 12:50 ?        00:00:00 postgres: wal writer process          
1 S postgres  2454  2448  0  80   0 - 66953 ep_pol 12:50 ?        00:00:00 postgres: autovacuum launcher process   
1 S postgres  2455  2448  0  80   0 - 29644 ep_pol 12:50 ?        00:00:00 postgres: stats collector process   

 

浠ヤ笅閰嶇疆淇敼涓嶉渶瑕侀噸鍚湇鍔★紝鍙渶閲嶈浇閰嶇疆

[[email protected] ~]# su -l postgres -c 鈥?/span>/opt/pg9.6/bin/pg_ctl -D /mnt/pgdata reload鈥?/span>

 

2.log_directory = 鈥榩g_log鈥?/strong> ---- 鏃ュ織鏂囦欢鐩綍锛岄粯璁ゆ槸${PGDATA}鐨勭浉瀵硅矾寰勶紝鍗?{PGDATA}/pg_log锛屼篃鍙互鏀逛负缁濆璺緞

榛樿涓?{PGDATA}/pg_log锛屽嵆闆嗙兢鐩綍涓嬶紝浣嗘槸鏃ュ織鏂囦欢鍙兘浼氶潪甯稿锛屽缓璁皢鏃ュ織閲嶅畾鍚戝埌鍏朵粬鐩綍鎴栧垎鍖恒€?/span>

灏嗘閰嶇疆淇敼涓?var/log/pg_log涓嬶紝蹇呴』鍏堝垱寤烘鐩綍锛屽苟淇敼鏉冮檺锛屽

[[email protected] ~]# mkdir -p /var/log/pg_log
[[email protected] ~]# chown postgres:postgres /var/log/pg_log/
[[email protected] ~]# chmod 700 /var/log/pg_log/

閲嶅惎DB鏈嶅姟鍚庯紝鏃ュ織灏嗛噸瀹氬悜鑷?var/log/pg_log涓?/span>

[[email protected] ~]# su -l postgres -c 鈥?/span>/opt/pg9.6/bin/pg_ctl -D /mnt/pgdata start鈥?/span>
server starting
LOG:  redirecting log output to logging collector process
HINT:  Future log output will appear in directory "/var/log/pg_log".

[[email protected] ~]# ls /var/log/pg_log/
postgresql-2016-06-18_130611.log

 

3.log_filename = 鈥榩ostgresql-%Y-%m-%d_%H%M%S.log鈥?/span> ---- 鏃ュ織鏂囦欢鍛藉悕褰㈠紡锛屼娇鐢ㄩ粯璁ゅ嵆鍙?/span>

4. log_rotation_age = 1d ----  鍗曚釜鏃ュ織鏂囦欢鐨勭敓瀛樻湡锛岄粯璁?澶╋紝鍦ㄦ棩蹇楁枃浠跺ぇ灏忔病鏈夎揪鍒?tt class="VARNAME">log_rotation_size鏃讹紝涓€澶╁彧鐢熸垚涓€涓棩蹇楁枃浠?/tt>

5. log_rotation_size = 10MB  ---- 鍗曚釜鏃ュ織鏂囦欢鐨勫ぇ灏忥紝濡傛灉鏃堕棿娌℃湁瓒呰繃log_rotation_age锛屼竴涓棩蹇楁枃浠舵渶澶у彧鑳藉埌10M锛屽惁鍒欏皢鏂扮敓鎴愪竴涓棩蹇楁枃浠躲€?/span>

6.log_truncate_on_rotation = off ---- 褰撴棩蹇楁枃浠跺凡瀛樺湪鏃讹紝璇ラ厤缃鏋滀负off锛屾柊鐢熸垚鐨勬棩蹇楀皢鍦ㄦ枃浠跺熬閮ㄨ拷鍔狅紝濡傛灉涓簅n锛屽垯浼氳鐩栧師鏉ョ殑鏃ュ織銆?/span>

7.log_lock_waits = off ---- 鎺у埗褰撲竴涓細璇濈瓑寰呮椂闂磋秴杩嘾eadlock_timeout鑰岃閿佹椂鏄惁浜х敓涓€涓棩蹇椾俊鎭€傚湪鍒ゆ柇涓€涓攣绛夊緟鏄惁浼氬奖鍝嶆€ц兘鏃舵槸鏈夌敤鐨勶紝缂虹渷鏄痮ff銆?/span>

8.log_statement = 鈥榥one鈥?/span> # none, ddl, mod, all ---- 鎺у埗璁板綍鍝簺SQL璇彞銆俷one涓嶈褰曪紝ddl璁板綍鎵€鏈夋暟鎹畾涔夊懡浠わ紝姣斿CREATE,ALTER,鍜孌ROP 璇彞銆俶od璁板綍鎵€鏈塪dl璇彞,鍔犱笂鏁版嵁淇敼璇彞INSERT,UPDATE绛?all璁板綍鎵€鏈夋墽琛岀殑璇彞锛?span style="color: #ff0000;">灏嗘閰嶇疆璁剧疆涓篴ll鍙窡韪暣涓暟鎹簱鎵ц鐨凷QL璇彞銆?/span>

9.log_duration = off ---- 璁板綍姣忔潯SQL璇彞鎵ц瀹屾垚娑堣€楃殑鏃堕棿锛?span style="color: #ff0000;">灏嗘閰嶇疆璁剧疆涓簅n,鐢ㄤ簬缁熻鍝簺SQL璇彞鑰楁椂杈冮暱銆?/span>

10.log_min_duration_statement = -1 # -1 is disabled, 0 logs all statements and their durations, > 0 logs only statements running at least this number of milliseconds

-1琛ㄧず涓嶅彲鐢紝0灏嗚褰曟墍鏈塖QL璇彞鍜屽畠浠殑鑰楁椂锛?gt;0鍙褰曢偅浜涜€楁椂瓒呰繃锛堟垨绛変簬锛夎繖涓€硷紙ms锛夌殑SQL璇彞銆?span style="color: #ff0000;">涓汉鏇村枩娆娇鐢ㄨ閰嶇疆鏉ヨ窡韪偅浜涜€楁椂杈冮暱锛屽彲鑳藉瓨鍦ㄦ€ц兘闂鐨凷QL璇彞銆傝櫧鐒朵娇鐢╨og_statement鍜宭og_duration涔熻兘澶熺粺璁QL璇彞鍙婅€楁椂锛屼絾鏄疭QL璇彞鍜岃€楁椂缁熻缁撴灉鍙兘鐩稿樊寰堝琛岋紝鎴栧湪涓嶅悓鐨勬枃浠朵腑锛屼絾鏄痩og_min_duration_statement浼氬皢SQL璇彞鍜岃€楁椂鍦ㄥ悓涓€琛岃褰曪紝鏇存柟渚块槄璇汇€?/span>

11.log_connections = off ----鏄惁璁板綍杩炴帴鏃ュ織

12.log_disconnections = off ---- 鏄惁璁板綍杩炴帴鏂紑鏃ュ織

13.log_line_prefix = 鈥?m %p %u %d %r 鈥?/span> ---- 鏃ュ織杈撳嚭鏍煎紡锛?m,%p瀹為檯鎰忎箟閰嶇疆鏂囦欢涓湁瑙i噴锛?鍙牴鎹嚜宸遍渶瑕佽缃紙鑳藉璁板綍鏃堕棿锛岀敤鎴峰悕绉帮紝鏁版嵁搴撳悕绉帮紝瀹㈡埛绔疘P鍜岀鍙o紝鏂逛究瀹氫綅闂锛?/span>

 

14.log_timezone = 鈥楢sia/Shanghai鈥?/span> ---- 鏃ュ織鏃跺尯锛?span style="color: #ff0000;">鏈€濂藉拰鏈嶅姟鍣ㄨ缃悓涓€涓椂鍖猴紝鏂逛究闂瀹氫綅

鏈嶅姟鍣ㄦ椂鍖鸿缃?/span>

[[email protected] ~]# cp -rf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime 

 

以上是关于Postgresql鏃ュ織鏀堕泦的主要内容,如果未能解决你的问题,请参考以下文章

webpack鍏ラ棬-涓汉瀛︿範璧勬簮鏀堕泦

璇﹁В JVM Garbage First(G1) 鍨冨溇鏀堕泦鍣?/h1>

logging鏃ュ織妯″潡

mysql 鏃ュ織log

nginx鏃ュ織璇存槑

Apache鏃ュ織鍒嗗壊