]> granicus.if.org Git - postgresql/blob - src/include/miscadmin.h
Update copyright to 2004.
[postgresql] / src / include / miscadmin.h
1 /*-------------------------------------------------------------------------
2  *
3  * miscadmin.h
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().
12  *
13  * Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
14  * Portions Copyright (c) 1994, Regents of the University of California
15  *
16  * $PostgreSQL: pgsql/src/include/miscadmin.h,v 1.166 2004/08/29 04:13:03 momjian Exp $
17  *
18  * NOTES
19  *        some of the information in this file should be moved to other files.
20  *
21  *-------------------------------------------------------------------------
22  */
23 #ifndef MISCADMIN_H
24 #define MISCADMIN_H
25
26
27 #define PG_VERSIONSTR "postgres (PostgreSQL) " PG_VERSION "\n"
28
29
30 /*****************************************************************************
31  *        System interrupt and critical section handling
32  *
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.
40  *
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.
50  *
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.
55  *
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.
62  *
63  *****************************************************************************/
64
65 /* in globals.c */
66 /* these are marked volatile because they are set by signal handlers: */
67 extern DLLIMPORT volatile bool InterruptPending;
68 extern volatile bool QueryCancelPending;
69 extern volatile bool ProcDiePending;
70
71 /* these are marked volatile because they are examined by signal handlers: */
72 extern volatile bool ImmediateInterruptOK;
73 extern volatile uint32 InterruptHoldoffCount;
74 extern volatile uint32 CritSectionCount;
75
76 /* in tcop/postgres.c */
77 extern void ProcessInterrupts(void);
78
79 #ifndef WIN32
80
81 #define CHECK_FOR_INTERRUPTS() \
82 do { \
83         if (InterruptPending) \
84                 ProcessInterrupts(); \
85 } while(0)
86
87 #else  /* WIN32 */
88
89 #define CHECK_FOR_INTERRUPTS() \
90 do { \
91         if (WaitForSingleObject(pgwin32_signal_event,0) == WAIT_OBJECT_0) \
92                 pgwin32_dispatch_queued_signals(); \
93         if (InterruptPending) \
94                 ProcessInterrupts(); \
95 } while(0)
96
97 #endif /* WIN32 */
98
99
100 #define HOLD_INTERRUPTS()  (InterruptHoldoffCount++)
101
102 #define RESUME_INTERRUPTS() \
103 do { \
104         Assert(InterruptHoldoffCount > 0); \
105         InterruptHoldoffCount--; \
106 } while(0)
107
108 #define START_CRIT_SECTION()  (CritSectionCount++)
109
110 #define END_CRIT_SECTION() \
111 do { \
112         Assert(CritSectionCount > 0); \
113         CritSectionCount--; \
114 } while(0)
115
116
117 /*****************************************************************************
118  *        globals.h --                                                                                                                   *
119  *****************************************************************************/
120
121 /*
122  * from utils/init/globals.c
123  */
124 extern pid_t PostmasterPid;
125 extern bool IsPostmasterEnvironment;
126 extern bool IsUnderPostmaster;
127
128 extern bool ExitOnAnyError;
129
130 extern char *DataDir;
131
132 extern DLLIMPORT int NBuffers;
133 extern int      MaxBackends;
134
135 extern DLLIMPORT int MyProcPid;
136 extern struct Port *MyProcPort;
137 extern long MyCancelKey;
138
139 extern char OutputFileName[];
140 extern char my_exec_path[];
141 extern char pkglib_path[];
142 #ifdef EXEC_BACKEND
143 extern char postgres_exec_path[];
144 #endif
145
146 /*
147  * done in storage/backendid.h for now.
148  *
149  * extern BackendId    MyBackendId;
150  */
151 extern DLLIMPORT Oid MyDatabaseId;
152
153 extern DLLIMPORT Oid MyDatabaseTableSpace;
154
155 /*
156  * Date/Time Configuration
157  *
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
163  *
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)
170  *
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.
173  *
174  * The user-visible "DateStyle" run-time parameter subsumes both of these.
175  */
176
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
183 /* valid DateOrder values */
184 #define DATEORDER_YMD                   0
185 #define DATEORDER_DMY                   1
186 #define DATEORDER_MDY                   2
187
188 extern int      DateStyle;
189 extern int      DateOrder;
190
191 /*
192  * HasCTZSet is true if user has set timezone as a numeric offset from UTC.
193  * If so, CTimeZone is the timezone offset in seconds (using the Unix-ish
194  * sign convention, ie, positive offset is west of UTC, rather than the
195  * SQL-ish convention that positive is east of UTC).
196  */
197 extern bool HasCTZSet;
198 extern int      CTimeZone;
199
200 #define MAXTZLEN                10              /* max TZ name len, not counting tr. null */
201
202 extern bool enableFsync;
203 extern bool allowSystemTableMods;
204 extern DLLIMPORT int work_mem;
205 extern DLLIMPORT int maintenance_work_mem;
206
207 extern int      VacuumCostPageHit;
208 extern int      VacuumCostPageMiss;
209 extern int      VacuumCostPageDirty;
210 extern int      VacuumCostLimit;
211 extern int      VacuumCostDelay;
212
213 extern int      VacuumCostBalance;
214 extern bool     VacuumCostActive;
215
216
217 /* in tcop/postgres.c */
218 extern void check_stack_depth(void);
219
220
221 /*****************************************************************************
222  *        pdir.h --                                                                                                                              *
223  *                      POSTGRES directory path definitions.                                                     *
224  *****************************************************************************/
225
226 extern char *DatabasePath;
227
228 /* in utils/misc/database.c */
229 extern void GetRawDatabaseInfo(const char *name, Oid *db_id, Oid *db_tablespace);
230
231 /* now in utils/init/miscinit.c */
232 extern void SetDatabasePath(const char *path);
233
234 extern char *GetUserNameFromId(AclId userid);
235 extern AclId GetUserId(void);
236 extern void SetUserId(AclId userid);
237 extern AclId GetSessionUserId(void);
238 extern void SetSessionUserId(AclId userid);
239 extern void InitializeSessionUserId(const char *username);
240 extern void InitializeSessionUserIdStandalone(void);
241 extern void SetSessionAuthorization(AclId userid, bool is_superuser);
242
243 extern void SetDataDir(const char *dir);
244
245 /* in utils/misc/superuser.c */
246 extern bool superuser(void);    /* current user is superuser */
247 extern bool superuser_arg(AclId userid);                /* given user is superuser */
248
249
250 /*****************************************************************************
251  *        pmod.h --                                                                                                                              *
252  *                      POSTGRES processing mode definitions.                                                    *
253  *****************************************************************************/
254
255 /*
256  * Description:
257  *              There are three processing modes in POSTGRES.  They are
258  * BootstrapProcessing or "bootstrap," InitProcessing or
259  * "initialization," and NormalProcessing or "normal."
260  *
261  * The first two processing modes are used during special times. When the
262  * system state indicates bootstrap processing, transactions are all given
263  * transaction id "one" and are consequently guaranteed to commit. This mode
264  * is used during the initial generation of template databases.
265  *
266  * Initialization mode: used while starting a backend, until all normal
267  * initialization is complete.  Some code behaves differently when executed
268  * in this mode to enable system bootstrapping.
269  *
270  * If a POSTGRES binary is in normal mode, then all code may be executed
271  * normally.
272  */
273
274 typedef enum ProcessingMode
275 {
276         BootstrapProcessing,            /* bootstrap creation of template database */
277         InitProcessing,                         /* initializing system */
278         NormalProcessing                        /* normal processing */
279 } ProcessingMode;
280
281 extern ProcessingMode Mode;
282
283 #define IsBootstrapProcessingMode() ((bool)(Mode == BootstrapProcessing))
284 #define IsInitProcessingMode() ((bool)(Mode == InitProcessing))
285 #define IsNormalProcessingMode() ((bool)(Mode == NormalProcessing))
286
287 #define SetProcessingMode(mode) \
288         do { \
289                 AssertArg((mode) == BootstrapProcessing || \
290                                   (mode) == InitProcessing || \
291                                   (mode) == NormalProcessing); \
292                 Mode = (mode); \
293         } while(0)
294
295 #define GetProcessingMode() Mode
296
297
298 /*****************************************************************************
299  *        pinit.h --                                                                                                                     *
300  *                      POSTGRES initialization and cleanup definitions.                                 *
301  *****************************************************************************/
302
303 /* in utils/init/postinit.c */
304 extern void InitPostgres(const char *dbname, const char *username);
305 extern void BaseInit(void);
306
307 /* in utils/init/miscinit.c */
308 extern void IgnoreSystemIndexes(bool mode);
309 extern bool IsIgnoringSystemIndexes(void);
310 extern void SetReindexProcessing(Oid heapOid, Oid indexOid);
311 extern void ResetReindexProcessing(void);
312 extern bool ReindexIsProcessingHeap(Oid heapOid);
313 extern bool ReindexIsProcessingIndex(Oid indexOid);
314 extern void CreateDataDirLockFile(const char *datadir, bool amPostmaster);
315 extern void CreateSocketLockFile(const char *socketfile, bool amPostmaster);
316 extern void TouchSocketLockFile(void);
317 extern void RecordSharedMemoryInLockFile(unsigned long id1,
318                                                          unsigned long id2);
319 extern void ValidatePgVersion(const char *path);
320 extern void process_preload_libraries(char *preload_libraries_string);
321
322 #endif   /* MISCADMIN_H */