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鏃ュ織鏀堕泦的主要内容,如果未能解决你的问题,请参考以下文章