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

Generated by: LCOV version 1.14