DIR *spill_dir;
struct dirent *spill_de;
struct stat statbuf;
- char path[MAXPGPATH * 2 + 12];
+ char path[MAXPGPATH * 2 + sizeof(PG_REPLSLOT_DIR)];
- sprintf(path, "pg_replslot/%s", slotname);
+ sprintf(path, "%s/%s", PG_REPLSLOT_DIR, slotname);
/* we're only handling directories here, skip if it's not ours */
if (lstat(path, &statbuf) == 0 && !S_ISDIR(statbuf.st_mode))
if (strncmp(spill_de->d_name, "xid", 3) == 0)
{
snprintf(path, sizeof(path),
- "pg_replslot/%s/%s", slotname,
+ "%s/%s/%s", PG_REPLSLOT_DIR, slotname,
spill_de->d_name);
if (unlink(path) != 0)
ereport(ERROR,
(errcode_for_file_access(),
- errmsg("could not remove file \"%s\" during removal of pg_replslot/%s/xid*: %m",
- path, slotname)));
+ errmsg("could not remove file \"%s\" during removal of %s/%s/xid*: %m",
+ path, PG_REPLSLOT_DIR, slotname)));
}
}
FreeDir(spill_dir);
XLogSegNoOffsetToRecPtr(segno, 0, wal_segment_size, recptr);
- snprintf(path, MAXPGPATH, "pg_replslot/%s/xid-%u-lsn-%X-%X.spill",
+ snprintf(path, MAXPGPATH, "%s/%s/xid-%u-lsn-%X-%X.spill",
+ PG_REPLSLOT_DIR,
NameStr(MyReplicationSlot->data.name),
xid, LSN_FORMAT_ARGS(recptr));
}
DIR *logical_dir;
struct dirent *logical_de;
- logical_dir = AllocateDir("pg_replslot");
- while ((logical_de = ReadDir(logical_dir, "pg_replslot")) != NULL)
+ logical_dir = AllocateDir(PG_REPLSLOT_DIR);
+ while ((logical_de = ReadDir(logical_dir, PG_REPLSLOT_DIR)) != NULL)
{
if (strcmp(logical_de->d_name, ".") == 0 ||
strcmp(logical_de->d_name, "..") == 0)
* on standbys (to support cascading setups). The requirement that slots be
* usable on standbys precludes storing them in the system catalogs.
*
- * Each replication slot gets its own directory inside the $PGDATA/pg_replslot
- * directory. Inside that directory the state file will contain the slot's
- * own data. Additional data can be stored alongside that file if required.
- * While the server is running, the state data is also cached in memory for
- * efficiency.
+ * Each replication slot gets its own directory inside the directory
+ * $PGDATA / PG_REPLSLOT_DIR. Inside that directory the state file will
+ * contain the slot's own data. Additional data can be stored alongside that
+ * file if required. While the server is running, the state data is also
+ * cached in memory for efficiency.
*
* ReplicationSlotAllocationLock must be taken in exclusive mode to allocate
* or free a slot. ReplicationSlotControlLock must be taken in shared mode
LWLockAcquire(ReplicationSlotAllocationLock, LW_EXCLUSIVE);
/* Generate pathnames. */
- sprintf(path, "pg_replslot/%s", NameStr(slot->data.name));
- sprintf(tmppath, "pg_replslot/%s.tmp", NameStr(slot->data.name));
+ sprintf(path, "%s/%s", PG_REPLSLOT_DIR, NameStr(slot->data.name));
+ sprintf(tmppath, "%s/%s.tmp", PG_REPLSLOT_DIR, NameStr(slot->data.name));
/*
* Rename the slot directory on disk, so that we'll no longer recognize
*/
START_CRIT_SECTION();
fsync_fname(tmppath, true);
- fsync_fname("pg_replslot", true);
+ fsync_fname(PG_REPLSLOT_DIR, true);
END_CRIT_SECTION();
}
else
Assert(MyReplicationSlot != NULL);
- sprintf(path, "pg_replslot/%s", NameStr(MyReplicationSlot->data.name));
+ sprintf(path, "%s/%s", PG_REPLSLOT_DIR, NameStr(MyReplicationSlot->data.name));
SaveSlotToPath(MyReplicationSlot, path, ERROR);
}
continue;
/* save the slot to disk, locking is handled in SaveSlotToPath() */
- sprintf(path, "pg_replslot/%s", NameStr(s->data.name));
+ sprintf(path, "%s/%s", PG_REPLSLOT_DIR, NameStr(s->data.name));
/*
* Slot's data is not flushed each time the confirmed_flush LSN is
elog(DEBUG1, "starting up replication slots");
/* restore all slots by iterating over all on-disk entries */
- replication_dir = AllocateDir("pg_replslot");
- while ((replication_de = ReadDir(replication_dir, "pg_replslot")) != NULL)
+ replication_dir = AllocateDir(PG_REPLSLOT_DIR);
+ while ((replication_de = ReadDir(replication_dir, PG_REPLSLOT_DIR)) != NULL)
{
- char path[MAXPGPATH + 12];
+ char path[MAXPGPATH + sizeof(PG_REPLSLOT_DIR)];
PGFileType de_type;
if (strcmp(replication_de->d_name, ".") == 0 ||
strcmp(replication_de->d_name, "..") == 0)
continue;
- snprintf(path, sizeof(path), "pg_replslot/%s", replication_de->d_name);
+ snprintf(path, sizeof(path), "%s/%s", PG_REPLSLOT_DIR, replication_de->d_name);
de_type = get_dirent_type(path, replication_de, false, DEBUG1);
/* we're only creating directories here, skip if it's not our's */
path)));
continue;
}
- fsync_fname("pg_replslot", true);
+ fsync_fname(PG_REPLSLOT_DIR, true);
continue;
}
* takes out the lock, if we'd take the lock here, we'd deadlock.
*/
- sprintf(path, "pg_replslot/%s", NameStr(slot->data.name));
- sprintf(tmppath, "pg_replslot/%s.tmp", NameStr(slot->data.name));
+ sprintf(path, "%s/%s", PG_REPLSLOT_DIR, NameStr(slot->data.name));
+ sprintf(tmppath, "%s/%s.tmp", PG_REPLSLOT_DIR, NameStr(slot->data.name));
/*
* It's just barely possible that some previous effort to create or drop a
START_CRIT_SECTION();
fsync_fname(path, true);
- fsync_fname("pg_replslot", true);
+ fsync_fname(PG_REPLSLOT_DIR, true);
END_CRIT_SECTION();
}
fsync_fname(path, false);
fsync_fname(dir, true);
- fsync_fname("pg_replslot", true);
+ fsync_fname(PG_REPLSLOT_DIR, true);
END_CRIT_SECTION();
{
ReplicationSlotOnDisk cp;
int i;
- char slotdir[MAXPGPATH + 12];
- char path[MAXPGPATH + 22];
+ char slotdir[MAXPGPATH + sizeof(PG_REPLSLOT_DIR)];
+ char path[MAXPGPATH + sizeof(PG_REPLSLOT_DIR) + 10];
int fd;
bool restored = false;
int readBytes;
/* no need to lock here, no concurrent access allowed yet */
/* delete temp file if it exists */
- sprintf(slotdir, "pg_replslot/%s", name);
+ sprintf(slotdir, "%s/%s", PG_REPLSLOT_DIR, name);
sprintf(path, "%s/state.tmp", slotdir);
if (unlink(path) < 0 && errno != ENOENT)
ereport(PANIC,
(errmsg("could not remove directory \"%s\"",
slotdir)));
}
- fsync_fname("pg_replslot", true);
+ fsync_fname(PG_REPLSLOT_DIR, true);
return;
}