mirror of
https://github.com/postgres/postgres.git
synced 2025-06-11 20:28:21 +03:00
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.
This commit is contained in:
@ -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"
|
||||
@ -261,6 +262,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
|
||||
*/
|
||||
|
Reference in New Issue
Block a user