2020 * on standbys (to support cascading setups). The requirement that slots be
2121 * usable on standbys precludes storing them in the system catalogs.
2222 *
23- * Each replication slot gets its own directory inside the $PGDATA/pg_replslot
24- * directory. Inside that directory the state file will contain the slot's
25- * own data. Additional data can be stored alongside that file if required.
26- * While the server is running, the state data is also cached in memory for
27- * efficiency.
23+ * Each replication slot gets its own directory inside the directory
24+ * $PGDATA / PG_REPLSLOT_DIR. Inside that directory the state file will
25+ * contain the slot's own data. Additional data can be stored alongside that
26+ * file if required. While the server is running, the state data is also
27+ * cached in memory for efficiency.
2828 *
2929 * ReplicationSlotAllocationLock must be taken in exclusive mode to allocate
3030 * or free a slot. ReplicationSlotControlLock must be taken in shared mode
@@ -916,8 +916,8 @@ ReplicationSlotDropPtr(ReplicationSlot *slot)
916916 LWLockAcquire (ReplicationSlotAllocationLock , LW_EXCLUSIVE );
917917
918918 /* Generate pathnames. */
919- sprintf (path , "pg_replslot /%s" , NameStr (slot -> data .name ));
920- sprintf (tmppath , "pg_replslot /%s.tmp" , NameStr (slot -> data .name ));
919+ sprintf (path , "%s /%s" , PG_REPLSLOT_DIR , NameStr (slot -> data .name ));
920+ sprintf (tmppath , "%s /%s.tmp" , PG_REPLSLOT_DIR , NameStr (slot -> data .name ));
921921
922922 /*
923923 * Rename the slot directory on disk, so that we'll no longer recognize
@@ -938,7 +938,7 @@ ReplicationSlotDropPtr(ReplicationSlot *slot)
938938 */
939939 START_CRIT_SECTION ();
940940 fsync_fname (tmppath , true);
941- fsync_fname ("pg_replslot" , true);
941+ fsync_fname (PG_REPLSLOT_DIR , true);
942942 END_CRIT_SECTION ();
943943 }
944944 else
@@ -1016,7 +1016,7 @@ ReplicationSlotSave(void)
10161016
10171017 Assert (MyReplicationSlot != NULL );
10181018
1019- sprintf (path , "pg_replslot /%s" , NameStr (MyReplicationSlot -> data .name ));
1019+ sprintf (path , "%s /%s" , PG_REPLSLOT_DIR , NameStr (MyReplicationSlot -> data .name ));
10201020 SaveSlotToPath (MyReplicationSlot , path , ERROR );
10211021}
10221022
@@ -1881,7 +1881,7 @@ CheckPointReplicationSlots(bool is_shutdown)
18811881 continue ;
18821882
18831883 /* save the slot to disk, locking is handled in SaveSlotToPath() */
1884- sprintf (path , "pg_replslot /%s" , NameStr (s -> data .name ));
1884+ sprintf (path , "%s /%s" , PG_REPLSLOT_DIR , NameStr (s -> data .name ));
18851885
18861886 /*
18871887 * Slot's data is not flushed each time the confirmed_flush LSN is
@@ -1922,17 +1922,17 @@ StartupReplicationSlots(void)
19221922 elog (DEBUG1 , "starting up replication slots" );
19231923
19241924 /* restore all slots by iterating over all on-disk entries */
1925- replication_dir = AllocateDir ("pg_replslot" );
1926- while ((replication_de = ReadDir (replication_dir , "pg_replslot" )) != NULL )
1925+ replication_dir = AllocateDir (PG_REPLSLOT_DIR );
1926+ while ((replication_de = ReadDir (replication_dir , PG_REPLSLOT_DIR )) != NULL )
19271927 {
1928- char path [MAXPGPATH + 12 ];
1928+ char path [MAXPGPATH + sizeof ( PG_REPLSLOT_DIR ) ];
19291929 PGFileType de_type ;
19301930
19311931 if (strcmp (replication_de -> d_name , "." ) == 0 ||
19321932 strcmp (replication_de -> d_name , ".." ) == 0 )
19331933 continue ;
19341934
1935- snprintf (path , sizeof (path ), "pg_replslot /%s" , replication_de -> d_name );
1935+ snprintf (path , sizeof (path ), "%s /%s" , PG_REPLSLOT_DIR , replication_de -> d_name );
19361936 de_type = get_dirent_type (path , replication_de , false, DEBUG1 );
19371937
19381938 /* we're only creating directories here, skip if it's not our's */
@@ -1949,7 +1949,7 @@ StartupReplicationSlots(void)
19491949 path )));
19501950 continue ;
19511951 }
1952- fsync_fname ("pg_replslot" , true);
1952+ fsync_fname (PG_REPLSLOT_DIR , true);
19531953 continue ;
19541954 }
19551955
@@ -1987,8 +1987,8 @@ CreateSlotOnDisk(ReplicationSlot *slot)
19871987 * takes out the lock, if we'd take the lock here, we'd deadlock.
19881988 */
19891989
1990- sprintf (path , "pg_replslot /%s" , NameStr (slot -> data .name ));
1991- sprintf (tmppath , "pg_replslot /%s.tmp" , NameStr (slot -> data .name ));
1990+ sprintf (path , "%s /%s" , PG_REPLSLOT_DIR , NameStr (slot -> data .name ));
1991+ sprintf (tmppath , "%s /%s.tmp" , PG_REPLSLOT_DIR , NameStr (slot -> data .name ));
19921992
19931993 /*
19941994 * It's just barely possible that some previous effort to create or drop a
@@ -2027,7 +2027,7 @@ CreateSlotOnDisk(ReplicationSlot *slot)
20272027 START_CRIT_SECTION ();
20282028
20292029 fsync_fname (path , true);
2030- fsync_fname ("pg_replslot" , true);
2030+ fsync_fname (PG_REPLSLOT_DIR , true);
20312031
20322032 END_CRIT_SECTION ();
20332033}
@@ -2170,7 +2170,7 @@ SaveSlotToPath(ReplicationSlot *slot, const char *dir, int elevel)
21702170
21712171 fsync_fname (path , false);
21722172 fsync_fname (dir , true);
2173- fsync_fname ("pg_replslot" , true);
2173+ fsync_fname (PG_REPLSLOT_DIR , true);
21742174
21752175 END_CRIT_SECTION ();
21762176
@@ -2195,8 +2195,8 @@ RestoreSlotFromDisk(const char *name)
21952195{
21962196 ReplicationSlotOnDisk cp ;
21972197 int i ;
2198- char slotdir [MAXPGPATH + 12 ];
2199- char path [MAXPGPATH + 22 ];
2198+ char slotdir [MAXPGPATH + sizeof ( PG_REPLSLOT_DIR ) ];
2199+ char path [MAXPGPATH + sizeof ( PG_REPLSLOT_DIR ) + 10 ];
22002200 int fd ;
22012201 bool restored = false;
22022202 int readBytes ;
@@ -2205,7 +2205,7 @@ RestoreSlotFromDisk(const char *name)
22052205 /* no need to lock here, no concurrent access allowed yet */
22062206
22072207 /* delete temp file if it exists */
2208- sprintf (slotdir , "pg_replslot /%s" , name );
2208+ sprintf (slotdir , "%s /%s" , PG_REPLSLOT_DIR , name );
22092209 sprintf (path , "%s/state.tmp" , slotdir );
22102210 if (unlink (path ) < 0 && errno != ENOENT )
22112211 ereport (PANIC ,
@@ -2332,7 +2332,7 @@ RestoreSlotFromDisk(const char *name)
23322332 (errmsg ("could not remove directory \"%s\"" ,
23332333 slotdir )));
23342334 }
2335- fsync_fname ("pg_replslot" , true);
2335+ fsync_fname (PG_REPLSLOT_DIR , true);
23362336 return ;
23372337 }
23382338
0 commit comments