如何获取PostgreSQL数据库的最后访问/修改日期? [英] How to get last access/modification date of a PostgreSQL database?

查看:123
本文介绍了如何获取PostgreSQL数据库的最后访问/修改日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在开发服务器上,我想删除未使用的数据库。实现我需要知道数据库是否仍然由某人使用。

On development server I'd like to remove unused databases. To realize that I need to know if database is still used by someone or not.

有没有办法获得给定数据库,模式或表的最后访问或修改日期?

Is there a way to get last access or modification date of given database, schema or table?

推荐答案

您可以通过检查表文件的最后修改时间来完成。
在postgresql中,每个表对应一个或多个os文件,如下所示:

You can do it via checking last modification time of table's file. In postgresql,every table correspond one or more os files,like this:

select relfilenode from pg_class where relname = 'test';

relfilenode是表test的文件名。然后你可以在数据库目录。

the relfilenode is the file name of table "test".Then you could find the file in the database's directory.

在我的测试环境中:

cd /data/pgdata/base/18976

ls -l -t | head

最后一个命令表示列出按上次修改时间排序的所有文件。

the last command means listing all files ordered by last modification time.

这篇关于如何获取PostgreSQL数据库的最后访问/修改日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