pg确定一张表最后被使用的时间
2017-03-28 09:34
204 查看
create or replace function table_file_access_info(IN schemaname text,IN tablename text,OUT last_access timestamp with time zone,OUT last_change timestamp with time zone) LANGUAGE plpgsql AS $func$DECLARE tabledir text; filenode text;BEGIN SELECT regexp_replace(current_setting('data_directory') || '/' || pg_relation_filepath(c.oid), pg_relation_filenode(c.oid) || '$',''),pg_relation_filenode(c.oid)INTO tabledir,filenodefrom pg_class cjoin pg_namespace nson c.relnamespace=ns.oidand c.relname=tablenameand ns.nspname=schemaname;raise notice 'tabledir:% - filenode : %',tabledir,filenode;select max((pg_stat_file(tabledir || filename)).access), max((pg_stat_file(tabledir || filename)).modification) INTO last_access, last_changefrom pg_ls_dir(tabledir) as filenamewhere filename ~ ('^' || filenode || '([.]?[0-9]+)?$');END;$func$;
调用该函数:select table_file_access_info('public','test'); --大概时间输出示例:
postgres=# select table_file_access_info('public','test');
NOTICE: tabledir:/home/postgres/datalm/base/13241/ - filenode : 16392
table_file_access_info
-----------------------------------------------------
("2017-03-23 17:26:02+08","2017-03-23 17:35:16+08")
(1 row)
postgres=#
调用该函数:select table_file_access_info('public','test'); --大概时间输出示例:
postgres=# select table_file_access_info('public','test');
NOTICE: tabledir:/home/postgres/datalm/base/13241/ - filenode : 16392
table_file_access_info
-----------------------------------------------------
("2017-03-23 17:26:02+08","2017-03-23 17:35:16+08")
(1 row)
postgres=#
相关文章推荐
- pg确定一张表最后被使用的时间
- 关于何时使用实体标签ETag和最后修改时间(Last-modified)的规则
- Solr 的DIH组件 使用delta_import时 父子关系的entity 最后修改时间问题
- Linux使用find查找最后修改时间超过三天的文件并移动到指定目录(附:find找出文件并清空)
- vim配置技巧——在vim中使用autocmd命令在保存文件时自动插入最后修改日期和时间
- Mysql update语句赋值嵌套select,更新和查询同一张表,必须取别名;用例:更新指定游戏服务器最后启动记录的结束时间
- MySQL中日期类型数据的使用:如何让字段保存记录的创建时间和最后修改时间
- 使用svn log确定分支创建的时间点
- Android 优化电池使用时间——确定和监控基座对接状态和类型
- 确定使用多张网卡中的一张上网
- “日期和时间->自动确定日期和时间->使用网络提供时间”功能是怎样实现的?
- 近几天使用到多张表合成一张表、时间转化笔记。
- 查看mysql各数据库使用大小以及库中每个表最后修改时间
- Delphi 使用 IDHttp 获取文件最后修改时间
- BPFP系列:优化电池使用时间:确定和监控基座对接状态和类型
- BPFP系列:优化电池使用时间:确定和监控网络连接状态
- 【案例】SVN下载时如何使用“使用配置库最后提交时间”
- PG的时间函数使用整理如下
- 根据当前时间来确定上个月的最后一天
- 创建一张表,记录电话呼叫员的工作流水,记录呼叫员编 号、对方号码、通话开始时间、通话结束时间。建表、插数 据等最后都自己写SQL语句。