主頁(yè) > 知識(shí)庫(kù) > Postgresql的日志配置教程詳解

Postgresql的日志配置教程詳解

熱門(mén)標(biāo)簽:濟(jì)南外呼網(wǎng)絡(luò)電話(huà)線路 地圖標(biāo)注要花多少錢(qián) 移動(dòng)外呼系統(tǒng)模擬題 電話(huà)機(jī)器人怎么換人工座席 江蘇400電話(huà)辦理官方 電銷(xiāo)機(jī)器人能補(bǔ)救房產(chǎn)中介嗎 天津開(kāi)發(fā)區(qū)地圖標(biāo)注app 400電話(huà)申請(qǐng)客服 廣州電銷(xiāo)機(jī)器人公司招聘

背景

公司的項(xiàng)目中使用了postgresql(簡(jiǎn)稱(chēng)pg)作為其數(shù)據(jù)庫(kù)管理系統(tǒng),前兩天環(huán)境突然崩潰了,頁(yè)面無(wú)法打開(kāi)。經(jīng)過(guò)排查,我發(fā)現(xiàn)是數(shù)據(jù)庫(kù)所在機(jī)器磁盤(pán)滿(mǎn)了,通過(guò)目錄和文件排序,原來(lái)是pg的日志太多(大約保留了大半年的日志在磁盤(pán)上沒(méi)有被清理)。

我看了下pg的日志配置,發(fā)現(xiàn)基本都是用的默認(rèn)配置,日志滾動(dòng)沒(méi)有開(kāi)啟,于是乎做了下相關(guān)配置優(yōu)化后對(duì)pg進(jìn)行重啟,最后看了pg的日志滾動(dòng),恢復(fù)正常了。以下是我梳理的關(guān)于pg的日志配置項(xiàng)。

配置詳解

配置文件:postgresql.conf

配置1:日志開(kāi)啟與關(guān)閉

默認(rèn)為off,設(shè)置為on則pg可以記錄相關(guān)日志,建議打開(kāi),否則在數(shù)據(jù)庫(kù)出現(xiàn)異常時(shí)候,沒(méi)有日志來(lái)定位具體問(wèn)題

# This is used when logging to stderr:
logging_collector =on# Enable capturing of stderr and csvlog
# into log files. Required to be on for
# csvlogs.
# (change requires restart)

配置2:日志滾動(dòng)策略

# These are only used if logging_collector is on:

#配置日志目錄,默認(rèn)為pg_log即可

log_directory = 'pg_log' # directory where log files are written,

# can be absolute or relative to PGDATA

#pg日志文件名及其擴(kuò)展名,默認(rèn)即可

log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log' # log file name pattern,

# can include strftime() escapes

#pg日志文件的權(quán)限,默認(rèn)即可

log_file_mode = 0600 # creation mode for log files,

#開(kāi)啟日志滾動(dòng)階段,這里需要設(shè)置為on

log_truncate_on_rotation =on# If on, an existing log file with the

#日志保留天數(shù),這里看實(shí)際環(huán)境,如果是測(cè)試建議1d,如果是生產(chǎn)環(huán)境建議7d

log_rotation_age = 1d # Automatic rotation of logfiles will

#單個(gè)日志大小,默認(rèn)100MB即可,比較標(biāo)準(zhǔn)的配置

配置3:日志打印時(shí)機(jī)

#發(fā)送給客戶(hù)端的消息級(jí)別,建議warning即可,日志等級(jí)越低,打印的內(nèi)容越多,性能上越有損耗
client_min_messages = warning # values in order of decreasing detail:
# debug5
# debug4
# debug3
# debug2
# debug1
# log
# notice
# warning
# error
#寫(xiě)到數(shù)據(jù)庫(kù)日志文件中的消息的級(jí)別,建議warning即可,日志等級(jí)越低,打印的內(nèi)容越多,性能上越有損耗
log_min_messages = warning # values in order of decreasing detail:
# debug5
# debug4
# debug3
# debug2
# debug1
# info
# notice
# warning
# error
# log
# fatal
# panic
#是否記錄導(dǎo)致數(shù)據(jù)庫(kù)出現(xiàn)錯(cuò)誤的SQL語(yǔ)句,建議warning即可,日志等級(jí)越低,打印的內(nèi)容越多,性能上越有損耗
log_min_error_statement = error # values in order of decreasing detail:
# debug5
# debug4
# debug3
# debug2
# debug1
# info
# notice
# warning
# error
# log
# fatal
# panic (effectively off)

配置4:數(shù)據(jù)庫(kù)統(tǒng)計(jì)監(jiān)控

#log_statement_stats為on則會(huì)開(kāi)啟log_parser_stats,log_planner_stats,log_executor_stats這三個(gè)選項(xiàng),生產(chǎn)環(huán)境不建議開(kāi)啟,建議測(cè)試環(huán)境開(kāi)啟,用于定位問(wèn)題。
#log_parser_stats = off
#log_planner_stats = off
#log_executor_stats = off
#log_statement_stats = off 

配置5:慢sql記錄配置

#執(zhí)行sql時(shí)間為2s以上的sql都會(huì)被記錄下來(lái)
log_min_duration_statement = 2s

以上配置再修改完之后,均需要重啟pg生效。

到此這篇關(guān)于Postgresql的日志配置的文章就介紹到這了,更多相關(guān)Postgresql日志配置內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

您可能感興趣的文章:
  • PostgreSQL 性能優(yōu)化之服務(wù)器參數(shù)配置操作
  • postgresql 性能參數(shù)配置方式
  • PostgreSQL歸檔配置及自動(dòng)清理歸檔日志的操作
  • postgresql安裝及配置超詳細(xì)教程
  • PostgreSQL 邏輯復(fù)制 配置操作
  • 基于PostgreSQL pg_hba.conf 配置參數(shù)的使用說(shuō)明
  • PostgreSQL 自動(dòng)Vacuum配置方式

標(biāo)簽:寶雞 榆林 昭通 濮陽(yáng) 辛集 溫州 杭州 海西

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Postgresql的日志配置教程詳解》,本文關(guān)鍵詞  Postgresql,的,日志,配置,教程,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《Postgresql的日志配置教程詳解》相關(guān)的同類(lèi)信息!
  • 本頁(yè)收集關(guān)于Postgresql的日志配置教程詳解的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章