1996-10-31 08:10:14 +01:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* miscadmin.h
|
1997-09-07 07:04:48 +02:00
|
|
|
* this file contains general postgres administration and initialization
|
|
|
|
* stuff that used to be spread out between the following files:
|
|
|
|
* globals.h global variables
|
|
|
|
* pdir.h directory path crud
|
|
|
|
* pinit.h postgres initialization
|
|
|
|
* pmod.h processing modes
|
1996-10-31 08:10:14 +01:00
|
|
|
*
|
|
|
|
*
|
2002-06-20 22:29:54 +02:00
|
|
|
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-10-31 08:10:14 +01:00
|
|
|
*
|
2002-09-04 22:31:48 +02:00
|
|
|
* $Id: miscadmin.h,v 1.109 2002/09/04 20:31:36 momjian Exp $
|
1996-10-31 08:10:14 +01:00
|
|
|
*
|
|
|
|
* NOTES
|
2001-01-14 06:08:17 +01:00
|
|
|
* some of the information in this file should be moved to
|
1997-09-07 07:04:48 +02:00
|
|
|
* other files.
|
1996-10-31 08:10:14 +01:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#ifndef MISCADMIN_H
|
|
|
|
#define MISCADMIN_H
|
|
|
|
|
2002-05-05 02:03:29 +02:00
|
|
|
|
1999-09-27 22:27:32 +02:00
|
|
|
|
2001-01-14 06:08:17 +01:00
|
|
|
/*****************************************************************************
|
2001-03-22 05:01:46 +01:00
|
|
|
* System interrupt and critical section handling
|
2001-01-14 06:08:17 +01:00
|
|
|
*
|
|
|
|
* There are two types of interrupts that a running backend needs to accept
|
|
|
|
* without messing up its state: QueryCancel (SIGINT) and ProcDie (SIGTERM).
|
|
|
|
* In both cases, we need to be able to clean up the current transaction
|
|
|
|
* gracefully, so we can't respond to the interrupt instantaneously ---
|
|
|
|
* there's no guarantee that internal data structures would be self-consistent
|
2001-03-22 05:01:46 +01:00
|
|
|
* if the code is interrupted at an arbitrary instant. Instead, the signal
|
2001-01-14 06:08:17 +01:00
|
|
|
* handlers set flags that are checked periodically during execution.
|
|
|
|
*
|
|
|
|
* The CHECK_FOR_INTERRUPTS() macro is called at strategically located spots
|
|
|
|
* where it is normally safe to accept a cancel or die interrupt. In some
|
|
|
|
* cases, we invoke CHECK_FOR_INTERRUPTS() inside low-level subroutines that
|
|
|
|
* might sometimes be called in contexts that do *not* want to allow a cancel
|
2001-01-19 23:08:47 +01:00
|
|
|
* or die interrupt. The HOLD_INTERRUPTS() and RESUME_INTERRUPTS() macros
|
|
|
|
* allow code to ensure that no cancel or die interrupt will be accepted,
|
2001-03-22 05:01:46 +01:00
|
|
|
* even if CHECK_FOR_INTERRUPTS() gets called in a subroutine. The interrupt
|
2002-01-02 00:16:22 +01:00
|
|
|
* will be held off until CHECK_FOR_INTERRUPTS() is done outside any
|
|
|
|
* HOLD_INTERRUPTS() ... RESUME_INTERRUPTS() section.
|
2001-01-14 06:08:17 +01:00
|
|
|
*
|
|
|
|
* Special mechanisms are used to let an interrupt be accepted when we are
|
2001-09-29 06:02:27 +02:00
|
|
|
* waiting for a lock or when we are waiting for command input (but, of
|
2001-10-25 07:50:21 +02:00
|
|
|
* course, only if the interrupt holdoff counter is zero). See the
|
2001-01-14 06:08:17 +01:00
|
|
|
* related code for details.
|
|
|
|
*
|
2001-01-19 23:08:47 +01:00
|
|
|
* A related, but conceptually distinct, mechanism is the "critical section"
|
|
|
|
* mechanism. A critical section not only holds off cancel/die interrupts,
|
|
|
|
* but causes any elog(ERROR) or elog(FATAL) to become elog(STOP) --- that is,
|
|
|
|
* a system-wide reset is forced. Needless to say, only really *critical*
|
|
|
|
* code should be marked as a critical section! Currently, this mechanism
|
|
|
|
* is only used for XLOG-related code.
|
|
|
|
*
|
2001-01-14 06:08:17 +01:00
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
/* in globals.c */
|
|
|
|
/* these are marked volatile because they are set by signal handlers: */
|
|
|
|
extern volatile bool InterruptPending;
|
|
|
|
extern volatile bool QueryCancelPending;
|
|
|
|
extern volatile bool ProcDiePending;
|
2001-03-22 05:01:46 +01:00
|
|
|
|
2001-01-14 06:08:17 +01:00
|
|
|
/* these are marked volatile because they are examined by signal handlers: */
|
|
|
|
extern volatile bool ImmediateInterruptOK;
|
2001-01-19 23:08:47 +01:00
|
|
|
extern volatile uint32 InterruptHoldoffCount;
|
2001-01-14 06:08:17 +01:00
|
|
|
extern volatile uint32 CritSectionCount;
|
|
|
|
|
|
|
|
/* in postgres.c */
|
|
|
|
extern void ProcessInterrupts(void);
|
|
|
|
|
|
|
|
#define CHECK_FOR_INTERRUPTS() \
|
|
|
|
do { \
|
|
|
|
if (InterruptPending) \
|
|
|
|
ProcessInterrupts(); \
|
|
|
|
} while(0)
|
|
|
|
|
2001-03-22 05:01:46 +01:00
|
|
|
#define HOLD_INTERRUPTS() (InterruptHoldoffCount++)
|
2001-01-19 23:08:47 +01:00
|
|
|
|
|
|
|
#define RESUME_INTERRUPTS() \
|
|
|
|
do { \
|
|
|
|
Assert(InterruptHoldoffCount > 0); \
|
|
|
|
InterruptHoldoffCount--; \
|
|
|
|
} while(0)
|
|
|
|
|
2001-03-22 05:01:46 +01:00
|
|
|
#define START_CRIT_SECTION() (CritSectionCount++)
|
2001-01-14 06:08:17 +01:00
|
|
|
|
|
|
|
#define END_CRIT_SECTION() \
|
|
|
|
do { \
|
|
|
|
Assert(CritSectionCount > 0); \
|
|
|
|
CritSectionCount--; \
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
|
1996-10-31 08:10:14 +01:00
|
|
|
/*****************************************************************************
|
1997-09-07 07:04:48 +02:00
|
|
|
* globals.h -- *
|
1996-10-31 08:10:14 +01:00
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* from postmaster/postmaster.c
|
|
|
|
*/
|
2002-03-04 02:46:04 +01:00
|
|
|
extern bool IsUnderPostmaster;
|
|
|
|
extern bool ClientAuthInProgress;
|
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
extern int PostmasterMain(int argc, char *argv[]);
|
2001-08-05 04:06:50 +02:00
|
|
|
extern void ClosePostmasterPorts(bool pgstat_too);
|
1996-10-31 08:10:14 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* from utils/init/globals.c
|
|
|
|
*/
|
1998-09-01 06:40:42 +02:00
|
|
|
extern bool Noversion;
|
1997-09-08 04:41:22 +02:00
|
|
|
extern char *DataDir;
|
1996-10-31 08:10:14 +01:00
|
|
|
|
2001-10-25 07:50:21 +02:00
|
|
|
extern DLLIMPORT int MyProcPid;
|
1998-09-01 06:40:42 +02:00
|
|
|
extern struct Port *MyProcPort;
|
|
|
|
extern long MyCancelKey;
|
1998-07-09 05:29:11 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
extern char OutputFileName[];
|
2001-10-21 05:25:36 +02:00
|
|
|
extern char pg_pathname[];
|
1996-10-31 08:10:14 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* done in storage/backendid.h for now.
|
|
|
|
*
|
|
|
|
* extern BackendId MyBackendId;
|
|
|
|
*/
|
2001-10-25 07:50:21 +02:00
|
|
|
extern DLLIMPORT Oid MyDatabaseId;
|
1996-10-31 08:10:14 +01:00
|
|
|
|
1997-03-18 17:36:50 +01:00
|
|
|
/* Date/Time Configuration
|
1997-03-25 09:11:24 +01:00
|
|
|
*
|
|
|
|
* Constants to pass info from runtime environment:
|
1997-09-07 07:04:48 +02:00
|
|
|
* USE_POSTGRES_DATES specifies traditional postgres format for output.
|
|
|
|
* USE_ISO_DATES specifies ISO-compliant format for output.
|
|
|
|
* USE_SQL_DATES specified Oracle/Ingres-compliant format for output.
|
1998-02-26 05:46:47 +01:00
|
|
|
* USE_GERMAN_DATES specifies German-style dd.mm/yyyy date format.
|
1997-03-25 09:11:24 +01:00
|
|
|
*
|
|
|
|
* DateStyle specifies preference for date formatting for output.
|
1997-03-18 17:36:50 +01:00
|
|
|
* EuroDates if client prefers dates interpreted and written w/European conventions.
|
1997-03-25 09:11:24 +01:00
|
|
|
*
|
|
|
|
* HasCTZSet if client timezone is specified by client.
|
|
|
|
* CDayLight is the apparent daylight savings time status.
|
1997-03-18 17:36:50 +01:00
|
|
|
* CTimeZone is the timezone offset in seconds.
|
|
|
|
* CTZName is the timezone label.
|
|
|
|
*/
|
|
|
|
|
2000-05-29 21:16:57 +02:00
|
|
|
#define MAXTZLEN 10 /* max TZ name len, not counting tr. null */
|
1997-03-25 09:11:24 +01:00
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
#define USE_POSTGRES_DATES 0
|
|
|
|
#define USE_ISO_DATES 1
|
|
|
|
#define USE_SQL_DATES 2
|
1997-12-05 00:58:01 +01:00
|
|
|
#define USE_GERMAN_DATES 3
|
1997-03-25 09:11:24 +01:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
extern int DateStyle;
|
|
|
|
extern bool EuroDates;
|
|
|
|
extern bool HasCTZSet;
|
|
|
|
extern bool CDayLight;
|
|
|
|
extern int CTimeZone;
|
|
|
|
extern char CTZName[];
|
1997-01-26 16:32:28 +01:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
extern char FloatFormat[];
|
|
|
|
extern char DateFormat[];
|
1997-03-18 21:15:39 +01:00
|
|
|
|
2000-05-31 02:28:42 +02:00
|
|
|
extern bool enableFsync;
|
1999-05-25 18:15:34 +02:00
|
|
|
extern bool allowSystemTableMods;
|
1997-09-08 04:41:22 +02:00
|
|
|
extern int SortMem;
|
2001-09-21 05:32:36 +02:00
|
|
|
extern int VacuumMem;
|
1997-08-14 18:11:41 +02:00
|
|
|
|
2001-08-15 20:42:16 +02:00
|
|
|
/*
|
|
|
|
* A few postmaster startup options are exported here so the
|
2001-10-25 07:50:21 +02:00
|
|
|
* configuration file processor can access them.
|
2001-08-15 20:42:16 +02:00
|
|
|
*/
|
2000-05-31 02:28:42 +02:00
|
|
|
|
|
|
|
extern bool NetServer;
|
2000-09-06 21:54:52 +02:00
|
|
|
extern bool EnableSSL;
|
2000-10-08 11:25:38 +02:00
|
|
|
extern bool SilentMode;
|
2001-03-22 05:01:46 +01:00
|
|
|
extern int MaxBackends;
|
2002-08-29 23:02:12 +02:00
|
|
|
extern int ReservedBackends;
|
2001-03-22 05:01:46 +01:00
|
|
|
extern int NBuffers;
|
|
|
|
extern int PostPortNumber;
|
|
|
|
extern int Unix_socket_permissions;
|
2000-11-25 23:34:14 +01:00
|
|
|
extern char *Unix_socket_group;
|
|
|
|
extern char *UnixSocketDir;
|
2000-11-29 21:59:54 +01:00
|
|
|
extern char *VirtualHost;
|
2000-11-25 23:34:14 +01:00
|
|
|
|
2000-05-31 02:28:42 +02:00
|
|
|
|
1996-10-31 08:10:14 +01:00
|
|
|
/*****************************************************************************
|
1997-09-07 07:04:48 +02:00
|
|
|
* pdir.h -- *
|
|
|
|
* POSTGRES directory path definitions. *
|
1996-10-31 08:10:14 +01:00
|
|
|
*****************************************************************************/
|
|
|
|
|
1998-04-05 23:04:50 +02:00
|
|
|
extern char *DatabaseName;
|
|
|
|
extern char *DatabasePath;
|
|
|
|
|
1997-11-07 07:38:51 +01:00
|
|
|
/* in utils/misc/database.c */
|
2000-01-13 19:26:18 +01:00
|
|
|
extern void GetRawDatabaseInfo(const char *name, Oid *db_id, char *path);
|
|
|
|
extern char *ExpandDatabasePath(const char *path);
|
1997-11-07 07:38:51 +01:00
|
|
|
|
1996-10-31 08:10:14 +01:00
|
|
|
/* now in utils/init/miscinit.c */
|
2000-01-13 19:26:18 +01:00
|
|
|
extern void SetDatabaseName(const char *name);
|
|
|
|
extern void SetDatabasePath(const char *path);
|
1998-09-01 06:40:42 +02:00
|
|
|
|
2002-06-11 15:40:53 +02:00
|
|
|
extern char *GetUserNameFromId(Oid userid);
|
2000-09-19 20:18:04 +02:00
|
|
|
|
2001-03-22 05:01:46 +01:00
|
|
|
extern Oid GetUserId(void);
|
2000-09-06 16:15:31 +02:00
|
|
|
extern void SetUserId(Oid userid);
|
2001-03-22 05:01:46 +01:00
|
|
|
extern Oid GetSessionUserId(void);
|
2000-09-19 20:18:04 +02:00
|
|
|
extern void SetSessionUserId(Oid userid);
|
2001-05-08 23:06:43 +02:00
|
|
|
extern void InitializeSessionUserId(const char *username);
|
2001-09-08 17:24:00 +02:00
|
|
|
extern void InitializeSessionUserIdStandalone(void);
|
2002-05-17 03:19:19 +02:00
|
|
|
extern void SetSessionAuthorization(Oid userid);
|
2000-09-19 20:18:04 +02:00
|
|
|
|
2000-11-04 13:43:24 +01:00
|
|
|
extern void SetDataDir(const char *dir);
|
|
|
|
|
2001-03-22 05:01:46 +01:00
|
|
|
extern int FindExec(char *full_path, const char *argv0,
|
|
|
|
const char *binary_name);
|
1997-09-08 04:41:22 +02:00
|
|
|
extern int CheckPathAccess(char *path, char *name, int open_mode);
|
1996-10-31 08:10:14 +01:00
|
|
|
|
2000-11-21 22:16:06 +01:00
|
|
|
#ifdef CYR_RECODE
|
2001-02-10 03:31:31 +01:00
|
|
|
extern void SetCharSet(void);
|
2000-11-25 06:00:33 +01:00
|
|
|
extern char *convertstr(unsigned char *buff, int len, int dest);
|
2000-11-21 22:16:06 +01:00
|
|
|
#endif
|
|
|
|
|
2001-06-13 23:44:41 +02:00
|
|
|
/* in utils/misc/superuser.c */
|
|
|
|
extern bool superuser(void); /* current user is superuser */
|
2002-02-19 00:11:58 +01:00
|
|
|
extern bool superuser_arg(Oid userid); /* given user is superuser */
|
2001-10-25 07:50:21 +02:00
|
|
|
extern bool is_dbadmin(Oid dbid); /* current user is owner of
|
|
|
|
* database */
|
2001-06-13 23:44:41 +02:00
|
|
|
|
|
|
|
|
1996-10-31 08:10:14 +01:00
|
|
|
/*****************************************************************************
|
1997-09-07 07:04:48 +02:00
|
|
|
* pmod.h -- *
|
|
|
|
* POSTGRES processing mode definitions. *
|
1996-10-31 08:10:14 +01:00
|
|
|
*****************************************************************************/
|
2001-09-27 18:29:13 +02:00
|
|
|
|
1996-10-31 08:10:14 +01:00
|
|
|
/*
|
|
|
|
* Description:
|
2000-04-12 19:17:23 +02:00
|
|
|
* There are three processing modes in POSTGRES. They are
|
2001-01-14 06:08:17 +01:00
|
|
|
* BootstrapProcessing or "bootstrap," InitProcessing or
|
1996-10-31 08:10:14 +01:00
|
|
|
* "initialization," and NormalProcessing or "normal."
|
|
|
|
*
|
1999-10-06 23:58:18 +02:00
|
|
|
* The first two processing modes are used during special times. When the
|
1996-10-31 08:10:14 +01:00
|
|
|
* system state indicates bootstrap processing, transactions are all given
|
2001-01-14 06:08:17 +01:00
|
|
|
* transaction id "one" and are consequently guaranteed to commit. This mode
|
1996-10-31 08:10:14 +01:00
|
|
|
* is used during the initial generation of template databases.
|
|
|
|
*
|
2001-01-14 06:08:17 +01:00
|
|
|
* Initialization mode: used while starting a backend, until all normal
|
2001-03-22 05:01:46 +01:00
|
|
|
* initialization is complete. Some code behaves differently when executed
|
2001-01-14 06:08:17 +01:00
|
|
|
* in this mode to enable system bootstrapping.
|
1999-10-06 23:58:18 +02:00
|
|
|
*
|
|
|
|
* If a POSTGRES binary is in normal mode, then all code may be executed
|
2000-04-12 19:17:23 +02:00
|
|
|
* normally.
|
1996-10-31 08:10:14 +01:00
|
|
|
*/
|
|
|
|
|
1997-09-07 07:04:48 +02:00
|
|
|
typedef enum ProcessingMode
|
|
|
|
{
|
2001-10-28 07:26:15 +01:00
|
|
|
BootstrapProcessing, /* bootstrap creation of template database */
|
|
|
|
InitProcessing, /* initializing system */
|
|
|
|
NormalProcessing /* normal processing */
|
1997-09-08 23:56:23 +02:00
|
|
|
} ProcessingMode;
|
1996-10-31 08:10:14 +01:00
|
|
|
|
2000-01-13 19:26:18 +01:00
|
|
|
extern ProcessingMode Mode;
|
|
|
|
|
|
|
|
#define IsBootstrapProcessingMode() ((bool)(Mode == BootstrapProcessing))
|
|
|
|
#define IsInitProcessingMode() ((bool)(Mode == InitProcessing))
|
|
|
|
#define IsNormalProcessingMode() ((bool)(Mode == NormalProcessing))
|
|
|
|
|
|
|
|
#define SetProcessingMode(mode) \
|
2000-04-12 19:17:23 +02:00
|
|
|
do { \
|
2001-01-14 06:08:17 +01:00
|
|
|
AssertArg((mode) == BootstrapProcessing || \
|
|
|
|
(mode) == InitProcessing || \
|
|
|
|
(mode) == NormalProcessing); \
|
|
|
|
Mode = (mode); \
|
2000-04-12 19:17:23 +02:00
|
|
|
} while(0)
|
1996-10-31 08:10:14 +01:00
|
|
|
|
2000-01-13 19:26:18 +01:00
|
|
|
#define GetProcessingMode() Mode
|
1997-09-08 04:41:22 +02:00
|
|
|
|
2001-09-27 18:29:13 +02:00
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* pinit.h -- *
|
|
|
|
* POSTGRES initialization and cleanup definitions. *
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
/* in utils/init/postinit.c */
|
|
|
|
extern void InitPostgres(const char *dbname, const char *username);
|
|
|
|
extern void BaseInit(void);
|
|
|
|
|
|
|
|
/* in utils/init/miscinit.c */
|
2000-11-29 21:59:54 +01:00
|
|
|
extern bool CreateDataDirLockFile(const char *datadir, bool amPostmaster);
|
|
|
|
extern bool CreateSocketLockFile(const char *socketfile, bool amPostmaster);
|
2001-01-27 01:05:31 +01:00
|
|
|
extern void TouchSocketLockFile(void);
|
2002-05-05 02:03:29 +02:00
|
|
|
extern void RecordSharedMemoryInLockFile(unsigned long id1,
|
2002-09-04 22:31:48 +02:00
|
|
|
unsigned long id2);
|
2000-07-02 17:21:27 +02:00
|
|
|
|
|
|
|
extern void ValidatePgVersion(const char *path);
|
|
|
|
|
2001-01-14 06:08:17 +01:00
|
|
|
/* these externs do not belong here... */
|
|
|
|
extern void IgnoreSystemIndexes(bool mode);
|
|
|
|
extern bool IsIgnoringSystemIndexes(void);
|
|
|
|
extern bool IsCacheInitialized(void);
|
2001-10-28 07:26:15 +01:00
|
|
|
|
2001-11-05 18:46:40 +01:00
|
|
|
#endif /* MISCADMIN_H */
|