LCOV - code coverage report
Current view: top level - src/backend/postmaster - auxprocess.c (source / functions) Coverage Total Hit
Test: PostgreSQL 19devel Lines: 100.0 % 21 21
Test Date: 2026-03-08 08:14:37 Functions: 100.0 % 2 2
Legend: Lines:     hit not hit

            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              : #include "utils/wait_event.h"
      28              : 
      29              : 
      30              : static void ShutdownAuxiliaryProcess(int code, Datum arg);
      31              : 
      32              : 
      33              : /*
      34              :  *   AuxiliaryProcessMainCommon
      35              :  *
      36              :  *   Common initialization code for auxiliary processes, such as the bgwriter,
      37              :  *   walwriter, walreceiver, and the startup process.
      38              :  */
      39              : void
      40         4630 : AuxiliaryProcessMainCommon(void)
      41              : {
      42              :     Assert(IsUnderPostmaster);
      43              : 
      44              :     /* Release postmaster's working memory context */
      45         4630 :     if (PostmasterContext)
      46              :     {
      47         4630 :         MemoryContextDelete(PostmasterContext);
      48         4630 :         PostmasterContext = NULL;
      49              :     }
      50              : 
      51         4630 :     init_ps_display(NULL);
      52              : 
      53              :     Assert(GetProcessingMode() == InitProcessing);
      54              : 
      55         4630 :     IgnoreSystemIndexes = true;
      56              : 
      57              :     /*
      58              :      * As an auxiliary process, we aren't going to do the full InitPostgres
      59              :      * pushups, but there are a couple of things that need to get lit up even
      60              :      * in an auxiliary process.
      61              :      */
      62              : 
      63              :     /*
      64              :      * Create a PGPROC so we can use LWLocks and access shared memory.
      65              :      */
      66         4630 :     InitAuxiliaryProcess();
      67              : 
      68         4630 :     BaseInit();
      69              : 
      70         4630 :     ProcSignalInit(NULL, 0);
      71              : 
      72              :     /*
      73              :      * Auxiliary processes don't run transactions, but they may need a
      74              :      * resource owner anyway to manage buffer pins acquired outside
      75              :      * transactions (and, perhaps, other things in future).
      76              :      */
      77         4630 :     CreateAuxProcessResourceOwner();
      78              : 
      79              : 
      80              :     /* Initialize backend status information */
      81         4630 :     pgstat_beinit();
      82         4630 :     pgstat_bestart_initial();
      83         4630 :     pgstat_bestart_final();
      84              : 
      85              :     /* register a before-shutdown callback for LWLock cleanup */
      86         4630 :     before_shmem_exit(ShutdownAuxiliaryProcess, 0);
      87              : 
      88         4630 :     SetProcessingMode(NormalProcessing);
      89         4630 : }
      90              : 
      91              : /*
      92              :  * Begin shutdown of an auxiliary process.  This is approximately the equivalent
      93              :  * of ShutdownPostgres() in postinit.c.  We can't run transactions in an
      94              :  * auxiliary process, so most of the work of AbortTransaction() is not needed,
      95              :  * but we do need to make sure we've released any LWLocks we are holding.
      96              :  * (This is only critical during an error exit.)
      97              :  */
      98              : static void
      99         4630 : ShutdownAuxiliaryProcess(int code, Datum arg)
     100              : {
     101         4630 :     LWLockReleaseAll();
     102         4630 :     ConditionVariableCancelSleep();
     103         4630 :     pgstat_report_wait_end();
     104         4630 : }
        

Generated by: LCOV version 2.0-1