1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-14 18:42:34 +03:00

Define PG_TBLSPC_DIR for path pg_tblspc/ in data folder

Similarly to 2065ddf5e3, this introduces a define for "pg_tblspc".
This makes the style more consistent with the existing PG_STAT_TMP_DIR,
for example.

There is a difference with the other cases with the introduction of
PG_TBLSPC_DIR_SLASH, required in two places for recovery and backups.

Author: Bertrand Drouvot
Reviewed-by: Ashutosh Bapat, Álvaro Herrera, Yugo Nagata, Michael
Paquier
Discussion: https://postgr.es/m/ZryVvjqS9SnV1GPP@ip-10-97-1-34.eu-west-3.compute.internal
This commit is contained in:
Michael Paquier
2024-09-03 09:11:54 +09:00
parent 94eec79633
commit c7cd2d6ed0
18 changed files with 88 additions and 70 deletions

View File

@ -8944,10 +8944,10 @@ do_pg_backup_start(const char *backupidstr, bool fast, List **tablespaces,
datadirpathlen = strlen(DataDir); datadirpathlen = strlen(DataDir);
/* Collect information about all tablespaces */ /* Collect information about all tablespaces */
tblspcdir = AllocateDir("pg_tblspc"); tblspcdir = AllocateDir(PG_TBLSPC_DIR);
while ((de = ReadDir(tblspcdir, "pg_tblspc")) != NULL) while ((de = ReadDir(tblspcdir, PG_TBLSPC_DIR)) != NULL)
{ {
char fullpath[MAXPGPATH + 10]; char fullpath[MAXPGPATH + sizeof(PG_TBLSPC_DIR)];
char linkpath[MAXPGPATH]; char linkpath[MAXPGPATH];
char *relpath = NULL; char *relpath = NULL;
char *s; char *s;
@ -8970,7 +8970,7 @@ do_pg_backup_start(const char *backupidstr, bool fast, List **tablespaces,
if (*badp != '\0' || errno == EINVAL || errno == ERANGE) if (*badp != '\0' || errno == EINVAL || errno == ERANGE)
continue; continue;
snprintf(fullpath, sizeof(fullpath), "pg_tblspc/%s", de->d_name); snprintf(fullpath, sizeof(fullpath), "%s/%s", PG_TBLSPC_DIR, de->d_name);
de_type = get_dirent_type(fullpath, de, false, ERROR); de_type = get_dirent_type(fullpath, de, false, ERROR);
@ -9031,8 +9031,8 @@ do_pg_backup_start(const char *backupidstr, bool fast, List **tablespaces,
* In this case, we store a relative path rather than an * In this case, we store a relative path rather than an
* absolute path into the tablespaceinfo. * absolute path into the tablespaceinfo.
*/ */
snprintf(linkpath, sizeof(linkpath), "pg_tblspc/%s", snprintf(linkpath, sizeof(linkpath), "%s/%s",
de->d_name); PG_TBLSPC_DIR, de->d_name);
relpath = pstrdup(linkpath); relpath = pstrdup(linkpath);
} }
else else

View File

@ -677,7 +677,7 @@ InitWalRecovery(ControlFileData *ControlFile, bool *wasShutdown_ptr,
tablespaceinfo *ti = lfirst(lc); tablespaceinfo *ti = lfirst(lc);
char *linkloc; char *linkloc;
linkloc = psprintf("pg_tblspc/%u", ti->oid); linkloc = psprintf("%s/%u", PG_TBLSPC_DIR, ti->oid);
/* /*
* Remove the existing symlink if any and Create the symlink * Remove the existing symlink if any and Create the symlink
@ -2157,23 +2157,24 @@ CheckTablespaceDirectory(void)
DIR *dir; DIR *dir;
struct dirent *de; struct dirent *de;
dir = AllocateDir("pg_tblspc"); dir = AllocateDir(PG_TBLSPC_DIR);
while ((de = ReadDir(dir, "pg_tblspc")) != NULL) while ((de = ReadDir(dir, PG_TBLSPC_DIR)) != NULL)
{ {
char path[MAXPGPATH + 10]; char path[MAXPGPATH + sizeof(PG_TBLSPC_DIR)];
/* Skip entries of non-oid names */ /* Skip entries of non-oid names */
if (strspn(de->d_name, "0123456789") != strlen(de->d_name)) if (strspn(de->d_name, "0123456789") != strlen(de->d_name))
continue; continue;
snprintf(path, sizeof(path), "pg_tblspc/%s", de->d_name); snprintf(path, sizeof(path), "%s/%s", PG_TBLSPC_DIR, de->d_name);
if (get_dirent_type(path, de, false, ERROR) != PGFILETYPE_LNK) if (get_dirent_type(path, de, false, ERROR) != PGFILETYPE_LNK)
ereport(allow_in_place_tablespaces ? WARNING : PANIC, ereport(allow_in_place_tablespaces ? WARNING : PANIC,
(errcode(ERRCODE_DATA_CORRUPTED), (errcode(ERRCODE_DATA_CORRUPTED),
errmsg("unexpected directory entry \"%s\" found in %s", errmsg("unexpected directory entry \"%s\" found in %s",
de->d_name, "pg_tblspc/"), de->d_name, PG_TBLSPC_DIR),
errdetail("All directory entries in pg_tblspc/ should be symbolic links."), errdetail("All directory entries in %s/ should be symbolic links.",
PG_TBLSPC_DIR),
errhint("Remove those directories, or set \"allow_in_place_tablespaces\" to ON transiently to let recovery complete."))); errhint("Remove those directories, or set \"allow_in_place_tablespaces\" to ON transiently to let recovery complete.")));
} }
} }

