postgresql - 对象在 PostgreSQL 数据库中的物理位置?

标签 postgresql database-design data-storage

我有兴趣获取 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/

相关文章:

ruby-on-rails - Postgresql 和 ActiveRecord 其中 : Regex matching

sql - postgres 中 SQL 以外的语言

php - 将用户评论存储在数据库中

database - 我们如何优化oracle数据库?

database - 在流行的 BaaS 中使用自己的数据存储的方法

database - Tokyo Cabinet 的最大尺寸是多少?

node.js - Redis 使用 node.js 占用内存

django - 在 Postgres 中使用 jsonb(与 Django 的 JSONField 一起使用)唯一索引实际上做了什么?

sql - 在限定时间内获得 COUNT() 结果

database - 这是对数据库规范化的一次很好的尝试吗?