Postgresql:query for location of global tablespace?

Source: Internet
Author: User

Q:

I have been trying to make we database clients pro-active about not filling up the partition on which the database they a Re using resides.

As all of our clients is on the same host as the database manager, it should is 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 Availab Le Space is available:
adb= Select *  fromPg_tablespace; Spcname|Spcowner|Spclocation|Spcacl------------+----------+-------------------+---------------------Pg_default|       Ten |                   |Pg_global|       Ten |                   |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 was returned for it in the above query.

Unfortunately, we have many legacy systems on the field using a particular database created in the global Tablespace, and It would is 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 where name='data_directory';
and Pg_global lives in: 
Test=Select Setting| | ' /global '  from where name='data_directory'
src/backend/commands/tablespace.cSays so:   *There is tablespaces created at Initdb time  :Pg_global ( forshared   *Tables )and Pg_default ( foreverything Else ).For backwards compatibility   *And to remain functional on platforms without symlinks ,these tablespaces   *is accessed specially :they is respectively   *$PGDATA /Global /Relfilenode   *$PGDATA /Base /dboid  /Relfilenode   here is the detailed description in the code:
 * Tablespaces in PostgreSQL is 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 is
* Named by Tablespace OIDs and point to the actual tablespace directories.
* There is also a Per-cluster version directory of each tablespace.
* Thus the full path to a 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 is 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
* is accessed Specially:they is 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 and we make the
* Provision that a zero in pg_class.reltablespace means the database ' s
* Default tablespace. Without this, CREATE DATABASE would has to go
* and munge the system catalogs of the new database.
*
Reference:Http://dba.stackexchange.com/questions/9603/postgresql-query-for-location-of-global-tablespacesrc/backend/commands/tablespace.c

Postgresql:query for location of global tablespace?

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.