--获取表记录更新时间(通过表磁盘存储文件时间) 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,filenode from pg_class c join pg_namespace ns on c.relnamespace=ns.oid and c.relname = tablename and 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_change from pg_ls_dir(tabledir) as filename where filename ~ ('^' || filenode || '([.]?[0-9]+)?$'); END; $func$;
备注:本方法相对于通过触发器实现方法有一定的时间延迟,通常在2到5分钟左右的时间,对实时性要求高的地方,不推荐使用该方法
转载于:https://www.cnblogs.com/mxly/p/9268922.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。