PostgreSQL Source Code git master
pg_tablespace.h File Reference
#include "catalog/genbki.h"
#include "catalog/pg_tablespace_d.h"
Include dependency graph for pg_tablespace.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef FormData_pg_tablespaceForm_pg_tablespace
 

Functions

 CATALOG (pg_tablespace, 1213, TableSpaceRelationId) BKI_SHARED_RELATION
 
 DECLARE_TOAST_WITH_MACRO (pg_tablespace, 4185, 4186, PgTablespaceToastTable, PgTablespaceToastIndex)
 
 DECLARE_UNIQUE_INDEX_PKEY (pg_tablespace_oid_index, 2697, TablespaceOidIndexId, pg_tablespace, btree(oid oid_ops))
 
 DECLARE_UNIQUE_INDEX (pg_tablespace_spcname_index, 2698, TablespaceNameIndexId, pg_tablespace, btree(spcname name_ops))
 
 MAKE_SYSCACHE (TABLESPACEOID, pg_tablespace_oid_index, 4)
 
char * get_tablespace_location (Oid tablespaceOid)
 

Variables

 FormData_pg_tablespace
 

Typedef Documentation

◆ Form_pg_tablespace

Definition at line 48 of file pg_tablespace.h.

Function Documentation

◆ CATALOG()

CATALOG ( pg_tablespace  ,
1213  ,
TableSpaceRelationId   
)

Definition at line 29 of file pg_tablespace.h.

30{
31 Oid oid; /* oid */
32 NameData spcname; /* tablespace name */
33
34 /* owner of tablespace */
35 Oid spcowner BKI_DEFAULT(POSTGRES) BKI_LOOKUP(pg_authid);
36
37#ifdef CATALOG_VARLEN /* variable-length fields start here */
38 aclitem spcacl[1]; /* access permissions */
39 text spcoptions[1]; /* per-tablespace options */
40#endif
#define BKI_LOOKUP(catalog)
Definition: genbki.h:46
#define BKI_DEFAULT(value)
Definition: genbki.h:35
FormData_pg_tablespace
Definition: pg_tablespace.h:41
unsigned int Oid
Definition: postgres_ext.h:32
Definition: c.h:749
Definition: c.h:695

References BKI_DEFAULT, and BKI_LOOKUP.

◆ DECLARE_TOAST_WITH_MACRO()

DECLARE_TOAST_WITH_MACRO ( pg_tablespace  ,
4185  ,
4186  ,
PgTablespaceToastTable  ,
PgTablespaceToastIndex   
)

◆ DECLARE_UNIQUE_INDEX()

DECLARE_UNIQUE_INDEX ( pg_tablespace_spcname_index  ,
2698  ,
TablespaceNameIndexId  ,
pg_tablespace  ,
btree(spcname name_ops)   
)

◆ DECLARE_UNIQUE_INDEX_PKEY()

DECLARE_UNIQUE_INDEX_PKEY ( pg_tablespace_oid_index  ,
2697  ,
TablespaceOidIndexId  ,
pg_tablespace  ,
btree(oid oid_ops)   
)

◆ get_tablespace_location()

char * get_tablespace_location ( Oid  tablespaceOid)

Definition at line 30 of file pg_tablespace.c.

31{
32 char sourcepath[MAXPGPATH];
33 char targetpath[MAXPGPATH];
34 int rllen;
35 struct stat st;
36
37 /*
38 * It's useful to apply this to pg_class.reltablespace, wherein zero means
39 * "the database's default tablespace". So, rather than throwing an error
40 * for zero, we choose to assume that's what is meant.
41 */
42 if (tablespaceOid == InvalidOid)
43 tablespaceOid = MyDatabaseTableSpace;
44
45 /*
46 * Return empty string for the cluster's default tablespaces
47 */
48 if (tablespaceOid == DEFAULTTABLESPACE_OID ||
49 tablespaceOid == GLOBALTABLESPACE_OID)
50 return pstrdup("");
51
52 /*
53 * Find the location of the tablespace by reading the symbolic link that
54 * is in pg_tblspc/<oid>.
55 */
56 snprintf(sourcepath, sizeof(sourcepath), "%s/%u", PG_TBLSPC_DIR, tablespaceOid);
57
58 /*
59 * Before reading the link, check if the source path is a link or a
60 * junction point. Note that a directory is possible for a tablespace
61 * created with allow_in_place_tablespaces enabled. If a directory is
62 * found, a relative path to the data directory is returned.
63 */
64 if (lstat(sourcepath, &st) < 0)
67 errmsg("could not stat file \"%s\": %m",
68 sourcepath));
69
70 if (!S_ISLNK(st.st_mode))
71 return pstrdup(sourcepath);
72
73 /*
74 * In presence of a link or a junction point, return the path pointed to.
75 */
76 rllen = readlink(sourcepath, targetpath, sizeof(targetpath));
77 if (rllen < 0)
80 errmsg("could not read symbolic link \"%s\": %m",
81 sourcepath));
82 if (rllen >= sizeof(targetpath))
84 errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
85 errmsg("symbolic link \"%s\" target is too long",
86 sourcepath));
87 targetpath[rllen] = '\0';
88
89 return pstrdup(targetpath);
90}
int errcode_for_file_access(void)
Definition: elog.c:886
int errcode(int sqlerrcode)
Definition: elog.c:863
int errmsg(const char *fmt,...)
Definition: elog.c:1080
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:150
Oid MyDatabaseTableSpace
Definition: globals.c:96
char * pstrdup(const char *in)
Definition: mcxt.c:1759
#define MAXPGPATH
#define snprintf
Definition: port.h:260
#define InvalidOid
Definition: postgres_ext.h:37
#define PG_TBLSPC_DIR
Definition: relpath.h:41
#define lstat(path, sb)
Definition: win32_port.h:275
#define S_ISLNK(m)
Definition: win32_port.h:334
#define readlink(path, buf, size)
Definition: win32_port.h:226

References ereport, errcode(), errcode_for_file_access(), errmsg(), ERROR, InvalidOid, lstat, MAXPGPATH, MyDatabaseTableSpace, PG_TBLSPC_DIR, pstrdup(), readlink, S_ISLNK, snprintf, and stat::st_mode.

Referenced by pg_tablespace_location().

◆ MAKE_SYSCACHE()

MAKE_SYSCACHE ( TABLESPACEOID  ,
pg_tablespace_oid_index  ,
 
)

Variable Documentation

◆ FormData_pg_tablespace

FormData_pg_tablespace

Definition at line 41 of file pg_tablespace.h.