我有兴趣获取 Linux 操作系统中 PostgreSQL 表中可用的表、 View 、函数、数据/内容的物理位置。我有一个场景,PostgreSQL 可以安装在 SD 卡设备和硬盘中。如果我在 SD 中有表、 View 、函数和数据,我想获取它们的物理位置,并在我希望替换存储空间时合并/复制到我的硬盘中。我希望数据库的存储应该是纯文件架构。
另外,是否可以查看文件的内容?我的意思是,我可以访问它们吗?
最佳答案
Kevin 和 Mike 已经提供了在哪里可以找到数据目录的指针。对于文件系统中表的物理位置,使用:
SELECT pg_relation_filepath('my_table');
除非您确切地知道自己在做什么,否则不要直接弄乱文件。
数据库作为一个整体由PGDATA/base
中的一个子目录表示:
如果您使用表空间,它会变得更加复杂。阅读章节 Database File Layout in the manual 中的详细信息:
For each database in the cluster there is a subdirectory within PGDATA/base, named after the database's OID in
pg_database
. This subdirectory is the default location for the database's files; in particular, its system catalogs are stored there.
...
Each table and index is stored in a separate file. For ordinary relations, these files are named after the table or index's filenode number, which can be found in
pg_class.relfilenode
.
...
The
pg_relation_filepath()
function shows the entire path (relative to PGDATA) of any relation.
大胆强调我的。
The manual about the function pg_relation_filepath()
.
关于postgresql - 对象在 PostgreSQL 数据库中的物理位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10431635/