diff options
author | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2010-01-15 09:19:10 +0000 |
---|---|---|
committer | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2010-01-15 09:19:10 +0000 |
commit | 40f908bdcdc726fc11912cd95dfd2f89603d1f37 (patch) | |
tree | fcbbda839e58184fc284d261cc5a0f5e8ac921f3 /src/backend/storage | |
parent | 4cbe473938779ec414d90c2063c4398e68a70838 (diff) | |
download | postgresql-40f908bdcdc726fc11912cd95dfd2f89603d1f37.tar.gz postgresql-40f908bdcdc726fc11912cd95dfd2f89603d1f37.zip |
Introduce Streaming Replication.
This includes two new kinds of postmaster processes, walsenders and
walreceiver. Walreceiver is responsible for connecting to the primary server
and streaming WAL to disk, while walsender runs in the primary server and
streams WAL from disk to the client.
Documentation still needs work, but the basics are there. We will probably
pull the replication section to a new chapter later on, as well as the
sections describing file-based replication. But let's do that as a separate
patch, so that it's easier to see what has been added/changed. This patch
also adds a new section to the chapter about FE/BE protocol, documenting the
protocol used by walsender/walreceivxer.
Bump catalog version because of two new functions,
pg_last_xlog_receive_location() and pg_last_xlog_replay_location(), for
monitoring the progress of replication.
Fujii Masao, with additional hacking by me
Diffstat (limited to 'src/backend/storage')
-rw-r--r-- | src/backend/storage/ipc/ipci.c | 8 | ||||
-rw-r--r-- | src/backend/storage/ipc/pmsignal.c | 41 | ||||
-rw-r--r-- | src/backend/storage/lmgr/proc.c | 10 |
3 files changed, 54 insertions, 5 deletions
diff --git a/src/backend/storage/ipc/ipci.c b/src/backend/storage/ipc/ipci.c index 134521c91cd..01a9fabc8c9 100644 --- a/src/backend/storage/ipc/ipci.c +++ b/src/backend/storage/ipc/ipci.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/storage/ipc/ipci.c,v 1.102 2010/01/02 16:57:51 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/storage/ipc/ipci.c,v 1.103 2010/01/15 09:19:03 heikki Exp $ * *------------------------------------------------------------------------- */ @@ -25,6 +25,8 @@ #include "postmaster/autovacuum.h" #include "postmaster/bgwriter.h" #include "postmaster/postmaster.h" +#include "replication/walreceiver.h" +#include "replication/walsender.h" #include "storage/bufmgr.h" #include "storage/ipc.h" #include "storage/pg_shmem.h" @@ -116,6 +118,8 @@ CreateSharedMemoryAndSemaphores(bool makePrivate, int port) size = add_size(size, ProcSignalShmemSize()); size = add_size(size, BgWriterShmemSize()); size = add_size(size, AutoVacuumShmemSize()); + size = add_size(size, WalSndShmemSize()); + size = add_size(size, WalRcvShmemSize()); size = add_size(size, BTreeShmemSize()); size = add_size(size, SyncScanShmemSize()); #ifdef EXEC_BACKEND @@ -213,6 +217,8 @@ CreateSharedMemoryAndSemaphores(bool makePrivate, int port) ProcSignalShmemInit(); BgWriterShmemInit(); AutoVacuumShmemInit(); + WalSndShmemInit(); + WalRcvShmemInit(); /* * Set up other modules that need some shared memory space diff --git a/src/backend/storage/ipc/pmsignal.c b/src/backend/storage/ipc/pmsignal.c index 0199c8b577c..2a414a0c2f3 100644 --- a/src/backend/storage/ipc/pmsignal.c +++ b/src/backend/storage/ipc/pmsignal.c @@ -8,7 +8,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/storage/ipc/pmsignal.c,v 1.29 2010/01/02 16:57:51 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/storage/ipc/pmsignal.c,v 1.30 2010/01/15 09:19:03 heikki Exp $ * *------------------------------------------------------------------------- */ @@ -45,11 +45,15 @@ * process is actively using shared memory. The slots are assigned to * child processes at random, and postmaster.c is responsible for tracking * which one goes with which PID. + * + * The fourth state, WALSENDER, is just like ACTIVE, but carries the extra + * information that the child is a WAL sender. */ #define PM_CHILD_UNUSED 0 /* these values must fit in sig_atomic_t */ #define PM_CHILD_ASSIGNED 1 #define PM_CHILD_ACTIVE 2 +#define PM_CHILD_WALSENDER 3 /* "typedef struct PMSignalData PMSignalData" appears in pmsignal.h */ struct PMSignalData @@ -193,6 +197,22 @@ ReleasePostmasterChildSlot(int slot) } /* + * IsPostmasterChildWalSender - check if given slot is in use by a + * walsender process. + */ +bool +IsPostmasterChildWalSender(int slot) +{ + Assert(slot > 0 && slot <= PMSignalState->num_child_flags); + slot--; + + if (PMSignalState->PMChildFlags[slot] == PM_CHILD_WALSENDER) + return true; + else + return false; +} + +/* * MarkPostmasterChildActive - mark a postmaster child as about to begin * actively using shared memory. This is called in the child process. */ @@ -208,6 +228,22 @@ MarkPostmasterChildActive(void) } /* + * MarkPostmasterChildWalSender - like MarkPostmasterChildActive(), but + * marks the postmaster child as a WAL sender instead of a regular backend. + * This is called in the child process. + */ +void +MarkPostmasterChildWalSender(void) +{ + int slot = MyPMChildSlot; + + Assert(slot > 0 && slot <= PMSignalState->num_child_flags); + slot--; + Assert(PMSignalState->PMChildFlags[slot] == PM_CHILD_ASSIGNED); + PMSignalState->PMChildFlags[slot] = PM_CHILD_WALSENDER; +} + +/* * MarkPostmasterChildInactive - mark a postmaster child as done using * shared memory. This is called in the child process. */ @@ -218,7 +254,8 @@ MarkPostmasterChildInactive(void) Assert(slot > 0 && slot <= PMSignalState->num_child_flags); slot--; - Assert(PMSignalState->PMChildFlags[slot] == PM_CHILD_ACTIVE); + Assert(PMSignalState->PMChildFlags[slot] == PM_CHILD_ACTIVE || + PMSignalState->PMChildFlags[slot] == PM_CHILD_WALSENDER); PMSignalState->PMChildFlags[slot] = PM_CHILD_ASSIGNED; } diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index ca7a19e4f4c..91065b368cd 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/storage/lmgr/proc.c,v 1.211 2010/01/02 16:57:52 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/storage/lmgr/proc.c,v 1.212 2010/01/15 09:19:03 heikki Exp $ * *------------------------------------------------------------------------- */ @@ -39,6 +39,7 @@ #include "access/xact.h" #include "miscadmin.h" #include "postmaster/autovacuum.h" +#include "replication/walsender.h" #include "storage/ipc.h" #include "storage/lmgr.h" #include "storage/pmsignal.h" @@ -290,7 +291,12 @@ InitProcess(void) * this; it probably should.) */ if (IsUnderPostmaster && !IsAutoVacuumLauncherProcess()) - MarkPostmasterChildActive(); + { + if (am_walsender) + MarkPostmasterChildWalSender(); + else + MarkPostmasterChildActive(); + } /* * Initialize all fields of MyProc, except for the semaphore which was |