@@ -219,8 +219,8 @@ test_slru_shmem_startup(void)
219219 */
220220 const bool long_segment_names = true;
221221 const char slru_dir_name [] = "pg_test_slru" ;
222- int test_tranche_id ;
223- int test_buffer_tranche_id ;
222+ int test_tranche_id = -1 ;
223+ int test_buffer_tranche_id = -1 ;
224224
225225 if (prev_shmem_startup_hook )
226226 prev_shmem_startup_hook ();
@@ -231,10 +231,19 @@ test_slru_shmem_startup(void)
231231 */
232232 (void ) MakePGDirectory (slru_dir_name );
233233
234- /* initialize the SLRU facility */
235- test_tranche_id = LWLockNewTrancheId ("test_slru_tranche" );
236-
237- test_buffer_tranche_id = LWLockNewTrancheId ("test_buffer_tranche" );
234+ /*
235+ * Initialize the SLRU facility.
236+ *
237+ * In EXEC_BACKEND builds, the shmem_startup_hook is called in the
238+ * postmaster and in each backend, but we only need to generate the LWLock
239+ * tranches once. Note that these IDs are not used by SimpleLruInit() in
240+ * the IsUnderPostmaster (i.e., backend) case.
241+ */
242+ if (!IsUnderPostmaster )
243+ {
244+ test_tranche_id = LWLockNewTrancheId ("test_slru_tranche" );
245+ test_buffer_tranche_id = LWLockNewTrancheId ("test_buffer_tranche" );
246+ }
238247
239248 TestSlruCtl -> PagePrecedes = test_slru_page_precedes_logically ;
240249 SimpleLruInit (TestSlruCtl , "TestSLRU" ,
0 commit comments