20
20
* on standbys (to support cascading setups). The requirement that slots be
21
21
* usable on standbys precludes storing them in the system catalogs.
22
22
*
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.
28
28
*
29
29
* ReplicationSlotAllocationLock must be taken in exclusive mode to allocate
30
30
* or free a slot. ReplicationSlotControlLock must be taken in shared mode
@@ -916,8 +916,8 @@ ReplicationSlotDropPtr(ReplicationSlot *slot)
916
916
LWLockAcquire (ReplicationSlotAllocationLock , LW_EXCLUSIVE );
917
917
918
918
/* 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 ));
921
921
922
922
/*
923
923
* Rename the slot directory on disk, so that we'll no longer recognize
@@ -938,7 +938,7 @@ ReplicationSlotDropPtr(ReplicationSlot *slot)
938
938
*/
939
939
START_CRIT_SECTION ();
940
940
fsync_fname (tmppath , true);
941
- fsync_fname ("pg_replslot" , true);
941
+ fsync_fname (PG_REPLSLOT_DIR , true);
942
942
END_CRIT_SECTION ();
943
943
}
944
944
else
@@ -1016,7 +1016,7 @@ ReplicationSlotSave(void)
1016
1016
1017
1017
Assert (MyReplicationSlot != NULL );
1018
1018
1019
- sprintf (path , "pg_replslot /%s" , NameStr (MyReplicationSlot -> data .name ));
1019
+ sprintf (path , "%s /%s" , PG_REPLSLOT_DIR , NameStr (MyReplicationSlot -> data .name ));
1020
1020
SaveSlotToPath (MyReplicationSlot , path , ERROR );
1021
1021
}
1022
1022
@@ -1881,7 +1881,7 @@ CheckPointReplicationSlots(bool is_shutdown)
1881
1881
continue ;
1882
1882
1883
1883
/* 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 ));
1885
1885
1886
1886
/*
1887
1887
* Slot's data is not flushed each time the confirmed_flush LSN is
@@ -1922,17 +1922,17 @@ StartupReplicationSlots(void)
1922
1922
elog (DEBUG1 , "starting up replication slots" );
1923
1923
1924
1924
/* 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 )
1927
1927
{
1928
- char path [MAXPGPATH + 12 ];
1928
+ char path [MAXPGPATH + sizeof ( PG_REPLSLOT_DIR ) ];
1929
1929
PGFileType de_type ;
1930
1930
1931
1931
if (strcmp (replication_de -> d_name , "." ) == 0 ||
1932
1932
strcmp (replication_de -> d_name , ".." ) == 0 )
1933
1933
continue ;
1934
1934
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 );
1936
1936
de_type = get_dirent_type (path , replication_de , false, DEBUG1 );
1937
1937
1938
1938
/* we're only creating directories here, skip if it's not our's */
@@ -1949,7 +1949,7 @@ StartupReplicationSlots(void)
1949
1949
path )));
1950
1950
continue ;
1951
1951
}
1952
- fsync_fname ("pg_replslot" , true);
1952
+ fsync_fname (PG_REPLSLOT_DIR , true);
1953
1953
continue ;
1954
1954
}
1955
1955
@@ -1987,8 +1987,8 @@ CreateSlotOnDisk(ReplicationSlot *slot)
1987
1987
* takes out the lock, if we'd take the lock here, we'd deadlock.
1988
1988
*/
1989
1989
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 ));
1992
1992
1993
1993
/*
1994
1994
* It's just barely possible that some previous effort to create or drop a
@@ -2027,7 +2027,7 @@ CreateSlotOnDisk(ReplicationSlot *slot)
2027
2027
START_CRIT_SECTION ();
2028
2028
2029
2029
fsync_fname (path , true);
2030
- fsync_fname ("pg_replslot" , true);
2030
+ fsync_fname (PG_REPLSLOT_DIR , true);
2031
2031
2032
2032
END_CRIT_SECTION ();
2033
2033
}
@@ -2170,7 +2170,7 @@ SaveSlotToPath(ReplicationSlot *slot, const char *dir, int elevel)
2170
2170
2171
2171
fsync_fname (path , false);
2172
2172
fsync_fname (dir , true);
2173
- fsync_fname ("pg_replslot" , true);
2173
+ fsync_fname (PG_REPLSLOT_DIR , true);
2174
2174
2175
2175
END_CRIT_SECTION ();
2176
2176
@@ -2195,8 +2195,8 @@ RestoreSlotFromDisk(const char *name)
2195
2195
{
2196
2196
ReplicationSlotOnDisk cp ;
2197
2197
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 ];
2200
2200
int fd ;
2201
2201
bool restored = false;
2202
2202
int readBytes ;
@@ -2205,7 +2205,7 @@ RestoreSlotFromDisk(const char *name)
2205
2205
/* no need to lock here, no concurrent access allowed yet */
2206
2206
2207
2207
/* delete temp file if it exists */
2208
- sprintf (slotdir , "pg_replslot /%s" , name );
2208
+ sprintf (slotdir , "%s /%s" , PG_REPLSLOT_DIR , name );
2209
2209
sprintf (path , "%s/state.tmp" , slotdir );
2210
2210
if (unlink (path ) < 0 && errno != ENOENT )
2211
2211
ereport (PANIC ,
@@ -2332,7 +2332,7 @@ RestoreSlotFromDisk(const char *name)
2332
2332
(errmsg ("could not remove directory \"%s\"" ,
2333
2333
slotdir )));
2334
2334
}
2335
- fsync_fname ("pg_replslot" , true);
2335
+ fsync_fname (PG_REPLSLOT_DIR , true);
2336
2336
return ;
2337
2337
}
2338
2338
0 commit comments