diff options
author | Magnus Hagander <magnus@hagander.net> | 2011-12-07 10:35:00 +0100 |
---|---|---|
committer | Magnus Hagander <magnus@hagander.net> | 2011-12-07 10:37:33 +0100 |
commit | 16d8e594acd96661267cb7897834f9cba51a2ffd (patch) | |
tree | 4ab54a17950270328b54550af91aae4e2c6e245f /src/backend/utils/adt/misc.c | |
parent | c6e3ac11b60ac4a8942ab964252d51c1c0bd8845 (diff) | |
download | postgresql-16d8e594acd96661267cb7897834f9cba51a2ffd.tar.gz postgresql-16d8e594acd96661267cb7897834f9cba51a2ffd.zip |
Remove spclocation field from pg_tablespace
Instead, add a function pg_tablespace_location(oid) used to return
the same information, and do this by reading the symbolic link.
Doing it this way makes it possible to relocate a tablespace when the
database is down by simply changing the symbolic link.
Diffstat (limited to 'src/backend/utils/adt/misc.c')
-rw-r--r-- | src/backend/utils/adt/misc.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/backend/utils/adt/misc.c b/src/backend/utils/adt/misc.c index 63ec6fd9d4e..4453e818c00 100644 --- a/src/backend/utils/adt/misc.c +++ b/src/backend/utils/adt/misc.c @@ -18,6 +18,7 @@ #include <signal.h> #include <dirent.h> #include <math.h> +#include <unistd.h> #include "catalog/catalog.h" #include "catalog/pg_tablespace.h" @@ -262,6 +263,44 @@ pg_tablespace_databases(PG_FUNCTION_ARGS) /* + * pg_tablespace_location - get location for a tablespace + */ +Datum +pg_tablespace_location(PG_FUNCTION_ARGS) +{ + Oid tablespaceOid = PG_GETARG_OID(0); + char sourcepath[MAXPGPATH]; + char targetpath[MAXPGPATH]; + int rllen; + + /* + * Return empty string for our two default tablespace + */ + if (tablespaceOid == DEFAULTTABLESPACE_OID || + tablespaceOid == GLOBALTABLESPACE_OID) + PG_RETURN_TEXT_P(cstring_to_text("")); + +#if defined(HAVE_READLINK) || defined(WIN32) + /* + * Find the location of the tablespace by reading the symbolic link that is + * in pg_tblspc/<oid>. + */ + snprintf(sourcepath, sizeof(sourcepath), "pg_tblspc/%u", tablespaceOid); + rllen =readlink(sourcepath, targetpath, sizeof(targetpath)); + if (rllen < 0 || rllen >= sizeof(targetpath)) + ereport(ERROR, + (errmsg("could not read symbolic link \"%s\": %m", sourcepath))); + targetpath[rllen] = '\0'; + + PG_RETURN_TEXT_P(cstring_to_text(targetpath)); +#else + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("tablespaces are not supported on this platform"))); +#endif +} + +/* * pg_sleep - delay for N seconds */ Datum |