View File

@ -16,6 +16,7 @@
#include "access/xlog.h" #include "access/xlog.h"
#include "backup/backup_manifest.h" #include "backup/backup_manifest.h"
#include "backup/basebackup_sink.h" #include "backup/basebackup_sink.h"
#include "common/relpath.h"
#include "mb/pg_wchar.h" #include "mb/pg_wchar.h"
#include "utils/builtins.h" #include "utils/builtins.h"
#include "utils/json.h" #include "utils/json.h"
@ -117,7 +118,7 @@ AddFileToBackupManifest(backup_manifest_info *manifest, Oid spcoid,
*/ */
if (OidIsValid(spcoid)) if (OidIsValid(spcoid))
{ {
snprintf(pathbuf, sizeof(pathbuf), "pg_tblspc/%u/%s", spcoid, snprintf(pathbuf, sizeof(pathbuf), "%s/%u/%s", PG_TBLSPC_DIR, spcoid,
pathname); pathname);
pathname = pathbuf; pathname = pathbuf;
} }

View File

@ -1488,7 +1488,7 @@ sendDir(bbsink *sink, const char *path, int basepathlen, bool sizeonly,
if (OidIsValid(spcoid)) if (OidIsValid(spcoid))
{ {
relspcoid = spcoid; relspcoid = spcoid;
lookup_path = psprintf("pg_tblspc/%u/%s", spcoid, lookup_path = psprintf("%s/%u/%s", PG_TBLSPC_DIR, spcoid,
tarfilename); tarfilename);
} }
else else

View File

@ -3257,7 +3257,7 @@ recovery_create_dbdir(char *path, bool only_tblspc)
if (stat(path, &st) == 0) if (stat(path, &st) == 0)
return; return;
if (only_tblspc && strstr(path, "pg_tblspc/") == NULL) if (only_tblspc && strstr(path, PG_TBLSPC_DIR_SLASH) == NULL)
elog(PANIC, "requested to created invalid directory: %s", path); elog(PANIC, "requested to created invalid directory: %s", path);
if (reachedConsistency && !allow_in_place_tablespaces) if (reachedConsistency && !allow_in_place_tablespaces)

View File

@ -576,7 +576,7 @@ create_tablespace_directories(const char *location, const Oid tablespaceoid)
struct stat st; struct stat st;
bool in_place; bool in_place;
linkloc = psprintf("pg_tblspc/%u", tablespaceoid); linkloc = psprintf("%s/%u", PG_TBLSPC_DIR, tablespaceoid);
/* /*
* If we're asked to make an 'in place' tablespace, create the directory * If we're asked to make an 'in place' tablespace, create the directory
@ -692,7 +692,7 @@ destroy_tablespace_directories(Oid tablespaceoid, bool redo)
char *subfile; char *subfile;
struct stat st; struct stat st;
linkloc_with_version_dir = psprintf("pg_tblspc/%u/%s", tablespaceoid, linkloc_with_version_dir = psprintf("%s/%u/%s", PG_TBLSPC_DIR, tablespaceoid,
TABLESPACE_VERSION_DIRECTORY); TABLESPACE_VERSION_DIRECTORY);
/* /*

View File

@ -1790,8 +1790,8 @@ TempTablespacePath(char *path, Oid tablespace)
else else
{ {
/* All other tablespaces are accessed via symlinks */ /* All other tablespaces are accessed via symlinks */
snprintf(path, MAXPGPATH, "pg_tblspc/%u/%s/%s", snprintf(path, MAXPGPATH, "%s/%u/%s/%s",
tablespace, TABLESPACE_VERSION_DIRECTORY, PG_TBLSPC_DIR, tablespace, TABLESPACE_VERSION_DIRECTORY,
PG_TEMP_FILES_DIR); PG_TEMP_FILES_DIR);
} }
} }
@ -3296,7 +3296,7 @@ CleanupTempFiles(bool isCommit, bool isProcExit)
void void
RemovePgTempFiles(void) RemovePgTempFiles(void)
{ {
char temp_path[MAXPGPATH + 10 + sizeof(TABLESPACE_VERSION_DIRECTORY) + sizeof(PG_TEMP_FILES_DIR)]; char temp_path[MAXPGPATH + sizeof(PG_TBLSPC_DIR) + sizeof(TABLESPACE_VERSION_DIRECTORY) + sizeof(PG_TEMP_FILES_DIR)];
DIR *spc_dir; DIR *spc_dir;
struct dirent *spc_de; struct dirent *spc_de;
@ -3310,20 +3310,21 @@ RemovePgTempFiles(void)
/* /*
* Cycle through temp directories for all non-default tablespaces. * Cycle through temp directories for all non-default tablespaces.
*/ */
spc_dir = AllocateDir("pg_tblspc"); spc_dir = AllocateDir(PG_TBLSPC_DIR);
while ((spc_de = ReadDirExtended(spc_dir, "pg_tblspc", LOG)) != NULL) while ((spc_de = ReadDirExtended(spc_dir, PG_TBLSPC_DIR, LOG)) != NULL)
{ {
if (strcmp(spc_de->d_name, ".") == 0 || if (strcmp(spc_de->d_name, ".") == 0 ||
strcmp(spc_de->d_name, "..") == 0) strcmp(spc_de->d_name, "..") == 0)
continue; continue;
snprintf(temp_path, sizeof(temp_path), "pg_tblspc/%s/%s/%s", snprintf(temp_path, sizeof(temp_path), "%s/%s/%s/%s",
spc_de->d_name, TABLESPACE_VERSION_DIRECTORY, PG_TEMP_FILES_DIR); PG_TBLSPC_DIR, spc_de->d_name, TABLESPACE_VERSION_DIRECTORY,
PG_TEMP_FILES_DIR);
RemovePgTempFilesInDir(temp_path, true, false); RemovePgTempFilesInDir(temp_path, true, false);
snprintf(temp_path, sizeof(temp_path), "pg_tblspc/%s/%s", snprintf(temp_path, sizeof(temp_path), "%s/%s/%s",
spc_de->d_name, TABLESPACE_VERSION_DIRECTORY); PG_TBLSPC_DIR, spc_de->d_name, TABLESPACE_VERSION_DIRECTORY);
RemovePgTempRelationFiles(temp_path); RemovePgTempRelationFiles(temp_path);
} }
@ -3610,15 +3611,15 @@ SyncDataDirectory(void)
/* Sync the top level pgdata directory. */ /* Sync the top level pgdata directory. */
do_syncfs("."); do_syncfs(".");
/* If any tablespaces are configured, sync each of those. */ /* If any tablespaces are configured, sync each of those. */
dir = AllocateDir("pg_tblspc"); dir = AllocateDir(PG_TBLSPC_DIR);
while ((de = ReadDirExtended(dir, "pg_tblspc", LOG))) while ((de = ReadDirExtended(dir, PG_TBLSPC_DIR, LOG)))
{ {
char path[MAXPGPATH]; char path[MAXPGPATH];
if (strcmp(de->d_name, ".") == 0 || strcmp(de->d_name, "..") == 0) if (strcmp(de->d_name, ".") == 0 || strcmp(de->d_name, "..") == 0)
continue; continue;
snprintf(path, MAXPGPATH, "pg_tblspc/%s", de->d_name); snprintf(path, MAXPGPATH, "%s/%s", PG_TBLSPC_DIR, de->d_name);
do_syncfs(path); do_syncfs(path);
} }
FreeDir(dir); FreeDir(dir);
@ -3641,7 +3642,7 @@ SyncDataDirectory(void)
walkdir(".", pre_sync_fname, false, DEBUG1); walkdir(".", pre_sync_fname, false, DEBUG1);
if (xlog_is_symlink) if (xlog_is_symlink)
walkdir("pg_wal", pre_sync_fname, false, DEBUG1); walkdir("pg_wal", pre_sync_fname, false, DEBUG1);
walkdir("pg_tblspc", pre_sync_fname, true, DEBUG1); walkdir(PG_TBLSPC_DIR, pre_sync_fname, true, DEBUG1);
#endif #endif
/* Prepare to report progress syncing the data directory via fsync. */ /* Prepare to report progress syncing the data directory via fsync. */
@ -3659,7 +3660,7 @@ SyncDataDirectory(void)
walkdir(".", datadir_fsync_fname, false, LOG); walkdir(".", datadir_fsync_fname, false, LOG);
if (xlog_is_symlink) if (xlog_is_symlink)
walkdir("pg_wal", datadir_fsync_fname, false, LOG); walkdir("pg_wal", datadir_fsync_fname, false, LOG);
walkdir("pg_tblspc", datadir_fsync_fname, true, LOG); walkdir(PG_TBLSPC_DIR, datadir_fsync_fname, true, LOG);
} }
/* /*

View File

@ -46,7 +46,7 @@ typedef struct
void void
ResetUnloggedRelations(int op) ResetUnloggedRelations(int op)
{ {
char temp_path[MAXPGPATH + 10 + sizeof(TABLESPACE_VERSION_DIRECTORY)]; char temp_path[MAXPGPATH + sizeof(PG_TBLSPC_DIR) + sizeof(TABLESPACE_VERSION_DIRECTORY)];
DIR *spc_dir; DIR *spc_dir;
struct dirent *spc_de; struct dirent *spc_de;
MemoryContext tmpctx, MemoryContext tmpctx,
@ -77,16 +77,16 @@ ResetUnloggedRelations(int op)
/* /*
* Cycle through directories for all non-default tablespaces. * Cycle through directories for all non-default tablespaces.
*/ */
spc_dir = AllocateDir("pg_tblspc"); spc_dir = AllocateDir(PG_TBLSPC_DIR);
while ((spc_de = ReadDir(spc_dir, "pg_tblspc")) != NULL) while ((spc_de = ReadDir(spc_dir, PG_TBLSPC_DIR)) != NULL)
{ {
if (strcmp(spc_de->d_name, ".") == 0 || if (strcmp(spc_de->d_name, ".") == 0 ||
strcmp(spc_de->d_name, "..") == 0) strcmp(spc_de->d_name, "..") == 0)
continue; continue;
snprintf(temp_path, sizeof(temp_path), "pg_tblspc/%s/%s", snprintf(temp_path, sizeof(temp_path), "%s/%s/%s",
spc_de->d_name, TABLESPACE_VERSION_DIRECTORY); PG_TBLSPC_DIR, spc_de->d_name, TABLESPACE_VERSION_DIRECTORY);
ResetUnloggedRelationsInTablespaceDir(temp_path, op); ResetUnloggedRelationsInTablespaceDir(temp_path, op);
} }

