1 /*-------------------------------------------------------------------------
4 * This file contains general postgres administration and initialization
5 * stuff that used to be spread out between the following files:
6 * globals.h global variables
7 * pdir.h directory path crud
8 * pinit.h postgres initialization
9 * pmod.h processing modes
10 * Over time, this has also become the preferred place for widely known
11 * resource-limitation stuff, such as work_mem and check_stack_depth().
13 * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
14 * Portions Copyright (c) 1994, Regents of the University of California
16 * $PostgreSQL: pgsql/src/include/miscadmin.h,v 1.195 2007/07/25 12:22:53 mha Exp $
19 * some of the information in this file should be moved to other files.
21 *-------------------------------------------------------------------------
27 #define PG_VERSIONSTR "postgres (PostgreSQL) " PG_VERSION "\n"
30 /*****************************************************************************
31 * System interrupt and critical section handling
33 * There are two types of interrupts that a running backend needs to accept
34 * without messing up its state: QueryCancel (SIGINT) and ProcDie (SIGTERM).
35 * In both cases, we need to be able to clean up the current transaction
36 * gracefully, so we can't respond to the interrupt instantaneously ---
37 * there's no guarantee that internal data structures would be self-consistent
38 * if the code is interrupted at an arbitrary instant. Instead, the signal
39 * handlers set flags that are checked periodically during execution.
41 * The CHECK_FOR_INTERRUPTS() macro is called at strategically located spots
42 * where it is normally safe to accept a cancel or die interrupt. In some
43 * cases, we invoke CHECK_FOR_INTERRUPTS() inside low-level subroutines that
44 * might sometimes be called in contexts that do *not* want to allow a cancel
45 * or die interrupt. The HOLD_INTERRUPTS() and RESUME_INTERRUPTS() macros
46 * allow code to ensure that no cancel or die interrupt will be accepted,
47 * even if CHECK_FOR_INTERRUPTS() gets called in a subroutine. The interrupt
48 * will be held off until CHECK_FOR_INTERRUPTS() is done outside any
49 * HOLD_INTERRUPTS() ... RESUME_INTERRUPTS() section.
51 * Special mechanisms are used to let an interrupt be accepted when we are
52 * waiting for a lock or when we are waiting for command input (but, of
53 * course, only if the interrupt holdoff counter is zero). See the
54 * related code for details.
56 * A related, but conceptually distinct, mechanism is the "critical section"
57 * mechanism. A critical section not only holds off cancel/die interrupts,
58 * but causes any ereport(ERROR) or ereport(FATAL) to become ereport(PANIC)
59 * --- that is, a system-wide reset is forced. Needless to say, only really
60 * *critical* code should be marked as a critical section! Currently, this
61 * mechanism is only used for XLOG-related code.
63 *****************************************************************************/
66 /* these are marked volatile because they are set by signal handlers: */
67 extern PGDLLIMPORT volatile bool InterruptPending;
68 extern volatile bool QueryCancelPending;
69 extern volatile bool ProcDiePending;
71 /* these are marked volatile because they are examined by signal handlers: */
72 extern volatile bool ImmediateInterruptOK;
73 extern PGDLLIMPORT volatile uint32 InterruptHoldoffCount;
74 extern PGDLLIMPORT volatile uint32 CritSectionCount;
76 /* in tcop/postgres.c */
77 extern void ProcessInterrupts(void);
81 #define CHECK_FOR_INTERRUPTS() \
83 if (InterruptPending) \
84 ProcessInterrupts(); \
88 #define CHECK_FOR_INTERRUPTS() \
90 if (UNBLOCKED_SIGNAL_QUEUE()) \
91 pgwin32_dispatch_queued_signals(); \
92 if (InterruptPending) \
93 ProcessInterrupts(); \
98 #define HOLD_INTERRUPTS() (InterruptHoldoffCount++)
100 #define RESUME_INTERRUPTS() \
102 Assert(InterruptHoldoffCount > 0); \
103 InterruptHoldoffCount--; \
106 #define START_CRIT_SECTION() (CritSectionCount++)
108 #define END_CRIT_SECTION() \
110 Assert(CritSectionCount > 0); \
111 CritSectionCount--; \
115 /*****************************************************************************
117 *****************************************************************************/
120 * from utils/init/globals.c
122 extern pid_t PostmasterPid;
123 extern bool IsPostmasterEnvironment;
124 extern bool IsUnderPostmaster;
126 extern bool ExitOnAnyError;
128 extern PGDLLIMPORT char *DataDir;
130 extern PGDLLIMPORT int NBuffers;
131 extern int MaxBackends;
132 extern int MaxConnections;
134 extern PGDLLIMPORT int MyProcPid;
135 extern PGDLLIMPORT struct Port *MyProcPort;
136 extern long MyCancelKey;
138 extern char OutputFileName[];
139 extern PGDLLIMPORT char my_exec_path[];
140 extern char pkglib_path[];
143 extern char postgres_exec_path[];
147 * done in storage/backendid.h for now.
149 * extern BackendId MyBackendId;
151 extern PGDLLIMPORT Oid MyDatabaseId;
153 extern PGDLLIMPORT Oid MyDatabaseTableSpace;
156 * Date/Time Configuration
158 * DateStyle defines the output formatting choice for date/time types:
159 * USE_POSTGRES_DATES specifies traditional Postgres format
160 * USE_ISO_DATES specifies ISO-compliant format
161 * USE_SQL_DATES specifies Oracle/Ingres-compliant format
162 * USE_GERMAN_DATES specifies German-style dd.mm/yyyy
164 * DateOrder defines the field order to be assumed when reading an
165 * ambiguous date (anything not in YYYY-MM-DD format, with a four-digit
166 * year field first, is taken to be ambiguous):
167 * DATEORDER_YMD specifies field order yy-mm-dd
168 * DATEORDER_DMY specifies field order dd-mm-yy ("European" convention)
169 * DATEORDER_MDY specifies field order mm-dd-yy ("US" convention)
171 * In the Postgres and SQL DateStyles, DateOrder also selects output field
172 * order: day comes before month in DMY style, else month comes before day.
174 * The user-visible "DateStyle" run-time parameter subsumes both of these.
177 /* valid DateStyle values */
178 #define USE_POSTGRES_DATES 0
179 #define USE_ISO_DATES 1
180 #define USE_SQL_DATES 2
181 #define USE_GERMAN_DATES 3
182 #define USE_XSD_DATES 4
184 /* valid DateOrder values */
185 #define DATEORDER_YMD 0
186 #define DATEORDER_DMY 1
187 #define DATEORDER_MDY 2
189 extern int DateStyle;
190 extern int DateOrder;
193 * HasCTZSet is true if user has set timezone as a numeric offset from UTC.
194 * If so, CTimeZone is the timezone offset in seconds (using the Unix-ish
195 * sign convention, ie, positive offset is west of UTC, rather than the
196 * SQL-ish convention that positive is east of UTC).
198 extern bool HasCTZSet;
199 extern int CTimeZone;
201 #define MAXTZLEN 10 /* max TZ name len, not counting tr. null */
203 extern bool enableFsync;
204 extern bool allowSystemTableMods;
205 extern PGDLLIMPORT int work_mem;
206 extern PGDLLIMPORT int maintenance_work_mem;
208 extern int VacuumCostPageHit;
209 extern int VacuumCostPageMiss;
210 extern int VacuumCostPageDirty;
211 extern int VacuumCostLimit;
212 extern int VacuumCostDelay;
214 extern int VacuumCostBalance;
215 extern bool VacuumCostActive;
218 /* in tcop/postgres.c */
219 extern void check_stack_depth(void);
222 /*****************************************************************************
224 * POSTGRES directory path definitions. *
225 *****************************************************************************/
227 extern char *DatabasePath;
229 /* now in utils/init/miscinit.c */
230 extern void SetDatabasePath(const char *path);
232 extern char *GetUserNameFromId(Oid roleid);
233 extern Oid GetUserId(void);
234 extern void SetUserId(Oid userid);
235 extern Oid GetOuterUserId(void);
236 extern Oid GetSessionUserId(void);
237 extern void InitializeSessionUserId(const char *rolename);
238 extern void InitializeSessionUserIdStandalone(void);
239 extern void AtAbort_UserId(void);
240 extern void SetSessionAuthorization(Oid userid, bool is_superuser);
241 extern Oid GetCurrentRoleId(void);
242 extern void SetCurrentRoleId(Oid roleid, bool is_superuser);
244 extern void SetDataDir(const char *dir);
245 extern void ChangeToDataDir(void);
246 extern char *make_absolute_path(const char *path);
248 /* in utils/misc/superuser.c */
249 extern bool superuser(void); /* current user is superuser */
250 extern bool superuser_arg(Oid roleid); /* given user is superuser */
253 /*****************************************************************************
255 * POSTGRES processing mode definitions. *
256 *****************************************************************************/
260 * There are three processing modes in POSTGRES. They are
261 * BootstrapProcessing or "bootstrap," InitProcessing or
262 * "initialization," and NormalProcessing or "normal."
264 * The first two processing modes are used during special times. When the
265 * system state indicates bootstrap processing, transactions are all given
266 * transaction id "one" and are consequently guaranteed to commit. This mode
267 * is used during the initial generation of template databases.
269 * Initialization mode: used while starting a backend, until all normal
270 * initialization is complete. Some code behaves differently when executed
271 * in this mode to enable system bootstrapping.
273 * If a POSTGRES binary is in normal mode, then all code may be executed
277 typedef enum ProcessingMode
279 BootstrapProcessing, /* bootstrap creation of template database */
280 InitProcessing, /* initializing system */
281 NormalProcessing /* normal processing */
284 extern ProcessingMode Mode;
286 #define IsBootstrapProcessingMode() ((bool)(Mode == BootstrapProcessing))
287 #define IsInitProcessingMode() ((bool)(Mode == InitProcessing))
288 #define IsNormalProcessingMode() ((bool)(Mode == NormalProcessing))
290 #define SetProcessingMode(mode) \
292 AssertArg((mode) == BootstrapProcessing || \
293 (mode) == InitProcessing || \
294 (mode) == NormalProcessing); \
298 #define GetProcessingMode() Mode
301 /*****************************************************************************
303 * POSTGRES initialization and cleanup definitions. *
304 *****************************************************************************/
306 /* in utils/init/postinit.c */
307 extern bool InitPostgres(const char *in_dbname, Oid dboid, const char *username,
309 extern void BaseInit(void);
311 /* in utils/init/miscinit.c */
312 extern bool IgnoreSystemIndexes;
313 extern char *shared_preload_libraries_string;
314 extern char *local_preload_libraries_string;
316 extern void SetReindexProcessing(Oid heapOid, Oid indexOid);
317 extern void ResetReindexProcessing(void);
318 extern bool ReindexIsProcessingHeap(Oid heapOid);
319 extern bool ReindexIsProcessingIndex(Oid indexOid);
320 extern void CreateDataDirLockFile(bool amPostmaster);
321 extern void CreateSocketLockFile(const char *socketfile, bool amPostmaster);
322 extern void TouchSocketLockFile(void);
323 extern void RecordSharedMemoryInLockFile(unsigned long id1,
325 extern void ValidatePgVersion(const char *path);
326 extern void process_shared_preload_libraries(void);
327 extern void process_local_preload_libraries(void);
329 #endif /* MISCADMIN_H */