Postgresql 日誌收集

來源:互聯網
上載者:User

標籤:none   常用   cto   跟蹤   相對路徑   trunc   pre   日誌配置   pos   

PG安裝完成後預設不會記錄日誌,必須修改對應的(${PGDATA}/postgresql.conf)配置才可以,這裡只介紹常用的日誌配置。

1.logging_collector = on/off ---- 是否將日誌重新導向至檔案中,預設是off(該配置修改後,需要重啟DB服務)

 

ps -ef | grep postgrespostgres 26167 1 1 09:55 ? 00:00:00 /usr/lib/postgresql/9.5/bin/postgres -D /var/lib/postgresql/9.5/main -c config_file=/etc/postgresql/9.5/main/postgresql.confpostgres 26169 26167 0 09:55 ? 00:00:00 postgres: checkpointer process postgres 26170 26167 0 09:55 ? 00:00:00 postgres: writer process postgres 26171 26167 0 09:55 ? 00:00:00 postgres: wal writer process postgres 26172 26167 0 09:55 ? 00:00:00 postgres: autovacuum launcher process postgres 26173 26167 0 09:55 ? 00:00:00 postgres: stats collector proces

 開啟後

ps -ef | grep postgrespostgres 25943 1 0 09:48 ? 00:00:00 /usr/lib/postgresql/9.5/bin/postgres -D /var/lib/postgresql/9.5/main -c config_file=/etc/postgresql/9.5/main/postgresql.confpostgres 25944 25943 0 09:48 ? 00:00:00 postgres: logger process postgres 25946 25943 0 09:48 ? 00:00:00 postgres: checkpointer process postgres 25947 25943 0 09:48 ? 00:00:00 postgres: writer process postgres 25948 25943 0 09:48 ? 00:00:00 postgres: wal writer process postgres 25949 25943 0 09:48 ? 00:00:00 postgres: autovacuum launcher process postgres 25950 25943 0 09:48 ? 00:00:00 postgres: stats collector process

 

2.log_directory = ‘pg_log‘ ---- 記錄檔目錄,預設是PGDATA的相對路徑,即PGDATA的相對路徑,即{PGDATA}/pg_log,也可以改為絕對路徑

預設為${PGDATA}/pg_log,即叢集目錄下,但是記錄檔可能會非常多,建議將日誌重新導向到其他目錄或分區。

將此配置修改為/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下

3.log_filename = ‘postgresql-%Y-%m-%d_%H%M%S.log‘ ---- 記錄檔命名形式,使用預設即可

4. log_rotation_age = 1d ---- 單個記錄檔的生存期,預設1天,在記錄檔大小沒有達到log_rotation_size時,一天只產生一個記錄檔

5. log_rotation_size = 10MB ---- 單個記錄檔的大小,如果時間沒有超過log_rotation_age,一個記錄檔最大隻能到10M,否則將新產生一個記錄檔。

6.log_truncate_on_rotation = off ---- 當記錄檔已存在時,該配置如果為off,新產生的日誌將在檔案尾部追加,如果為on,則會覆蓋原來的日誌。

7.log_lock_waits = off ---- 控制當一個會話等待時間超過deadlock_timeout而被鎖時是否產生一個日誌資訊。在判斷一個鎖等待是否會影響效能時是有用的,預設是off。

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

9.log_duration = off ---- 記錄每條SQL語句執行完成消耗的時間,將此配置設定為on,用於統計哪些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也能夠統計SQL語句及耗時,但是SQL語句和耗時統計結果可能相差很多行,或在不同的檔案中,但是log_min_duration_statement會將SQL語句和耗時在同一行記錄,更方便閱讀。

11.log_connections = off ----是否記錄串連日誌

12.log_disconnections = off ---- 是否記錄串連斷開日誌

13.log_line_prefix = ‘%m %p %u %d %r ‘ ---- 日誌輸出格式(%m,%p實際意義設定檔中有解釋),可根據自己需要設定(能夠記錄時間,使用者名稱稱,資料庫名稱,用戶端IP和連接埠,方便定位問題)

 

14.log_timezone = ‘Asia/Shanghai‘ ---- 日誌時區,最好和伺服器設定同一個時區,方便問題定位

伺服器時區設定

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

Postgresql 日誌收集

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.