View File

@ -143,7 +143,7 @@ calculate_database_size(Oid dbOid)
totalsize = db_dir_size(pathname); totalsize = db_dir_size(pathname);
/* Scan the non-default tablespaces */ /* Scan the non-default tablespaces */
snprintf(dirpath, MAXPGPATH, "pg_tblspc"); snprintf(dirpath, MAXPGPATH, PG_TBLSPC_DIR);
dirdesc = AllocateDir(dirpath); dirdesc = AllocateDir(dirpath);
while ((direntry = ReadDir(dirdesc, dirpath)) != NULL) while ((direntry = ReadDir(dirdesc, dirpath)) != NULL)
@ -154,8 +154,8 @@ calculate_database_size(Oid dbOid)
strcmp(direntry->d_name, "..") == 0) strcmp(direntry->d_name, "..") == 0)
continue; continue;
snprintf(pathname, sizeof(pathname), "pg_tblspc/%s/%s/%u", snprintf(pathname, sizeof(pathname), "%s/%s/%s/%u",
direntry->d_name, TABLESPACE_VERSION_DIRECTORY, dbOid); PG_TBLSPC_DIR, direntry->d_name, TABLESPACE_VERSION_DIRECTORY, dbOid);
totalsize += db_dir_size(pathname); totalsize += db_dir_size(pathname);
} }
@ -227,7 +227,7 @@ calculate_tablespace_size(Oid tblspcOid)
else if (tblspcOid == GLOBALTABLESPACE_OID) else if (tblspcOid == GLOBALTABLESPACE_OID)
snprintf(tblspcPath, MAXPGPATH, "global"); snprintf(tblspcPath, MAXPGPATH, "global");
else else
snprintf(tblspcPath, MAXPGPATH, "pg_tblspc/%u/%s", tblspcOid, snprintf(tblspcPath, MAXPGPATH, "%s/%u/%s", PG_TBLSPC_DIR, tblspcOid,
TABLESPACE_VERSION_DIRECTORY); TABLESPACE_VERSION_DIRECTORY);
dirdesc = AllocateDir(tblspcPath); dirdesc = AllocateDir(tblspcPath);

