postgresql錯誤日志收集的方法-創(chuàng)新互聯(lián)

創(chuàng)新互聯(lián)www.cdcxhl.cn八線動態(tài)BGP香港云服務(wù)器提供商,新人活動買多久送多久,劃算不套路!

企業(yè)建站必須是能夠以充分展現(xiàn)企業(yè)形象為主要目的,是企業(yè)文化與產(chǎn)品對外擴(kuò)展宣傳的重要窗口,一個合格的網(wǎng)站不僅僅能為公司帶來巨大的互聯(lián)網(wǎng)上的收集和信息發(fā)布平臺,創(chuàng)新互聯(lián)面向各種領(lǐng)域:成都輕質(zhì)隔墻板成都網(wǎng)站設(shè)計(jì)、營銷型網(wǎng)站解決方案、網(wǎng)站設(shè)計(jì)等建站排名服務(wù)。

小編給大家分享一下postgresql錯誤日志收集的方法,相信大部分人都還不怎么了解,因此分享這邊文章給大家學(xué)習(xí),希望大家閱讀完這篇文章后大所收獲,下面讓我們一起去學(xué)習(xí)方法吧!

PG安裝完成后默認(rèn)不會記錄日志,必須修改對應(yīng)的(${PGDATA}/postgresql.conf)配置才可以,這里只介紹常用的日志配置。

1、logging_collector = on/off  ----  是否將日志重定向至文件中,默認(rèn)是off(該配置修改后,需要重啟DB服務(wù)).

DB安裝完成,啟動的服務(wù)進(jìn)程如下

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

將此配置修改為on,并重啟DB服務(wù),DB啟動過程中會提示將日志重定向${PGDATA}/pg_log中。

[root@localhost ~]# su -l postgres -c '/opt/pg9.6/bin/pg_ctl -D /mnt/pgdata start'server starting
LOG:  redirecting log output to logging collector process
HINT:  Future log output will appear in directory "pg_log".

 此時在運(yùn)行的進(jìn)程如下,與之前相比,多了一個logger進(jìn)程。

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

以下配置修改不需要重啟服務(wù),只需重載配置

[root@localhost ~]# su -l postgres -c '/opt/pg9.6/bin/pg_ctl -D /mnt/pgdata reload'

2、log_directory = 'pg_log' ---- 日志文件目錄,默認(rèn)是PGDATA的相對路徑,即PGDATA的相對路徑,即{PGDATA}/pg_log,也可以改為絕對路徑

默認(rèn)為${PGDATA}/pg_log,即集群目錄下,但是日志文件可能會非常多,建議將日志重定向到其他目錄或分區(qū)。

將此配置修改為/var/log/pg_log下,必須先創(chuàng)建此目錄,并修改權(quán)限,如

[root@localhost ~]# mkdir -p /var/log/pg_log
[root@localhost ~]# chown postgres:postgres /var/log/pg_log/[root@localhost ~]# chmod 700 /var/log/pg_log/

重啟DB服務(wù)后,日志將重定向至/var/log/pg_log下

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

[root@localhost ~]# ls /var/log/pg_log/
postgresql-2016-06-18_130611.log

3.log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log' ---- 日志文件命名形式,使用默認(rèn)即可

4. log_rotation_age = 1d ----  單個日志文件的生存期,默認(rèn)1天,在日志文件大小沒有達(dá)到log_rotation_size時,一天只生成一個日志文件

5. log_rotation_size = 10MB  ---- 單個日志文件的大小,如果時間沒有超過log_rotation_age,一個日志文件大只能到10M,否則將新生成一個日志文件。

6.log_truncate_on_rotation = off ---- 當(dāng)日志文件已存在時,該配置如果為off,新生成的日志將在文件尾部追加,如果為on,則會覆蓋原來的日志。

7.log_lock_waits = off ---- 控制當(dāng)一個會話等待時間超過deadlock_timeout而被鎖時是否產(chǎn)生一個日志信息。在判斷一個鎖等待是否會影響性能時是有用的,缺省是off。

8.log_statement = 'none' # none, ddl, mod, all ---- 控制記錄哪些SQL語句。none不記錄,ddl記錄所有數(shù)據(jù)定義命令,比如CREATE,ALTER,和DROP 語句。mod記錄所有ddl語句,加上數(shù)據(jù)修改語句INSERT,UPDATE等,all記錄所有執(zhí)行的語句,將此配置設(shè)置為all可跟蹤整個數(shù)據(jù)庫執(zhí)行的SQL語句。

9.log_duration = off ---- 記錄每條SQL語句執(zhí)行完成消耗的時間,將此配置設(shè)置為on,用于統(tǒng)計(jì)哪些SQL語句耗時較長。

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將記錄所有SQL語句和它們的耗時,>0只記錄那些耗時超過(或等于)這個值(ms)的SQL語句。個人更喜歡使用該配置來跟蹤那些耗時較長,可能存在性能問題的SQL語句。雖然使用log_statement和log_duration也能夠統(tǒng)計(jì)SQL語句及耗時,但是SQL語句和耗時統(tǒng)計(jì)結(jié)果可能相差很多行,或在不同的文件中,但是log_min_duration_statement會將SQL語句和耗時在同一行記錄,更方便閱讀。

11.log_connections = off ----是否記錄連接日志

12.log_disconnections = off ---- 是否記錄連接斷開日志

13.log_line_prefix = '%m %p %u %d %r ' ---- 日志輸出格式(%m,%p實(shí)際意義配置文件中有解釋),可根據(jù)自己需要設(shè)置(能夠記錄時間,用戶名稱,數(shù)據(jù)庫名稱,客戶端IP和端口,方便定位問題)

14.log_timezone = 'Asia/Shanghai' ---- 日志時區(qū),最好和服務(wù)器設(shè)置同一個時區(qū),方便問題定位

服務(wù)器時區(qū)設(shè)置

[root@localhost ~]# cp -rf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

以上是postgresql錯誤日志收集的方法的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學(xué)習(xí)更多知識,歡迎關(guān)注創(chuàng)新互聯(lián)-成都網(wǎng)站建設(shè)公司行業(yè)資訊頻道!

當(dāng)前名稱:postgresql錯誤日志收集的方法-創(chuàng)新互聯(lián)
URL鏈接:http://muchs.cn/article28/dgiojp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站制作、軟件開發(fā)、定制網(wǎng)站、標(biāo)簽優(yōu)化、全網(wǎng)營銷推廣、網(wǎng)站導(dǎo)航

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站網(wǎng)頁設(shè)計(jì)