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

Generated by: LCOV version 1.14