日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

centos 6.8 + postgresql 9.6 + file_fdw

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

使用 file_fdw 讀取 pglog,以便實時監控日志。

創建 extension

CREATE EXTENSION file_fdw;

創建 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 ;

創建外部表

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 ;

可以和德哥一樣寫個存儲過程來判斷和創建。

參考:
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

轉載于:https://www.cnblogs.com/ctypyb2002/p/9793135.html

總結

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

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。