Age Owner Branch data TLA 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
27 heikki.linnakangas@i 44 :GNC 3223 : AuxiliaryProcessMainCommon(void)
45 : : {
983 andres@anarazel.de 46 [ - + ]:CBC 3223 : Assert(IsUnderPostmaster);
47 : :
48 : : /* Release postmaster's working memory context */
27 heikki.linnakangas@i 49 [ + - ]:GNC 3223 : if (PostmasterContext)
50 : : {
51 : 3223 : MemoryContextDelete(PostmasterContext);
52 : 3223 : PostmasterContext = NULL;
53 : : }
54 : :
983 andres@anarazel.de 55 :CBC 3223 : init_ps_display(NULL);
56 : :
57 : 3223 : SetProcessingMode(BootstrapProcessing);
58 : 3223 : 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 : 3223 : InitAuxiliaryProcess();
70 : :
71 : 3223 : BaseInit();
72 : :
42 heikki.linnakangas@i 73 :GNC 3223 : 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 : : */
983 andres@anarazel.de 80 :CBC 3223 : CreateAuxProcessResourceOwner();
81 : :
82 : :
83 : : /* Initialize backend status information */
84 : 3223 : pgstat_beinit();
85 : 3223 : pgstat_bestart();
86 : :
87 : : /* register a before-shutdown callback for LWLock cleanup */
88 : 3223 : before_shmem_exit(ShutdownAuxiliaryProcess, 0);
89 : :
90 : 3223 : SetProcessingMode(NormalProcessing);
983 andres@anarazel.de 91 :GIC 3223 : }
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
983 andres@anarazel.de 101 :CBC 2251 : ShutdownAuxiliaryProcess(int code, Datum arg)
102 : : {
103 : 2251 : LWLockReleaseAll();
104 : 2251 : ConditionVariableCancelSleep();
105 : 2251 : pgstat_report_wait_end();
106 : 2251 : }
|