View File

@ -242,7 +242,7 @@ pg_tablespace_databases(PG_FUNCTION_ARGS)
if (tablespaceOid == DEFAULTTABLESPACE_OID) if (tablespaceOid == DEFAULTTABLESPACE_OID)
location = "base"; location = "base";
else else
location = psprintf("pg_tblspc/%u/%s", tablespaceOid, location = psprintf("%s/%u/%s", PG_TBLSPC_DIR, tablespaceOid,
TABLESPACE_VERSION_DIRECTORY); TABLESPACE_VERSION_DIRECTORY);
dirdesc = AllocateDir(location); dirdesc = AllocateDir(location);
@ -325,7 +325,7 @@ pg_tablespace_location(PG_FUNCTION_ARGS)
* Find the location of the tablespace by reading the symbolic link that * Find the location of the tablespace by reading the symbolic link that
* is in pg_tblspc/<oid>. * is in pg_tblspc/<oid>.
*/ */
snprintf(sourcepath, sizeof(sourcepath), "pg_tblspc/%u", tablespaceOid); snprintf(sourcepath, sizeof(sourcepath), "%s/%u", PG_TBLSPC_DIR, tablespaceOid);
/* /*
* Before reading the link, check if the source path is a link or a * Before reading the link, check if the source path is a link or a

View File

@ -6800,10 +6800,10 @@ RelationCacheInitFilePostInvalidate(void)
void void
RelationCacheInitFileRemove(void) RelationCacheInitFileRemove(void)
{ {
const char *tblspcdir = "pg_tblspc"; const char *tblspcdir = PG_TBLSPC_DIR;
DIR *dir; DIR *dir;
struct dirent *de; struct dirent *de;
char path[MAXPGPATH + 10 + sizeof(TABLESPACE_VERSION_DIRECTORY)]; char path[MAXPGPATH + sizeof(PG_TBLSPC_DIR) + sizeof(TABLESPACE_VERSION_DIRECTORY)];
snprintf(path, sizeof(path), "global/%s", snprintf(path, sizeof(path), "global/%s",
RELCACHE_INIT_FILENAME); RELCACHE_INIT_FILENAME);

View File

@ -388,7 +388,7 @@ scan_directory(const char *basedir, const char *subdir, bool sizeonly)
* is valid, resolving the linked locations and dive into them * is valid, resolving the linked locations and dive into them
* directly. * directly.
*/ */
if (strncmp("pg_tblspc", subdir, strlen("pg_tblspc")) == 0) if (strncmp(PG_TBLSPC_DIR, subdir, strlen(PG_TBLSPC_DIR)) == 0)
{ {
char tblspc_path[MAXPGPATH]; char tblspc_path[MAXPGPATH];
struct stat tblspc_st; struct stat tblspc_st;
@ -593,12 +593,12 @@ main(int argc, char *argv[])
{ {
total_size = scan_directory(DataDir, "global", true); total_size = scan_directory(DataDir, "global", true);
total_size += scan_directory(DataDir, "base", true); total_size += scan_directory(DataDir, "base", true);
total_size += scan_directory(DataDir, "pg_tblspc", true); total_size += scan_directory(DataDir, PG_TBLSPC_DIR, true);
} }
(void) scan_directory(DataDir, "global", false); (void) scan_directory(DataDir, "global", false);
(void) scan_directory(DataDir, "base", false); (void) scan_directory(DataDir, "base", false);
(void) scan_directory(DataDir, "pg_tblspc", false); (void) scan_directory(DataDir, PG_TBLSPC_DIR, false);
if (showprogress) if (showprogress)
progress_report(true); progress_report(true);

View File

@ -373,7 +373,7 @@ main(int argc, char *argv[])
{ {
char linkpath[MAXPGPATH]; char linkpath[MAXPGPATH];
snprintf(linkpath, MAXPGPATH, "%s/pg_tblspc/%u", opt.output, snprintf(linkpath, MAXPGPATH, "%s/%s/%u", opt.output, PG_TBLSPC_DIR,
ts->oid); ts->oid);
if (opt.dry_run) if (opt.dry_run)
@ -867,12 +867,12 @@ process_directory_recursively(Oid tsoid,
is_incremental_dir = true; is_incremental_dir = true;
else if (relative_path != NULL) else if (relative_path != NULL)
{ {
is_pg_tblspc = strcmp(relative_path, "pg_tblspc") == 0; is_pg_tblspc = strcmp(relative_path, PG_TBLSPC_DIR) == 0;
is_pg_wal = (strcmp(relative_path, "pg_wal") == 0 || is_pg_wal = (strcmp(relative_path, "pg_wal") == 0 ||
strncmp(relative_path, "pg_wal/", 7) == 0); strncmp(relative_path, "pg_wal/", 7) == 0);
is_incremental_dir = strncmp(relative_path, "base/", 5) == 0 || is_incremental_dir = strncmp(relative_path, "base/", 5) == 0 ||
strcmp(relative_path, "global") == 0 || strcmp(relative_path, "global") == 0 ||
strncmp(relative_path, "pg_tblspc/", 10) == 0; strncmp(relative_path, PG_TBLSPC_DIR_SLASH, 10) == 0;
} }
/* /*
@ -895,7 +895,7 @@ process_directory_recursively(Oid tsoid,
strlcpy(ifulldir, input_directory, MAXPGPATH); strlcpy(ifulldir, input_directory, MAXPGPATH);
strlcpy(ofulldir, output_directory, MAXPGPATH); strlcpy(ofulldir, output_directory, MAXPGPATH);
if (OidIsValid(tsoid)) if (OidIsValid(tsoid))
snprintf(manifest_prefix, MAXPGPATH, "pg_tblspc/%u/", tsoid); snprintf(manifest_prefix, MAXPGPATH, "%s/%u/", PG_TBLSPC_DIR, tsoid);
else else
manifest_prefix[0] = '\0'; manifest_prefix[0] = '\0';
} }
@ -906,8 +906,8 @@ process_directory_recursively(Oid tsoid,
snprintf(ofulldir, MAXPGPATH, "%s/%s", output_directory, snprintf(ofulldir, MAXPGPATH, "%s/%s", output_directory,
relative_path); relative_path);
if (OidIsValid(tsoid)) if (OidIsValid(tsoid))
snprintf(manifest_prefix, MAXPGPATH, "pg_tblspc/%u/%s/", snprintf(manifest_prefix, MAXPGPATH, "%s/%u/%s/",
tsoid, relative_path); PG_TBLSPC_DIR, tsoid, relative_path);
else else
snprintf(manifest_prefix, MAXPGPATH, "%s/", relative_path); snprintf(manifest_prefix, MAXPGPATH, "%s/", relative_path);
} }
@ -1249,7 +1249,7 @@ scan_for_existing_tablespaces(char *pathname, cb_options *opt)
struct dirent *de; struct dirent *de;
cb_tablespace *tslist = NULL; cb_tablespace *tslist = NULL;
snprintf(pg_tblspc, MAXPGPATH, "%s/pg_tblspc", pathname); snprintf(pg_tblspc, MAXPGPATH, "%s/%s", pathname, PG_TBLSPC_DIR);
pg_log_debug("scanning \"%s\"", pg_tblspc); pg_log_debug("scanning \"%s\"", pg_tblspc);
if ((dir = opendir(pg_tblspc)) == NULL) if ((dir = opendir(pg_tblspc)) == NULL)
@ -1344,8 +1344,8 @@ scan_for_existing_tablespaces(char *pathname, cb_options *opt)
* we just record the paths within the data directories. * we just record the paths within the data directories.
*/ */
snprintf(ts->old_dir, MAXPGPATH, "%s/%s", pg_tblspc, de->d_name); snprintf(ts->old_dir, MAXPGPATH, "%s/%s", pg_tblspc, de->d_name);
snprintf(ts->new_dir, MAXPGPATH, "%s/pg_tblspc/%s", opt->output, snprintf(ts->new_dir, MAXPGPATH, "%s/%s/%s", opt->output,
de->d_name); PG_TBLSPC_DIR, de->d_name);
ts->in_place = true; ts->in_place = true;
} }

View File

@ -452,7 +452,7 @@ recurse_dir(const char *datadir, const char *parentpath,
* to process all the tablespaces. We also follow a symlink if * to process all the tablespaces. We also follow a symlink if
* it's for pg_wal. Symlinks elsewhere are ignored. * it's for pg_wal. Symlinks elsewhere are ignored.
*/ */
if ((parentpath && strcmp(parentpath, "pg_tblspc") == 0) || if ((parentpath && strcmp(parentpath, PG_TBLSPC_DIR) == 0) ||
strcmp(path, "pg_wal") == 0) strcmp(path, "pg_wal") == 0)
recurse_dir(datadir, path, callback); recurse_dir(datadir, path, callback);
} }

View File

@ -350,7 +350,7 @@ check_data_dir(ClusterInfo *cluster)
check_single_dir(pg_data, "global"); check_single_dir(pg_data, "global");
check_single_dir(pg_data, "pg_multixact"); check_single_dir(pg_data, "pg_multixact");
check_single_dir(pg_data, "pg_subtrans"); check_single_dir(pg_data, "pg_subtrans");
check_single_dir(pg_data, "pg_tblspc"); check_single_dir(pg_data, PG_TBLSPC_DIR);
check_single_dir(pg_data, "pg_twophase"); check_single_dir(pg_data, "pg_twophase");
/* pg_xlog has been renamed to pg_wal in v10 */ /* pg_xlog has been renamed to pg_wal in v10 */

View File

@ -28,6 +28,7 @@
#ifdef FRONTEND #ifdef FRONTEND
#include "common/logging.h" #include "common/logging.h"
#endif #endif
#include "common/relpath.h"
#include "port/pg_iovec.h" #include "port/pg_iovec.h"
#ifdef FRONTEND #ifdef FRONTEND
@ -105,7 +106,7 @@ sync_pgdata(const char *pg_data,
/* handle renaming of pg_xlog to pg_wal in post-10 clusters */ /* handle renaming of pg_xlog to pg_wal in post-10 clusters */
snprintf(pg_wal, MAXPGPATH, "%s/%s", pg_data, snprintf(pg_wal, MAXPGPATH, "%s/%s", pg_data,
serverVersion < MINIMUM_VERSION_FOR_PG_WAL ? "pg_xlog" : "pg_wal"); serverVersion < MINIMUM_VERSION_FOR_PG_WAL ? "pg_xlog" : "pg_wal");
snprintf(pg_tblspc, MAXPGPATH, "%s/pg_tblspc", pg_data); snprintf(pg_tblspc, MAXPGPATH, "%s/%s", pg_data, PG_TBLSPC_DIR);
/* /*
* If pg_wal is a symlink, we'll need to recurse into it separately, * If pg_wal is a symlink, we'll need to recurse into it separately,

View File

@ -123,8 +123,9 @@ GetDatabasePath(Oid dbOid, Oid spcOid)
else else
{ {
/* All other tablespaces are accessed via symlinks */ /* All other tablespaces are accessed via symlinks */
return psprintf("pg_tblspc/%u/%s/%u", return psprintf("%s/%u/%s/%u",
spcOid, TABLESPACE_VERSION_DIRECTORY, dbOid); PG_TBLSPC_DIR, spcOid,
TABLESPACE_VERSION_DIRECTORY, dbOid);
} }
} }
@ -184,25 +185,29 @@ GetRelationPath(Oid dbOid, Oid spcOid, RelFileNumber relNumber,
if (procNumber == INVALID_PROC_NUMBER) if (procNumber == INVALID_PROC_NUMBER)
{ {
if (forkNumber != MAIN_FORKNUM) if (forkNumber != MAIN_FORKNUM)
path = psprintf("pg_tblspc/%u/%s/%u/%u_%s", path = psprintf("%s/%u/%s/%u/%u_%s",
spcOid, TABLESPACE_VERSION_DIRECTORY, PG_TBLSPC_DIR, spcOid,
TABLESPACE_VERSION_DIRECTORY,
dbOid, relNumber, dbOid, relNumber,
forkNames[forkNumber]); forkNames[forkNumber]);
else else
path = psprintf("pg_tblspc/%u/%s/%u/%u", path = psprintf("%s/%u/%s/%u/%u",
spcOid, TABLESPACE_VERSION_DIRECTORY, PG_TBLSPC_DIR, spcOid,
TABLESPACE_VERSION_DIRECTORY,
dbOid, relNumber); dbOid, relNumber);
} }
else else
{ {
if (forkNumber != MAIN_FORKNUM) if (forkNumber != MAIN_FORKNUM)
path = psprintf("pg_tblspc/%u/%s/%u/t%d_%u_%s", path = psprintf("%s/%u/%s/%u/t%d_%u_%s",
spcOid, TABLESPACE_VERSION_DIRECTORY, PG_TBLSPC_DIR, spcOid,
TABLESPACE_VERSION_DIRECTORY,
dbOid, procNumber, relNumber, dbOid, procNumber, relNumber,
forkNames[forkNumber]); forkNames[forkNumber]);
else else
path = psprintf("pg_tblspc/%u/%s/%u/t%d_%u", path = psprintf("%s/%u/%s/%u/t%d_%u",
spcOid, TABLESPACE_VERSION_DIRECTORY, PG_TBLSPC_DIR, spcOid,
TABLESPACE_VERSION_DIRECTORY,
dbOid, procNumber, relNumber); dbOid, procNumber, relNumber);
} }
} }

View File

@ -33,6 +33,15 @@ typedef Oid RelFileNumber;
#define TABLESPACE_VERSION_DIRECTORY "PG_" PG_MAJORVERSION "_" \ #define TABLESPACE_VERSION_DIRECTORY "PG_" PG_MAJORVERSION "_" \
CppAsString2(CATALOG_VERSION_NO) CppAsString2(CATALOG_VERSION_NO)
/*
* Tablespace path (relative to installation's $PGDATA).
*
* These values should not be changed as many tools rely on it.
*/
#define PG_TBLSPC_DIR "pg_tblspc"
#define PG_TBLSPC_DIR_SLASH "pg_tblspc/" /* required for strings
* comparisons */
/* Characters to allow for an OID in a relation path */ /* Characters to allow for an OID in a relation path */
#define OIDCHARS 10 /* max chars printed by %u */ #define OIDCHARS 10 /* max chars printed by %u */