| 1 | /*------------------------------------------------------------------------- |
| 2 | * |
| 3 | * globals.c |
| 4 | * global variable declarations |
| 5 | * |
| 6 | * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group |
| 7 | * Portions Copyright (c) 1994, Regents of the University of California |
| 8 | * |
| 9 | * |
| 10 | * IDENTIFICATION |
| 11 | * src/backend/utils/init/globals.c |
| 12 | * |
| 13 | * NOTES |
| 14 | * Globals used all over the place should be declared here and not |
| 15 | * in other modules. |
| 16 | * |
| 17 | *------------------------------------------------------------------------- |
| 18 | */ |
| 19 | #include "postgres.h" |
| 20 | |
| 21 | #include "common/file_perm.h" |
| 22 | #include "libpq/libpq-be.h" |
| 23 | #include "libpq/pqcomm.h" |
| 24 | #include "miscadmin.h" |
| 25 | #include "storage/backendid.h" |
| 26 | |
| 27 | |
| 28 | ProtocolVersion FrontendProtocol; |
| 29 | |
| 30 | volatile sig_atomic_t InterruptPending = false; |
| 31 | volatile sig_atomic_t QueryCancelPending = false; |
| 32 | volatile sig_atomic_t ProcDiePending = false; |
| 33 | volatile sig_atomic_t ClientConnectionLost = false; |
| 34 | volatile sig_atomic_t IdleInTransactionSessionTimeoutPending = false; |
| 35 | volatile sig_atomic_t ConfigReloadPending = false; |
| 36 | volatile uint32 InterruptHoldoffCount = 0; |
| 37 | volatile uint32 QueryCancelHoldoffCount = 0; |
| 38 | volatile uint32 CritSectionCount = 0; |
| 39 | |
| 40 | int MyProcPid; |
| 41 | pg_time_t MyStartTime; |
| 42 | TimestampTz MyStartTimestamp; |
| 43 | struct Port *MyProcPort; |
| 44 | int32 MyCancelKey; |
| 45 | int MyPMChildSlot; |
| 46 | |
| 47 | /* |
| 48 | * MyLatch points to the latch that should be used for signal handling by the |
| 49 | * current process. It will either point to a process local latch if the |
| 50 | * current process does not have a PGPROC entry in that moment, or to |
| 51 | * PGPROC->procLatch if it has. Thus it can always be used in signal handlers, |
| 52 | * without checking for its existence. |
| 53 | */ |
| 54 | struct Latch *MyLatch; |
| 55 | |
| 56 | /* |
| 57 | * DataDir is the absolute path to the top level of the PGDATA directory tree. |
| 58 | * Except during early startup, this is also the server's working directory; |
| 59 | * most code therefore can simply use relative paths and not reference DataDir |
| 60 | * explicitly. |
| 61 | */ |
| 62 | char *DataDir = NULL; |
| 63 | |
| 64 | /* |
| 65 | * Mode of the data directory. The default is 0700 but it may be changed in |
| 66 | * checkDataDir() to 0750 if the data directory actually has that mode. |
| 67 | */ |
| 68 | int data_directory_mode = PG_DIR_MODE_OWNER; |
| 69 | |
| 70 | char OutputFileName[MAXPGPATH]; /* debugging output file */ |
| 71 | |
| 72 | char my_exec_path[MAXPGPATH]; /* full path to my executable */ |
| 73 | char pkglib_path[MAXPGPATH]; /* full path to lib directory */ |
| 74 | |
| 75 | #ifdef EXEC_BACKEND |
| 76 | char postgres_exec_path[MAXPGPATH]; /* full path to backend */ |
| 77 | |
| 78 | /* note: currently this is not valid in backend processes */ |
| 79 | #endif |
| 80 | |
| 81 | BackendId MyBackendId = InvalidBackendId; |
| 82 | |
| 83 | BackendId ParallelMasterBackendId = InvalidBackendId; |
| 84 | |
| 85 | Oid MyDatabaseId = InvalidOid; |
| 86 | |
| 87 | Oid MyDatabaseTableSpace = InvalidOid; |
| 88 | |
| 89 | /* |
| 90 | * DatabasePath is the path (relative to DataDir) of my database's |
| 91 | * primary directory, ie, its directory in the default tablespace. |
| 92 | */ |
| 93 | char *DatabasePath = NULL; |
| 94 | |
| 95 | pid_t PostmasterPid = 0; |
| 96 | |
| 97 | /* |
| 98 | * IsPostmasterEnvironment is true in a postmaster process and any postmaster |
| 99 | * child process; it is false in a standalone process (bootstrap or |
| 100 | * standalone backend). IsUnderPostmaster is true in postmaster child |
| 101 | * processes. Note that "child process" includes all children, not only |
| 102 | * regular backends. These should be set correctly as early as possible |
| 103 | * in the execution of a process, so that error handling will do the right |
| 104 | * things if an error should occur during process initialization. |
| 105 | * |
| 106 | * These are initialized for the bootstrap/standalone case. |
| 107 | */ |
| 108 | bool IsPostmasterEnvironment = false; |
| 109 | bool IsUnderPostmaster = false; |
| 110 | bool IsBinaryUpgrade = false; |
| 111 | bool IsBackgroundWorker = false; |
| 112 | |
| 113 | bool ExitOnAnyError = false; |
| 114 | |
| 115 | int DateStyle = USE_ISO_DATES; |
| 116 | int DateOrder = DATEORDER_MDY; |
| 117 | int IntervalStyle = INTSTYLE_POSTGRES; |
| 118 | |
| 119 | bool enableFsync = true; |
| 120 | bool allowSystemTableMods = false; |
| 121 | int work_mem = 1024; |
| 122 | int maintenance_work_mem = 16384; |
| 123 | int max_parallel_maintenance_workers = 2; |
| 124 | |
| 125 | /* |
| 126 | * Primary determinants of sizes of shared-memory structures. |
| 127 | * |
| 128 | * MaxBackends is computed by PostmasterMain after modules have had a chance to |
| 129 | * register background workers. |
| 130 | */ |
| 131 | int NBuffers = 1000; |
| 132 | int MaxConnections = 90; |
| 133 | int max_worker_processes = 8; |
| 134 | int max_parallel_workers = 8; |
| 135 | int MaxBackends = 0; |
| 136 | |
| 137 | int VacuumCostPageHit = 1; /* GUC parameters for vacuum */ |
| 138 | int VacuumCostPageMiss = 10; |
| 139 | int VacuumCostPageDirty = 20; |
| 140 | int VacuumCostLimit = 200; |
| 141 | double VacuumCostDelay = 0; |
| 142 | |
| 143 | int VacuumPageHit = 0; |
| 144 | int VacuumPageMiss = 0; |
| 145 | int VacuumPageDirty = 0; |
| 146 | |
| 147 | int VacuumCostBalance = 0; /* working state for vacuum */ |
| 148 | bool VacuumCostActive = false; |
| 149 | |
| 150 | double vacuum_cleanup_index_scale_factor; |
| 151 | |