patternsqlModerate
PostgreSQL: Query for location of global tablespace?
Viewed 0 times
postgresqlglobaltablespacequeryforlocation
Problem
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.
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.
Solution
pg_default and pg_global locations are "hardcoded".pg_default lives in:select setting||'/base' from pg_settings where name='data_directory';and
pg_global lives in:select setting||'/global' from pg_settings where name='data_directory';src/backend/commands/tablespace.c says so:* 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/relfilenodePlease also note, that exposing location of data directory is a - not so terrible but still - security hole.
app01@postgres=> show data_directory;
ERROR: must be superuser to examine "data_directory"Code Snippets
select setting||'/base' from pg_settings where name='data_directory';select setting||'/global' from pg_settings where name='data_directory';* 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/relfilenodeapp01@postgres=> show data_directory;
ERROR: must be superuser to examine "data_directory"Context
StackExchange Database Administrators Q#9603, answer score: 14
Revisions (0)
No revisions yet.