亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 5933 | 回復: 2
打印 上一主題 下一主題

pg的csv日志的格式有沒有詳細的介紹 [復制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2015-02-09 15:23 |只看該作者 |倒序瀏覽
把log_destination參數(shù)改成csv后,每段打印出來的內(nèi)容都代表什么意思,這個有沒有一個說明的地方?

論壇徽章:
4
丑牛
日期:2014-09-15 09:28:12雙子座
日期:2014-12-19 17:01:192015年辭舊歲徽章
日期:2015-03-03 16:54:15數(shù)據(jù)庫技術(shù)版塊每日發(fā)帖之星
日期:2016-06-28 06:20:00
2 [報告]
發(fā)表于 2015-02-13 11:59 |只看該作者
本帖最后由 tanfeng3 于 2015-02-13 12:00 編輯

提示我沒權(quán)限發(fā) url 鏈接: 俺把 blog 里內(nèi)容貼下來:中間有個日志表,就是 csv 日志文件的說明。

         像其它數(shù)據(jù)庫一樣,PostgreSQL也有自己的日志系統(tǒng),postgresql 日志方面有非常全
面的設置參數(shù),這篇不準備仔細的介紹PG的日志參數(shù),只介紹日志分析的一種方法,即可以將
日志文件內(nèi)容導入到數(shù)據(jù)庫表里,便于分析日志。

--日志文件目錄  
   日志的目錄可以通過參數(shù)  log_directory 來設置,下面是我的參數(shù)設置。
   log_directory = '/var/applog/pg_log'
   
[postgres@pg_log]$ ll /var/applog/pg_log   
-rw------- 1 postgres postgres 4.8M Mar 14 23:57 postgresql-2011-03-14_000000.csv
-rw------- 1 postgres postgres    0 Mar 14 00:00 postgresql-2011-03-14_000000.log
-rw------- 1 postgres postgres 294K Mar 15 15:10 postgresql-2011-03-15_000000.csv
-rw------- 1 postgres postgres    0 Mar 15 00:00 postgresql-2011-03-15_000000.log

--CSV日志文件內(nèi)容
2011-03-15 00:07:03.513 CST,"wapportal","wapportal_216",4137,"172.16.3.43:59356",4d7e361f.1029,3,"idle",2011-03-14 23:37:03 CST,,0,LOG,00000,"disconnection: session time: 0:30:00.086 user=wapportal database=wapportal_216 host=172.16.3.43 port=59356",,,,,,,,,""
2011-03-15 00:07:03.514 CST,,,5173,"",4d7e3d27.1435,1,"",2011-03-15 00:07:03 CST,,0,LOG,00000,"connection received: host=172.16.3.43 port=51135",,,,,,,,,""

   上面兩條是 postgresql-2011-03-15_000000.csv 日志文件的部分內(nèi)容 ,由于日志文件的可讀性
較差,于是可以通過下面方法將CSV日志導入到數(shù)據(jù)庫表里。詳細如下


將CSV日志導入數(shù)據(jù)庫表里  
1--調(diào)整參數(shù)
log_destination = 'csvlog'
logging_collector = on

    這兩個參數(shù)修改后,PG SERVER 需要重啟。

2--創(chuàng)建日志記錄表
CREATE TABLE postgres_log
(
  log_time timestamp(3) with time zone,
  user_name text,
  database_name text,
  process_id integer,
  connection_from text,
  session_id text,
  session_line_num bigint,
  command_tag text,
  session_start_time timestamp with time zone,
  virtual_transaction_id text,
  transaction_id bigint,
  error_severity text,
  sql_state_code text,
  message text,
  detail text,
  hint text,
  internal_query text,
  internal_query_pos integer,
  context text,
  query text,
  query_pos integer,
  location text,
  application_name text,
  PRIMARY KEY (session_id, session_line_num)
);

NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "postgres_log_pkey" for table "postgres_log"
CREATE TABLE;

    備注:創(chuàng)建日志表 postgres_log 用來保存 CSV日志數(shù)據(jù)。

3--導入操作系統(tǒng) csv 日志到表 postgres_log 表
skytf=# copy skytf.postgres_log from '/var/applog/pg_log/postgresql-2011-03-14_000000.csv' with csv;
COPY 26031

skytf=# copy skytf.postgres_log from '/var/applog/pg_log/postgresql-2011-03-15_000000.csv' with csv;
COPY 1297

      備注:文件形式導入導出數(shù)據(jù)需要以超級用戶 postgres 連接到目標庫。

4--常用日志分析sql
skytf=# select min(log_time),max(log_time) from skytf.postgres_log;
            min             |            max            
----------------------------+----------------------------
2011-03-14 14:04:07.275+08 | 2011-03-16 05:04:34.427+08
(1 row)

skytf=> select log_time,database_name,user_name,application_name,message from postgres_log where message like '%duration%';
          log_time          | database_name | user_name | application_name |                                                    mess
age                                                   
----------------------------+---------------+-----------+------------------+--------------------------------------------------------
-------------------------------------------------------
2011-03-15 00:23:38.957+08 | db_lbs        | lbs       |                  | duration: 1297.440 ms  execute <unnamed>:    SELECT cit
yname,province,the_geom as the_geom FROM china_city  
.......
   
       為了顯示方便,上面只取一條記錄。

5--總結(jié)
        當數(shù)據(jù)庫出現(xiàn)異常需要詳細分析日志文件時,上面的方法提供了一個非常有效的方式,
將數(shù)據(jù)庫日志導入到表里,能夠更準確,方便地分析數(shù)據(jù)庫日志。

論壇徽章:
1
2015年迎新春徽章
日期:2015-03-04 09:58:11
3 [報告]
發(fā)表于 2015-07-08 17:11 |只看該作者
好贊,學習了。
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP