PostgreSQL: Query for location of global tablespace?
2015-08-05 00:08
543 查看
Q:
I have been trying to make our database clients pro-active about not filling up the partition on which the database they are using resides.
As all our clients are on the same host as the database manager, it should be easy enough for user-created tablespaces; the client can look up the filesystem path for the tablespace (in spclocation), and use OS calls to check how much available space is available:
I can't see how, from the client, to get the path to where the global tablespace is stored; an empty string is returned for it in the above query.
Unfortunately, we have many legacy systems in the field using a particular database created in the global tablespace, and it would be a monumental effort to get it moved into a user-created tablespace.
Hopefully I'm just missing something really simple.
A:
pg_default and pg_global locations are "hardcoded".
pg_default lives in:
and pg_global lives in:
[align=left] [/align]
[align=left] src/backend/commands/tablespace.c says so:[/align]
[align=left] [/align]
[align=left] * There are two tablespaces created at initdb time : pg_global ( for shared[/align]
[align=left] * tables ) and pg_default (for everything else). For backwards compatibility[/align]
[align=left] * and to remain functional on platforms without symlinks , these tablespaces[/align]
[align=left] * are accessed specially : they are respectively[/align]
[align=left] * $PGDATA / global/ relfilenode[/align]
[align=left] * $PGDATA / base/ dboid /relfilenode[/align]
[align=left] [/align]
[align=left] [/align]
[align=left] [/align]
[align=left]下面是代码中详细的说明:[/align]
[align=left] [/align]
[align=left] * Tablespaces in PostgreSQL are designed to allow users to determine
* where the data file(s) for a given database object reside on the file
* system.
*
* A tablespace represents a directory on the file system. At tablespace
* creation time, the directory must be empty. To simplify things and
* remove the possibility of having file name conflicts, we isolate
* files within a tablespace into database-specific subdirectories.
*
* To support file access via the information given in RelFileNode, we
* maintain a symbolic-link map in $PGDATA/pg_tblspc. The symlinks are
* named by tablespace OIDs and point to the actual tablespace directories.
* There is also a per-cluster version directory in each tablespace.
* Thus the full path to an arbitrary file is
* $PGDATA/pg_tblspc/spcoid/PG_MAJORVER_CATVER/dboid/relfilenode
* e.g.
* $PGDATA/pg_tblspc/20981/PG_9.0_201002161/719849/83292814
*
* There are two tablespaces created at initdb time: pg_global (for shared
* tables) and pg_default (for everything else). For backwards compatibility
* and to remain functional on platforms without symlinks, these tablespaces
* are accessed specially: they are respectively
* $PGDATA/global/relfilenode
* $PGDATA/base/dboid/relfilenode
*
* To allow CREATE DATABASE to give a new database a default tablespace
* that's different from the template database's default, we make the
* provision that a zero in pg_class.reltablespace means the database's
* default tablespace. Without this, CREATE DATABASE would have to go in
* and munge the system catalogs of the new database.
*
[/align]
[align=left] [/align]
[align=left] [/align]
[align=left]参考:[/align]
[align=left]http://dba.stackexchange.com/questions/9603/postgresql-query-for-location-of-global-tablespace[/align]
[align=left]src /backend/commands/tablespace.c[/align]
I have been trying to make our database clients pro-active about not filling up the partition on which the database they are using resides.
As all our clients are on the same host as the database manager, it should be easy enough for user-created tablespaces; the client can look up the filesystem path for the tablespace (in spclocation), and use OS calls to check how much available space is available:
adb=> select * from pg_tablespace; spcname | spcowner | spclocation | spcacl ------------+----------+-------------------+--------------------- pg_default | 10 | | pg_global | 10 | | adb | 2033793 | /database /adb | {adb =C/ adb}
I can't see how, from the client, to get the path to where the global tablespace is stored; an empty string is returned for it in the above query.
Unfortunately, we have many legacy systems in the field using a particular database created in the global tablespace, and it would be a monumental effort to get it moved into a user-created tablespace.
Hopefully I'm just missing something really simple.
A:
pg_default and pg_global locations are "hardcoded".
pg_default lives in:
test=# select setting||'/base' from pg_settings where name='data_directory';
and pg_global lives in:
test=# select setting||'/global' from pg_settings where name='data_directory';
[align=left] [/align]
[align=left] src/backend/commands/tablespace.c says so:[/align]
[align=left] [/align]
[align=left] * There are two tablespaces created at initdb time : pg_global ( for shared[/align]
[align=left] * tables ) and pg_default (for everything else). For backwards compatibility[/align]
[align=left] * and to remain functional on platforms without symlinks , these tablespaces[/align]
[align=left] * are accessed specially : they are respectively[/align]
[align=left] * $PGDATA / global/ relfilenode[/align]
[align=left] * $PGDATA / base/ dboid /relfilenode[/align]
[align=left] [/align]
[align=left] [/align]
[align=left] [/align]
[align=left]下面是代码中详细的说明:[/align]
[align=left] [/align]
[align=left] * Tablespaces in PostgreSQL are designed to allow users to determine
* where the data file(s) for a given database object reside on the file
* system.
*
* A tablespace represents a directory on the file system. At tablespace
* creation time, the directory must be empty. To simplify things and
* remove the possibility of having file name conflicts, we isolate
* files within a tablespace into database-specific subdirectories.
*
* To support file access via the information given in RelFileNode, we
* maintain a symbolic-link map in $PGDATA/pg_tblspc. The symlinks are
* named by tablespace OIDs and point to the actual tablespace directories.
* There is also a per-cluster version directory in each tablespace.
* Thus the full path to an arbitrary file is
* $PGDATA/pg_tblspc/spcoid/PG_MAJORVER_CATVER/dboid/relfilenode
* e.g.
* $PGDATA/pg_tblspc/20981/PG_9.0_201002161/719849/83292814
*
* There are two tablespaces created at initdb time: pg_global (for shared
* tables) and pg_default (for everything else). For backwards compatibility
* and to remain functional on platforms without symlinks, these tablespaces
* are accessed specially: they are respectively
* $PGDATA/global/relfilenode
* $PGDATA/base/dboid/relfilenode
*
* To allow CREATE DATABASE to give a new database a default tablespace
* that's different from the template database's default, we make the
* provision that a zero in pg_class.reltablespace means the database's
* default tablespace. Without this, CREATE DATABASE would have to go in
* and munge the system catalogs of the new database.
*
[/align]
[align=left] [/align]
[align=left] [/align]
[align=left]参考:[/align]
[align=left]http://dba.stackexchange.com/questions/9603/postgresql-query-for-location-of-global-tablespace[/align]
[align=left]src /backend/commands/tablespace.c[/align]
相关文章推荐
- 【HDU4632】【Palindrome subsequence】
- iOS UIImageView 添加 UITapGestureRecognizer 事件
- install build essential
- UEditor的配置和使用(单独图片与文件上传)
- OC_NSNumer和NSValue
- N-Queens II
- 解决在使用request得到属性的空指针问题
- 4种线程中访问Ui界面的方法
- 输入一个字符串,如果第一个字符是大写并且其他字符不是大写,那么输出true,否则输出false。
- UI 04 代理设计模式
- iOS开发UI基础—手写控件,frame,center和bounds属性
- N-Queens
- UI04_UIDelegate
- VistualStudio 2005 设置PowerBuilder12.5 PBNI编绎命令行。
- UI 04 target...action 设计模式
- iOS开发——UI进阶篇(十六)Quartz2D实战小例子
- HDU1.2.6 Buildings
- UVA1152 4Values whose Sum is 0
- HDU 5301 Buildings
- DPDK 的 uio 以及 PMD 机制的实现