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/tcop/postgres.c | |
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/tcop/postgres.c')
-rw-r--r-- | src/backend/tcop/postgres.c | 66 |
1 files changed, 38 insertions, 28 deletions
diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c index 28560b94083..ad8678e2200 100644 --- a/src/backend/tcop/postgres.c +++ b/src/backend/tcop/postgres.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.581 2010/01/07 16:29:58 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.582 2010/01/15 09:19:04 heikki Exp $ * * NOTES * this is the "main" module of the postgres backend and @@ -56,6 +56,7 @@ #include "parser/parser.h" #include "postmaster/autovacuum.h" #include "postmaster/postmaster.h" +#include "replication/walsender.h" #include "rewrite/rewriteHandler.h" #include "storage/bufmgr.h" #include "storage/ipc.h" @@ -3331,36 +3332,41 @@ PostgresMain(int argc, char *argv[], const char *username) * an issue for signals that are locally generated, such as SIGALRM and * SIGPIPE.) */ - pqsignal(SIGHUP, SigHupHandler); /* set flag to read config file */ - pqsignal(SIGINT, StatementCancelHandler); /* cancel current query */ - pqsignal(SIGTERM, die); /* cancel current query and exit */ - - /* - * In a standalone backend, SIGQUIT can be generated from the keyboard - * easily, while SIGTERM cannot, so we make both signals do die() rather - * than quickdie(). - */ - if (IsUnderPostmaster) - pqsignal(SIGQUIT, quickdie); /* hard crash time */ + if (am_walsender) + WalSndSignals(); else - pqsignal(SIGQUIT, die); /* cancel current query and exit */ - pqsignal(SIGALRM, handle_sig_alarm); /* timeout conditions */ + { + pqsignal(SIGHUP, SigHupHandler); /* set flag to read config file */ + pqsignal(SIGINT, StatementCancelHandler); /* cancel current query */ + pqsignal(SIGTERM, die); /* cancel current query and exit */ - /* - * Ignore failure to write to frontend. Note: if frontend closes - * connection, we will notice it and exit cleanly when control next - * returns to outer loop. This seems safer than forcing exit in the midst - * of output during who-knows-what operation... - */ - pqsignal(SIGPIPE, SIG_IGN); - pqsignal(SIGUSR1, procsignal_sigusr1_handler); - pqsignal(SIGUSR2, SIG_IGN); - pqsignal(SIGFPE, FloatExceptionHandler); + /* + * In a standalone backend, SIGQUIT can be generated from the keyboard + * easily, while SIGTERM cannot, so we make both signals do die() rather + * than quickdie(). + */ + if (IsUnderPostmaster) + pqsignal(SIGQUIT, quickdie); /* hard crash time */ + else + pqsignal(SIGQUIT, die); /* cancel current query and exit */ + pqsignal(SIGALRM, handle_sig_alarm); /* timeout conditions */ - /* - * Reset some signals that are accepted by postmaster but not by backend - */ - pqsignal(SIGCHLD, SIG_DFL); /* system() requires this on some platforms */ + /* + * Ignore failure to write to frontend. Note: if frontend closes + * connection, we will notice it and exit cleanly when control next + * returns to outer loop. This seems safer than forcing exit in the midst + * of output during who-knows-what operation... + */ + pqsignal(SIGPIPE, SIG_IGN); + pqsignal(SIGUSR1, procsignal_sigusr1_handler); + pqsignal(SIGUSR2, SIG_IGN); + pqsignal(SIGFPE, FloatExceptionHandler); + + /* + * Reset some signals that are accepted by postmaster but not by backend + */ + pqsignal(SIGCHLD, SIG_DFL); /* system() requires this on some platforms */ + } pqinitmask(); @@ -3456,6 +3462,10 @@ PostgresMain(int argc, char *argv[], const char *username) if (IsUnderPostmaster && Log_disconnections) on_proc_exit(log_disconnections, 0); + /* If this is a WAL sender process, we're done with initialization. */ + if (am_walsender) + proc_exit(WalSenderMain()); + /* * process any libraries that should be preloaded at backend start (this * likewise can't be done until GUC settings are complete) |