|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* globals.c
|
|
|
|
* global variable declarations
|
|
|
|
*
|
|
|
|
* Portions Copyright (c) 1996-2015, PostgreSQL Global Development Group
|
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
|
|
|
* src/backend/utils/init/globals.c
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* Globals used all over the place should be declared here and not
|
|
|
|
* in other modules.
|
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
XLOG (and related) changes:
* Store two past checkpoint locations, not just one, in pg_control.
On startup, we fall back to the older checkpoint if the newer one
is unreadable. Also, a physical copy of the newest checkpoint record
is kept in pg_control for possible use in disaster recovery (ie,
complete loss of pg_xlog). Also add a version number for pg_control
itself. Remove archdir from pg_control; it ought to be a GUC
parameter, not a special case (not that it's implemented yet anyway).
* Suppress successive checkpoint records when nothing has been entered
in the WAL log since the last one. This is not so much to avoid I/O
as to make it actually useful to keep track of the last two
checkpoints. If the things are right next to each other then there's
not a lot of redundancy gained...
* Change CRC scheme to a true 64-bit CRC, not a pair of 32-bit CRCs
on alternate bytes. Polynomial borrowed from ECMA DLT1 standard.
* Fix XLOG record length handling so that it will work at BLCKSZ = 32k.
* Change XID allocation to work more like OID allocation. (This is of
dubious necessity, but I think it's a good idea anyway.)
* Fix a number of minor bugs, such as off-by-one logic for XLOG file
wraparound at the 4 gig mark.
* Add documentation and clean up some coding infelicities; move file
format declarations out to include files where planned contrib
utilities can get at them.
* Checkpoint will now occur every CHECKPOINT_SEGMENTS log segments or
every CHECKPOINT_TIMEOUT seconds, whichever comes first. It is also
possible to force a checkpoint by sending SIGUSR1 to the postmaster
(undocumented feature...)
* Defend against kill -9 postmaster by storing shmem block's key and ID
in postmaster.pid lockfile, and checking at startup to ensure that no
processes are still connected to old shmem block (if it still exists).
* Switch backends to accept SIGQUIT rather than SIGUSR1 for emergency
stop, for symmetry with postmaster and xlog utilities. Clean up signal
handling in bootstrap.c so that xlog utilities launched by postmaster
will react to signals better.
* Standalone bootstrap now grabs lockfile in target directory, as added
insurance against running it in parallel with live postmaster.
25 years ago
|
|
|
#include "postgres.h"
|
|
|
|
|
|
|
|
#include "libpq/libpq-be.h"
|
|
|
|
#include "libpq/pqcomm.h"
|
|
|
|
#include "miscadmin.h"
|
|
|
|
#include "storage/backendid.h"
|
|
|
|
|
|
|
|
|
|
|
|
ProtocolVersion FrontendProtocol;
|
|
|
|
|
|
|
|
volatile bool InterruptPending = false;
|
|
|
|
volatile bool QueryCancelPending = false;
|
|
|
|
volatile bool ProcDiePending = false;
|
|
|
|
volatile bool ClientConnectionLost = false;
|
|
|
|
volatile bool ImmediateInterruptOK = false;
|
|
|
|
volatile uint32 InterruptHoldoffCount = 0;
|
|
|
|
volatile uint32 CritSectionCount = 0;
|
|
|
|
|
|
|
|
int MyProcPid;
|
|
|
|
pg_time_t MyStartTime;
|
|
|
|
struct Port *MyProcPort;
|
|
|
|
long MyCancelKey;
|
Install a "dead man switch" to allow the postmaster to detect cases where
a backend has done exit(0) or exit(1) without having disengaged itself
from shared memory. We are at risk for this whenever third-party code is
loaded into a backend, since such code might not know it's supposed to go
through proc_exit() instead. Also, it is reported that under Windows
there are ways to externally kill a process that cause the status code
returned to the postmaster to be indistinguishable from a voluntary exit
(thank you, Microsoft). If this does happen then the system is probably
hosed --- for instance, the dead session might still be holding locks.
So the best recovery method is to treat this like a backend crash.
The dead man switch is armed for a particular child process when it
acquires a regular PGPROC, and disarmed when the PGPROC is released;
these should be the first and last touches of shared memory resources
in a backend, or close enough anyway. This choice means there is no
coverage for auxiliary processes, but I doubt we need that, since they
shouldn't be executing any user-provided code anyway.
This patch also improves the management of the EXEC_BACKEND
ShmemBackendArray array a bit, by reducing search costs.
Although this problem is of long standing, the lack of field complaints
seems to mean it's not critical enough to risk back-patching; at least
not till we get some more testing of this mechanism.
17 years ago
|
|
|
int MyPMChildSlot;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* MyLatch points to the latch that should be used for signal handling by the
|
|
|
|
* current process. It will either point to a process local latch if the
|
|
|
|
* current process does not have a PGPROC entry in that moment, or to
|
|
|
|
* PGPROC->procLatch if it has. Thus it can always be used in signal handlers,
|
|
|
|
* without checking for its existence.
|
|
|
|
*/
|
|
|
|
struct Latch *MyLatch;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* DataDir is the absolute path to the top level of the PGDATA directory tree.
|
|
|
|
* Except during early startup, this is also the server's working directory;
|
|
|
|
* most code therefore can simply use relative paths and not reference DataDir
|
|
|
|
* explicitly.
|
|
|
|
*/
|
|
|
|
char *DataDir = NULL;
|
|
|
|
|
|
|
|
char OutputFileName[MAXPGPATH]; /* debugging output file */
|
|
|
|
|
|
|
|
char my_exec_path[MAXPGPATH]; /* full path to my executable */
|
|
|
|
char pkglib_path[MAXPGPATH]; /* full path to lib directory */
|
|
|
|
|
|
|
|
#ifdef EXEC_BACKEND
|
|
|
|
char postgres_exec_path[MAXPGPATH]; /* full path to backend */
|
|
|
|
|
|
|
|
/* note: currently this is not valid in backend processes */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
BackendId MyBackendId = InvalidBackendId;
|
|
|
|
|
|
|
|
Oid MyDatabaseId = InvalidOid;
|
|
|
|
|
|
|
|
Oid MyDatabaseTableSpace = InvalidOid;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* DatabasePath is the path (relative to DataDir) of my database's
|
|
|
|
* primary directory, ie, its directory in the default tablespace.
|
|
|
|
*/
|
|
|
|
char *DatabasePath = NULL;
|
|
|
|
|
|
|
|
pid_t PostmasterPid = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* IsPostmasterEnvironment is true in a postmaster process and any postmaster
|
|
|
|
* child process; it is false in a standalone process (bootstrap or
|
|
|
|
* standalone backend). IsUnderPostmaster is true in postmaster child
|
|
|
|
* processes. Note that "child process" includes all children, not only
|
|
|
|
* regular backends. These should be set correctly as early as possible
|
|
|
|
* in the execution of a process, so that error handling will do the right
|
|
|
|
* things if an error should occur during process initialization.
|
|
|
|
*
|
|
|
|
* These are initialized for the bootstrap/standalone case.
|
|
|
|
*/
|
|
|
|
bool IsPostmasterEnvironment = false;
|
|
|
|
bool IsUnderPostmaster = false;
|
|
|
|
bool IsBinaryUpgrade = false;
|
Background worker processes
Background workers are postmaster subprocesses that run arbitrary
user-specified code. They can request shared memory access as well as
backend database connections; or they can just use plain libpq frontend
database connections.
Modules listed in shared_preload_libraries can register background
workers in their _PG_init() function; this is early enough that it's not
necessary to provide an extra GUC option, because the necessary extra
resources can be allocated early on. Modules can install more than one
bgworker, if necessary.
Care is taken that these extra processes do not interfere with other
postmaster tasks: only one such process is started on each ServerLoop
iteration. This means a large number of them could be waiting to be
started up and postmaster is still able to quickly service external
connection requests. Also, shutdown sequence should not be impacted by
a worker process that's reasonably well behaved (i.e. promptly responds
to termination signals.)
The current implementation lets worker processes specify their start
time, i.e. at what point in the server startup process they are to be
started: right after postmaster start (in which case they mustn't ask
for shared memory access), when consistent state has been reached
(useful during recovery in a HOT standby server), or when recovery has
terminated (i.e. when normal backends are allowed).
In case of a bgworker crash, actions to take depend on registration
data: if shared memory was requested, then all other connections are
taken down (as well as other bgworkers), just like it were a regular
backend crashing. The bgworker itself is restarted, too, within a
configurable timeframe (which can be configured to be never).
More features to add to this framework can be imagined without much
effort, and have been discussed, but this seems good enough as a useful
unit already.
An elementary sample module is supplied.
Author: Álvaro Herrera
This patch is loosely based on prior patches submitted by KaiGai Kohei,
and unsubmitted code by Simon Riggs.
Reviewed by: KaiGai Kohei, Markus Wanner, Andres Freund,
Heikki Linnakangas, Simon Riggs, Amit Kapila
13 years ago
|
|
|
bool IsBackgroundWorker = false;
|
|
|
|
|
|
|
|
bool ExitOnAnyError = false;
|
|
|
|
|
Make ISO date style (e.g. "2000-02-16 09:33") the default.
Implement "date/time grand unification".
Transform datetime and timespan into timestamp and interval.
Deprecate datetime and timespan, though translate to new types in gram.y.
Transform all datetime and timespan catalog entries into new types.
Make "INTERVAL" reserved word allowed as a column identifier in gram.y.
Remove dt.h, dt.c files, and retarget datetime.h, datetime.c as utility
routines for all date/time types.
date.{h,c} now deals with date, time types.
timestamp.{h,c} now deals with timestamp, interval types.
nabstime.{h,c} now deals with abstime, reltime, tinterval types.
Make NUMERIC a known native type for purposes of type coersion. Not tested.
26 years ago
|
|
|
int DateStyle = USE_ISO_DATES;
|
|
|
|
int DateOrder = DATEORDER_MDY;
|
|
|
|
int IntervalStyle = INTSTYLE_POSTGRES;
|
|
|
|
|
|
|
|
bool enableFsync = true;
|
|
|
|
bool allowSystemTableMods = false;
|
|
|
|
int work_mem = 1024;
|
|
|
|
int maintenance_work_mem = 16384;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Primary determinants of sizes of shared-memory structures.
|
|
|
|
*
|
|
|
|
* MaxBackends is computed by PostmasterMain after modules have had a chance to
|
|
|
|
* register background workers.
|
|
|
|
*/
|
|
|
|
int NBuffers = 1000;
|
|
|
|
int MaxConnections = 90;
|
Add new GUC, max_worker_processes, limiting number of bgworkers.
In 9.3, there's no particular limit on the number of bgworkers;
instead, we just count up the number that are actually registered,
and use that to set MaxBackends. However, that approach causes
problems for Hot Standby, which needs both MaxBackends and the
size of the lock table to be the same on the standby as on the
master, yet it may not be desirable to run the same bgworkers in
both places. 9.3 handles that by failing to notice the problem,
which will probably work fine in nearly all cases anyway, but is
not theoretically sound.
A further problem with simply counting the number of registered
workers is that new workers can't be registered without a
postmaster restart. This is inconvenient for administrators,
since bouncing the postmaster causes an interruption of service.
Moreover, there are a number of applications for background
processes where, by necessity, the background process must be
started on the fly (e.g. parallel query). While this patch
doesn't actually make it possible to register new background
workers after startup time, it's a necessary prerequisite.
Patch by me. Review by Michael Paquier.
12 years ago
|
|
|
int max_worker_processes = 8;
|
|
|
|
int MaxBackends = 0;
|
|
|
|
|
|
|
|
int VacuumCostPageHit = 1; /* GUC parameters for vacuum */
|
|
|
|
int VacuumCostPageMiss = 10;
|
|
|
|
int VacuumCostPageDirty = 20;
|
|
|
|
int VacuumCostLimit = 200;
|
|
|
|
int VacuumCostDelay = 0;
|
|
|
|
|
|
|
|
int VacuumPageHit = 0;
|
|
|
|
int VacuumPageMiss = 0;
|
|
|
|
int VacuumPageDirty = 0;
|
|
|
|
|
|
|
|
int VacuumCostBalance = 0; /* working state for vacuum */
|
|
|
|
bool VacuumCostActive = false;
|