LCOV - code coverage report
Current view: top level - src/backend/postmaster - auxprocess.c (source / functions) Coverage Total Hit
Test: Code coverage Lines: 100.0 % 24 24
Test Date: 2026-01-26 10:56:24 Functions: 100.0 % 2 2
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
Branches: 50.0 % 6 3

             Branch data     Line data    Source code
       1                 :             : /*-------------------------------------------------------------------------
       2                 :             :  * auxprocess.c
       3                 :             :  *        functions related to auxiliary processes.
       4                 :             :  *
       5                 :             :  *
       6                 :             :  * Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
       7                 :             :  * Portions Copyright (c) 1994, Regents of the University of California
       8                 :             :  *
       9                 :             :  * IDENTIFICATION
      10                 :             :  *        src/backend/postmaster/auxprocess.c
      11                 :             :  *-------------------------------------------------------------------------
      12                 :             :  */
      13                 :             : #include "postgres.h"
      14                 :             : 
      15                 :             : #include <unistd.h>
      16                 :             : #include <signal.h>
      17                 :             : 
      18                 :             : #include "miscadmin.h"
      19                 :             : #include "pgstat.h"
      20                 :             : #include "postmaster/auxprocess.h"
      21                 :             : #include "storage/condition_variable.h"
      22                 :             : #include "storage/ipc.h"
      23                 :             : #include "storage/proc.h"
      24                 :             : #include "storage/procsignal.h"
      25                 :             : #include "utils/memutils.h"
      26                 :             : #include "utils/ps_status.h"
      27                 :             : 
      28                 :             : 
      29                 :             : static void ShutdownAuxiliaryProcess(int code, Datum arg);
      30                 :             : 
      31                 :             : 
      32                 :             : /*
      33                 :             :  *       AuxiliaryProcessMainCommon
      34                 :             :  *
      35                 :             :  *       Common initialization code for auxiliary processes, such as the bgwriter,
      36                 :             :  *       walwriter, walreceiver, and the startup process.
      37                 :             :  */
      38                 :             : void
      39                 :           8 : AuxiliaryProcessMainCommon(void)
      40                 :             : {
      41         [ +  - ]:           8 :         Assert(IsUnderPostmaster);
      42                 :             : 
      43                 :             :         /* Release postmaster's working memory context */
      44         [ -  + ]:           8 :         if (PostmasterContext)
      45                 :             :         {
      46                 :           8 :                 MemoryContextDelete(PostmasterContext);
      47                 :           8 :                 PostmasterContext = NULL;
      48                 :           8 :         }
      49                 :             : 
      50                 :           8 :         init_ps_display(NULL);
      51                 :             : 
      52         [ +  - ]:           8 :         Assert(GetProcessingMode() == InitProcessing);
      53                 :             : 
      54                 :           8 :         IgnoreSystemIndexes = true;
      55                 :             : 
      56                 :             :         /*
      57                 :             :          * As an auxiliary process, we aren't going to do the full InitPostgres
      58                 :             :          * pushups, but there are a couple of things that need to get lit up even
      59                 :             :          * in an auxiliary process.
      60                 :             :          */
      61                 :             : 
      62                 :             :         /*
      63                 :             :          * Create a PGPROC so we can use LWLocks and access shared memory.
      64                 :             :          */
      65                 :           8 :         InitAuxiliaryProcess();
      66                 :             : 
      67                 :           8 :         BaseInit();
      68                 :             : 
      69                 :           8 :         ProcSignalInit(NULL, 0);
      70                 :             : 
      71                 :             :         /*
      72                 :             :          * Auxiliary processes don't run transactions, but they may need a
      73                 :             :          * resource owner anyway to manage buffer pins acquired outside
      74                 :             :          * transactions (and, perhaps, other things in future).
      75                 :             :          */
      76                 :           8 :         CreateAuxProcessResourceOwner();
      77                 :             : 
      78                 :             : 
      79                 :             :         /* Initialize backend status information */
      80                 :           8 :         pgstat_beinit();
      81                 :           8 :         pgstat_bestart_initial();
      82                 :           8 :         pgstat_bestart_final();
      83                 :             : 
      84                 :             :         /* register a before-shutdown callback for LWLock cleanup */
      85                 :           8 :         before_shmem_exit(ShutdownAuxiliaryProcess, 0);
      86                 :             : 
      87                 :           8 :         SetProcessingMode(NormalProcessing);
      88                 :           8 : }
      89                 :             : 
      90                 :             : /*
      91                 :             :  * Begin shutdown of an auxiliary process.  This is approximately the equivalent
      92                 :             :  * of ShutdownPostgres() in postinit.c.  We can't run transactions in an
      93                 :             :  * auxiliary process, so most of the work of AbortTransaction() is not needed,
      94                 :             :  * but we do need to make sure we've released any LWLocks we are holding.
      95                 :             :  * (This is only critical during an error exit.)
      96                 :             :  */
      97                 :             : static void
      98                 :           8 : ShutdownAuxiliaryProcess(int code, Datum arg)
      99                 :             : {
     100                 :           8 :         LWLockReleaseAll();
     101                 :           8 :         ConditionVariableCancelSleep();
     102                 :           8 :         pgstat_report_wait_end();
     103                 :           8 : }
        

Generated by: LCOV version 2.3.2-1