PageRenderTime 45ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/src/include/miscadmin.h

http://github.com/postgres/postgres-old-soon-decommissioned
C Header | 365 lines | 155 code | 64 blank | 146 comment | 11 complexity | 519c3dd38fef5702b86e6895da5a4861 MD5 | raw file
Possible License(s): LGPL-2.0, AGPL-3.0
  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-2010, PostgreSQL Global Development Group
  14. * Portions Copyright (c) 1994, Regents of the University of California
  15. *
  16. * $PostgreSQL$
  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. #include "pgtime.h" /* for pg_time_t */
  26. #define PG_BACKEND_VERSIONSTR "postgres (PostgreSQL) " PG_VERSION "\n"
  27. /*****************************************************************************
  28. * System interrupt and critical section handling
  29. *
  30. * There are two types of interrupts that a running backend needs to accept
  31. * without messing up its state: QueryCancel (SIGINT) and ProcDie (SIGTERM).
  32. * In both cases, we need to be able to clean up the current transaction
  33. * gracefully, so we can't respond to the interrupt instantaneously ---
  34. * there's no guarantee that internal data structures would be self-consistent
  35. * if the code is interrupted at an arbitrary instant. Instead, the signal
  36. * handlers set flags that are checked periodically during execution.
  37. *
  38. * The CHECK_FOR_INTERRUPTS() macro is called at strategically located spots
  39. * where it is normally safe to accept a cancel or die interrupt. In some
  40. * cases, we invoke CHECK_FOR_INTERRUPTS() inside low-level subroutines that
  41. * might sometimes be called in contexts that do *not* want to allow a cancel
  42. * or die interrupt. The HOLD_INTERRUPTS() and RESUME_INTERRUPTS() macros
  43. * allow code to ensure that no cancel or die interrupt will be accepted,
  44. * even if CHECK_FOR_INTERRUPTS() gets called in a subroutine. The interrupt
  45. * will be held off until CHECK_FOR_INTERRUPTS() is done outside any
  46. * HOLD_INTERRUPTS() ... RESUME_INTERRUPTS() section.
  47. *
  48. * Special mechanisms are used to let an interrupt be accepted when we are
  49. * waiting for a lock or when we are waiting for command input (but, of
  50. * course, only if the interrupt holdoff counter is zero). See the
  51. * related code for details.
  52. *
  53. * A related, but conceptually distinct, mechanism is the "critical section"
  54. * mechanism. A critical section not only holds off cancel/die interrupts,
  55. * but causes any ereport(ERROR) or ereport(FATAL) to become ereport(PANIC)
  56. * --- that is, a system-wide reset is forced. Needless to say, only really
  57. * *critical* code should be marked as a critical section! Currently, this
  58. * mechanism is only used for XLOG-related code.
  59. *
  60. *****************************************************************************/
  61. /* in globals.c */
  62. /* these are marked volatile because they are set by signal handlers: */
  63. extern PGDLLIMPORT volatile bool InterruptPending;
  64. extern volatile bool QueryCancelPending;
  65. extern volatile bool ProcDiePending;
  66. /* these are marked volatile because they are examined by signal handlers: */
  67. extern volatile bool ImmediateInterruptOK;
  68. extern PGDLLIMPORT volatile uint32 InterruptHoldoffCount;
  69. extern PGDLLIMPORT volatile uint32 CritSectionCount;
  70. /* in tcop/postgres.c */
  71. extern void ProcessInterrupts(void);
  72. #ifndef WIN32
  73. #define CHECK_FOR_INTERRUPTS() \
  74. do { \
  75. if (InterruptPending) \
  76. ProcessInterrupts(); \
  77. } while(0)
  78. #else /* WIN32 */
  79. #define CHECK_FOR_INTERRUPTS() \
  80. do { \
  81. if (UNBLOCKED_SIGNAL_QUEUE()) \
  82. pgwin32_dispatch_queued_signals(); \
  83. if (InterruptPending) \
  84. ProcessInterrupts(); \
  85. } while(0)
  86. #endif /* WIN32 */
  87. #define HOLD_INTERRUPTS() (InterruptHoldoffCount++)
  88. #define RESUME_INTERRUPTS() \
  89. do { \
  90. Assert(InterruptHoldoffCount > 0); \
  91. InterruptHoldoffCount--; \
  92. } while(0)
  93. #define START_CRIT_SECTION() (CritSectionCount++)
  94. #define END_CRIT_SECTION() \
  95. do { \
  96. Assert(CritSectionCount > 0); \
  97. CritSectionCount--; \
  98. } while(0)
  99. /*****************************************************************************
  100. * globals.h -- *
  101. *****************************************************************************/
  102. /*
  103. * from utils/init/globals.c
  104. */
  105. extern pid_t PostmasterPid;
  106. extern bool IsPostmasterEnvironment;
  107. extern PGDLLIMPORT bool IsUnderPostmaster;
  108. extern bool ExitOnAnyError;
  109. extern PGDLLIMPORT char *DataDir;
  110. extern PGDLLIMPORT int NBuffers;
  111. extern int MaxBackends;
  112. extern int MaxConnections;
  113. extern PGDLLIMPORT int MyProcPid;
  114. extern PGDLLIMPORT pg_time_t MyStartTime;
  115. extern PGDLLIMPORT struct Port *MyProcPort;
  116. extern long MyCancelKey;
  117. extern int MyPMChildSlot;
  118. extern char OutputFileName[];
  119. extern PGDLLIMPORT char my_exec_path[];
  120. extern char pkglib_path[];
  121. #ifdef EXEC_BACKEND
  122. extern char postgres_exec_path[];
  123. #endif
  124. /*
  125. * done in storage/backendid.h for now.
  126. *
  127. * extern BackendId MyBackendId;
  128. */
  129. extern PGDLLIMPORT Oid MyDatabaseId;
  130. extern PGDLLIMPORT Oid MyDatabaseTableSpace;
  131. /*
  132. * Date/Time Configuration
  133. *
  134. * DateStyle defines the output formatting choice for date/time types:
  135. * USE_POSTGRES_DATES specifies traditional Postgres format
  136. * USE_ISO_DATES specifies ISO-compliant format
  137. * USE_SQL_DATES specifies Oracle/Ingres-compliant format
  138. * USE_GERMAN_DATES specifies German-style dd.mm/yyyy
  139. *
  140. * DateOrder defines the field order to be assumed when reading an
  141. * ambiguous date (anything not in YYYY-MM-DD format, with a four-digit
  142. * year field first, is taken to be ambiguous):
  143. * DATEORDER_YMD specifies field order yy-mm-dd
  144. * DATEORDER_DMY specifies field order dd-mm-yy ("European" convention)
  145. * DATEORDER_MDY specifies field order mm-dd-yy ("US" convention)
  146. *
  147. * In the Postgres and SQL DateStyles, DateOrder also selects output field
  148. * order: day comes before month in DMY style, else month comes before day.
  149. *
  150. * The user-visible "DateStyle" run-time parameter subsumes both of these.
  151. */
  152. /* valid DateStyle values */
  153. #define USE_POSTGRES_DATES 0
  154. #define USE_ISO_DATES 1
  155. #define USE_SQL_DATES 2
  156. #define USE_GERMAN_DATES 3
  157. #define USE_XSD_DATES 4
  158. /* valid DateOrder values */
  159. #define DATEORDER_YMD 0
  160. #define DATEORDER_DMY 1
  161. #define DATEORDER_MDY 2
  162. extern int DateStyle;
  163. extern int DateOrder;
  164. /*
  165. * IntervalStyles
  166. * INTSTYLE_POSTGRES Like Postgres < 8.4 when DateStyle = 'iso'
  167. * INTSTYLE_POSTGRES_VERBOSE Like Postgres < 8.4 when DateStyle != 'iso'
  168. * INTSTYLE_SQL_STANDARD SQL standard interval literals
  169. * INTSTYLE_ISO_8601 ISO-8601-basic formatted intervals
  170. */
  171. #define INTSTYLE_POSTGRES 0
  172. #define INTSTYLE_POSTGRES_VERBOSE 1
  173. #define INTSTYLE_SQL_STANDARD 2
  174. #define INTSTYLE_ISO_8601 3
  175. extern int IntervalStyle;
  176. /*
  177. * HasCTZSet is true if user has set timezone as a numeric offset from UTC.
  178. * If so, CTimeZone is the timezone offset in seconds (using the Unix-ish
  179. * sign convention, ie, positive offset is west of UTC, rather than the
  180. * SQL-ish convention that positive is east of UTC).
  181. */
  182. extern bool HasCTZSet;
  183. extern int CTimeZone;
  184. #define MAXTZLEN 10 /* max TZ name len, not counting tr. null */
  185. extern bool enableFsync;
  186. extern bool allowSystemTableMods;
  187. extern PGDLLIMPORT int work_mem;
  188. extern PGDLLIMPORT int maintenance_work_mem;
  189. extern int VacuumCostPageHit;
  190. extern int VacuumCostPageMiss;
  191. extern int VacuumCostPageDirty;
  192. extern int VacuumCostLimit;
  193. extern int VacuumCostDelay;
  194. extern int VacuumCostBalance;
  195. extern bool VacuumCostActive;
  196. /* in tcop/postgres.c */
  197. extern void check_stack_depth(void);
  198. /* in tcop/utility.c */
  199. extern void PreventCommandIfReadOnly(const char *cmdname);
  200. extern void PreventCommandDuringRecovery(const char *cmdname);
  201. /* in utils/misc/guc.c */
  202. extern int trace_recovery_messages;
  203. extern int trace_recovery(int trace_level);
  204. /*****************************************************************************
  205. * pdir.h -- *
  206. * POSTGRES directory path definitions. *
  207. *****************************************************************************/
  208. /* flags to be OR'd to form sec_context */
  209. #define SECURITY_LOCAL_USERID_CHANGE 0x0001
  210. #define SECURITY_RESTRICTED_OPERATION 0x0002
  211. extern char *DatabasePath;
  212. /* now in utils/init/miscinit.c */
  213. extern void SetDatabasePath(const char *path);
  214. extern char *GetUserNameFromId(Oid roleid);
  215. extern Oid GetUserId(void);
  216. extern Oid GetOuterUserId(void);
  217. extern Oid GetSessionUserId(void);
  218. extern void GetUserIdAndSecContext(Oid *userid, int *sec_context);
  219. extern void SetUserIdAndSecContext(Oid userid, int sec_context);
  220. extern bool InLocalUserIdChange(void);
  221. extern bool InSecurityRestrictedOperation(void);
  222. extern void GetUserIdAndContext(Oid *userid, bool *sec_def_context);
  223. extern void SetUserIdAndContext(Oid userid, bool sec_def_context);
  224. extern void InitializeSessionUserId(const char *rolename);
  225. extern void InitializeSessionUserIdStandalone(void);
  226. extern void SetSessionAuthorization(Oid userid, bool is_superuser);
  227. extern Oid GetCurrentRoleId(void);
  228. extern void SetCurrentRoleId(Oid roleid, bool is_superuser);
  229. extern void SetDataDir(const char *dir);
  230. extern void ChangeToDataDir(void);
  231. extern char *make_absolute_path(const char *path);
  232. /* in utils/misc/superuser.c */
  233. extern bool superuser(void); /* current user is superuser */
  234. extern bool superuser_arg(Oid roleid); /* given user is superuser */
  235. /*****************************************************************************
  236. * pmod.h -- *
  237. * POSTGRES processing mode definitions. *
  238. *****************************************************************************/
  239. /*
  240. * Description:
  241. * There are three processing modes in POSTGRES. They are
  242. * BootstrapProcessing or "bootstrap," InitProcessing or
  243. * "initialization," and NormalProcessing or "normal."
  244. *
  245. * The first two processing modes are used during special times. When the
  246. * system state indicates bootstrap processing, transactions are all given
  247. * transaction id "one" and are consequently guaranteed to commit. This mode
  248. * is used during the initial generation of template databases.
  249. *
  250. * Initialization mode: used while starting a backend, until all normal
  251. * initialization is complete. Some code behaves differently when executed
  252. * in this mode to enable system bootstrapping.
  253. *
  254. * If a POSTGRES binary is in normal mode, then all code may be executed
  255. * normally.
  256. */
  257. typedef enum ProcessingMode
  258. {
  259. BootstrapProcessing, /* bootstrap creation of template database */
  260. InitProcessing, /* initializing system */
  261. NormalProcessing /* normal processing */
  262. } ProcessingMode;
  263. extern ProcessingMode Mode;
  264. #define IsBootstrapProcessingMode() ((bool)(Mode == BootstrapProcessing))
  265. #define IsInitProcessingMode() ((bool)(Mode == InitProcessing))
  266. #define IsNormalProcessingMode() ((bool)(Mode == NormalProcessing))
  267. #define SetProcessingMode(mode) \
  268. do { \
  269. AssertArg((mode) == BootstrapProcessing || \
  270. (mode) == InitProcessing || \
  271. (mode) == NormalProcessing); \
  272. Mode = (mode); \
  273. } while(0)
  274. #define GetProcessingMode() Mode
  275. /*****************************************************************************
  276. * pinit.h -- *
  277. * POSTGRES initialization and cleanup definitions. *
  278. *****************************************************************************/
  279. /* in utils/init/postinit.c */
  280. extern void pg_split_opts(char **argv, int *argcp, char *optstr);
  281. extern void InitPostgres(const char *in_dbname, Oid dboid, const char *username,
  282. char *out_dbname);
  283. extern void BaseInit(void);
  284. /* in utils/init/miscinit.c */
  285. extern bool IgnoreSystemIndexes;
  286. extern PGDLLIMPORT bool process_shared_preload_libraries_in_progress;
  287. extern char *shared_preload_libraries_string;
  288. extern char *local_preload_libraries_string;
  289. extern void CreateDataDirLockFile(bool amPostmaster);
  290. extern void CreateSocketLockFile(const char *socketfile, bool amPostmaster);
  291. extern void TouchSocketLockFile(void);
  292. extern void RecordSharedMemoryInLockFile(unsigned long id1,
  293. unsigned long id2);
  294. extern void ValidatePgVersion(const char *path);
  295. extern void process_shared_preload_libraries(void);
  296. extern void process_local_preload_libraries(void);
  297. extern void pg_bindtextdomain(const char *domain);
  298. /* in access/transam/xlog.c */
  299. extern bool BackupInProgress(void);
  300. extern void CancelBackup(void);
  301. #endif /* MISCADMIN_H */