日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

centos 6.8 + postgresql 9.6 + file_fdw

發(fā)布時間:2025/5/22 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 centos 6.8 + postgresql 9.6 + file_fdw 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

使用 file_fdw 讀取 pglog,以便實時監(jiān)控日志。

創(chuàng)建 extension

CREATE EXTENSION file_fdw;

創(chuàng)建 server

CREATE SERVER file_fdw_server FOREIGN DATA WRAPPER file_fdw;

獲取最新日志文件

select t00.* from (select t1.file,t1.file_ls,(pg_stat_file(t1.file)).modification as last_update_time,round( ((pg_stat_file(t1.file)).size)/1024/1024*1.0,1) as log_size_mbfrom (select dir||'/'||pg_ls_dir(t0.dir) as file,pg_ls_dir(t0.dir) as file_lsfrom ( select setting as dir from pg_settings where name='log_directory') t0) t1 where 1=1order by (pg_stat_file(file)).modification desc) t00 where 1=1and t00.file_ls like '%.csv' limit 1 ;

創(chuàng)建外部表

select name,setting from pg_settings where name ~ 'log';CREATE FOREIGN TABLE pglog_current ( log_time timestamp(3) without 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) server file_fdw_server options(filename '/var/log/postgresql/postgresql-2017-08-29.csv',format 'csv') ;

查詢外部表

select count(1) from pglog_current where 1=1 ;select plc.* from pglog_current plc where 1=1 order by plc.log_time ;

可以和德哥一樣寫個存儲過程來判斷和創(chuàng)建。

參考:
http://blog.163.com/digoal@126/blog/static/16387704020121023105322442/
https://www.postgresql.org/docs/current/static/sql-createforeigntable.html
https://www.postgresql.org/docs/current/static/file-fdw.html

轉(zhuǎn)載于:https://www.cnblogs.com/ctypyb2002/p/9793135.html

總結(jié)

以上是生活随笔為你收集整理的centos 6.8 + postgresql 9.6 + file_fdw的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。