postgresql怎么查询每天归档的日志量,有什么方便的sql吗?
归档每天产生一个日志文件夹,进入指定归档目录,执行 du -sh 查看当天归档量。
评论
有用 0用pg_stat_file去分析下wal日志目录,例如:
with tmp_file as (
select to_char(date_trunc('day',(pg_stat_file(file)).modification),'yyyymmdd') as day_id,
date_part('hour',(pg_stat_file(t1.file)).modification) as last_update_time,
date_part('minute',(pg_stat_file(t1.file)).modification) as last_update_per_min
from (select dir||'/'||pg_ls_dir(t0.dir) as file,
pg_ls_dir(t0.dir) as file_ls
from ( select setting||'/pg_wal' as dir from pg_settings where name='data_directory'
) t0
) t1
where 1=1 and t1.file_ls not in ('archive_status','.history')
order by (pg_stat_file(file)).modification desc
)
select day_id as 日期,
last_update_time as 小时,
sum(case when last_update_per_min >=0 and last_update_per_min <=10 then 1 else 0 end) as 第0_10分钟,
sum(case when last_update_per_min >10 and last_update_per_min <=20 then 1 else 0 end) as 第10_20分钟,
sum(case when last_update_per_min >20 and last_update_per_min <=30 then 1 else 0 end) as 第20_30分钟,
sum(case when last_update_per_min >30 and last_update_per_min <=40 then 1 else 0 end) as 第30_40分钟,
sum(case when last_update_per_min >40 and last_update_per_min <=50 then 1 else 0 end) as 第40_50分钟,
sum(case when last_update_per_min >50 and last_update_per_min <=60 then 1 else 0 end) as 第50_60分钟
from tmp_file tf
where 1=1
group by day_id,last_update_time
order by day_id,last_update_time desc;
评论
有用 2
墨值悬赏


