剛開始學習postgres的時候,可能對PostgreSQL中的日誌概念比較模糊,到底有多少種日誌,哪些日誌是能刪除的,各自又記錄什麼樣的功能。 linux
PostgreSQL中有三種日誌,pg_log,pg_xlog和pg_clog。
一.安裝路徑
這三種數據庫後二者通常的安裝路徑是$PGDATA/下面的文件夾下,前者默認路徑是$PGDATA/pg_log,一般可本身定義路徑和文件名 sql
[postgres@testdb ~]$ cd $PGDATA [postgres@testdb pgdata]$ ls -l total 88 drwx------ 10 postgres kenyon 4096 Dec 12 15:58 base drwx------ 2 postgres kenyon 4096 Dec 13 10:13 global drwx------ 2 postgres kenyon 4096 Jun 21 2012 pg_clog -rw------- 1 postgres kenyon 4739 Aug 10 09:31 pg_hba.conf -rw------- 1 postgres kenyon 1636 Jun 21 2012 pg_ident.conf drwx------ 4 postgres kenyon 4096 Jun 21 2012 pg_multixact drwx------ 2 postgres kenyon 4096 Dec 12 18:24 pg_notify drwx------ 2 postgres kenyon 4096 Jun 21 2012 pg_serial drwx------ 2 postgres kenyon 4096 Dec 21 20:17 pg_stat_tmp drwx------ 2 postgres kenyon 4096 Dec 14 15:01 pg_subtrans drwx------ 2 postgres kenyon 4096 Jun 21 2012 pg_tblspc drwx------ 2 postgres kenyon 4096 Jun 21 2012 pg_twophase -rw------- 1 postgres kenyon 4 Jun 21 2012 PG_VERSION drwx------ 3 postgres kenyon 4096 Dec 13 15:20 pg_xlog -rw------- 1 postgres kenyon 19439 Dec 13 18:23 postgresql.conf -rw------- 1 postgres kenyon 52 Dec 12 18:24 postmaster.opts -rw------- 1 postgres kenyon 73 Dec 12 18:24 postmaster.pid [postgres@testdb pgdata]$more postgresql.conf log_destination = 'csvlog' logging_collector = on log_directory = '/home/postgres/pg_log' log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log' |
[postgres@testdb pg_log]$ ll total 3996 -rw------- 1 postgres kenyon 15632 Dec 12 21:59 postgresql-2012-12-12_182439.csv -rw------- 1 postgres kenyon 0 Dec 12 18:24 postgresql-2012-12-12_182439.log -rw------- 1 postgres kenyon 3990717 Dec 13 23:48 postgresql-2012-12-13_000000.csv -rw------- 1 postgres kenyon 0 Dec 13 00:00 postgresql-2012-12-13_000000.log -rw------- 1 postgres kenyon 27518 Dec 14 17:46 postgresql-2012-12-14_000000.csv -rw------- 1 postgres kenyon 0 Dec 14 00:00 postgresql-2012-12-14_000000.log -rw------- 1 postgres kenyon 0 Dec 15 00:00 postgresql-2012-12-15_000000.csv -rw------- 1 postgres kenyon 0 Dec 15 00:00 postgresql-2012-12-15_000000.log -rw------- 1 postgres kenyon 0 Dec 16 00:00 postgresql-2012-12-16_000000.csv -rw------- 1 postgres kenyon 0 Dec 16 00:00 postgresql-2012-12-16_000000.log -rw------- 1 postgres kenyon 29713 Dec 17 21:07 postgresql-2012-12-17_000000.csv -rw------- 1 postgres kenyon 0 Dec 17 00:00 postgresql-2012-12-17_000000.log -rw------- 1 postgres kenyon 900 Dec 18 20:49 postgresql-2012-12-18_000000.csv -rw------- 1 postgres kenyon 0 Dec 18 00:00 postgresql-2012-12-18_000000.log -rw------- 1 postgres kenyon 4607 Dec 19 18:55 postgresql-2012-12-19_000000.csv -rw------- 1 postgres kenyon 0 Dec 19 00:00 postgresql-2012-12-19_000000.log -rw------- 1 postgres kenyon 1573 Dec 20 20:38 postgresql-2012-12-20_000000.csv -rw------- 1 postgres kenyon 0 Dec 20 00:00 postgresql-2012-12-20_000000.log -rw------- 1 postgres kenyon 0 Dec 21 00:00 postgresql-2012-12-21_000000.csv -rw------- 1 postgres kenyon 0 Dec 21 00:00 postgresql-2012-12-21_000000.log |
總結:
pg_log記錄各類Error信息,以及服務器與DB的狀態信息,可由用戶隨意更新刪除
pg_xlog與pg_clog記錄數據庫的事務信息,不得隨意刪除更新,作物理備份時要記得備份着兩個日誌。
參考轉譯:
http://it.toolbox.com/blogs/database-soup/pg_log-pg_xlog-and-pg_clog-45611 數據庫