Commit 9b4bfbdc authored by Peter Eisentraut's avatar Peter Eisentraut

Handle reading of startup packet and authentication exchange after forking

a new postmaster child process.  This should eliminate problems with
authentication blocking (e.g., ident, SSL init) and also reduce problems
with the accept queue filling up under heavy load.

The option to send elog output to a different file per backend (postgres -o)
has been disabled for now because the initialization would have to happen
in a different order and it's not clear we want to keep this anyway.
parent 588463a4
This diff is collapsed.
This diff is collapsed.
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.222 2001/06/19 23:40:10 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.223 2001/06/20 18:07:55 petere Exp $
* *
* NOTES * NOTES
* this is the "main" module of the postgres backend and * this is the "main" module of the postgres backend and
...@@ -45,6 +45,7 @@ ...@@ -45,6 +45,7 @@
#include "libpq/pqformat.h" #include "libpq/pqformat.h"
#include "libpq/pqsignal.h" #include "libpq/pqsignal.h"
#include "miscadmin.h" #include "miscadmin.h"
#include "libpq/auth.h"
#include "nodes/print.h" #include "nodes/print.h"
#include "optimizer/cost.h" #include "optimizer/cost.h"
#include "optimizer/planner.h" #include "optimizer/planner.h"
...@@ -1142,11 +1143,13 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[], const cha ...@@ -1142,11 +1143,13 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[], const cha
*/ */
if (!IsUnderPostmaster) if (!IsUnderPostmaster)
{ {
SetProcessingMode(InitProcessing);
EnableExceptionHandling(true); EnableExceptionHandling(true);
MemoryContextInit(); MemoryContextInit();
} }
SetProcessingMode(InitProcessing); if (IsUnderPostmaster)
ClientAuthentication(MyProcPort); /* might not return */
/* /*
* Set default values for command-line options. * Set default values for command-line options.
...@@ -1567,13 +1570,11 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[], const cha ...@@ -1567,13 +1570,11 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[], const cha
* restart... */ * restart... */
} }
pq_init(); /* initialize libpq at backend startup */ pq_init(); /* initialize libpq at backend startup */
whereToSendOutput = Remote;
BaseInit(); BaseInit();
} }
else else
{ {
/* interactive case: database name can be last arg on command line */ /* interactive case: database name can be last arg on command line */
whereToSendOutput = Debug;
if (errs || argc - optind > 1) if (errs || argc - optind > 1)
{ {
fprintf(stderr, "%s: invalid command line arguments\nTry -? for help.\n", argv[0]); fprintf(stderr, "%s: invalid command line arguments\nTry -? for help.\n", argv[0]);
...@@ -1709,7 +1710,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[], const cha ...@@ -1709,7 +1710,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[], const cha
if (!IsUnderPostmaster) if (!IsUnderPostmaster)
{ {
puts("\nPOSTGRES backend interactive interface "); puts("\nPOSTGRES backend interactive interface ");
puts("$Revision: 1.222 $ $Date: 2001/06/19 23:40:10 $\n"); puts("$Revision: 1.223 $ $Date: 2001/06/20 18:07:55 $\n");
} }
/* /*
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.86 2001/06/08 21:16:48 petere Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.87 2001/06/20 18:07:56 petere Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -129,10 +129,6 @@ elog(int lev, const char *fmt,...) ...@@ -129,10 +129,6 @@ elog(int lev, const char *fmt,...)
/* size of the prefix needed for timestamp and pid, if enabled */ /* size of the prefix needed for timestamp and pid, if enabled */
size_t timestamp_size; size_t timestamp_size;
/* ignore debug msgs if noplace to send */
if (lev == DEBUG && Debugfile < 0)
return;
/* Save error str before calling any function that might change errno */ /* Save error str before calling any function that might change errno */
errorstr = useful_strerror(errno); errorstr = useful_strerror(errno);
...@@ -336,10 +332,9 @@ elog(int lev, const char *fmt,...) ...@@ -336,10 +332,9 @@ elog(int lev, const char *fmt,...)
/* syslog doesn't want a trailing newline, but other destinations do */ /* syslog doesn't want a trailing newline, but other destinations do */
strcat(msg_buf, "\n"); strcat(msg_buf, "\n");
/* Write to debug file, if open and enabled */ /* write to terminal */
/* NOTE: debug file is typically pointed at stderr */ if (Use_syslog <= 1 || whereToSendOutput == Debug)
if (Debugfile >= 0 && Use_syslog <= 1) write(2, msg_buf, strlen(msg_buf));
write(Debugfile, msg_buf, strlen(msg_buf));
if (lev > DEBUG && whereToSendOutput == Remote) if (lev > DEBUG && whereToSendOutput == Remote)
{ {
...@@ -371,17 +366,6 @@ elog(int lev, const char *fmt,...) ...@@ -371,17 +366,6 @@ elog(int lev, const char *fmt,...)
MemoryContextSwitchTo(oldcxt); MemoryContextSwitchTo(oldcxt);
} }
if (lev > DEBUG && whereToSendOutput != Remote)
{
/*
* We are running as an interactive backend, so just send the
* message to stderr. But don't send a duplicate if Debugfile
* write, above, already sent to stderr.
*/
if (Debugfile != fileno(stderr))
fputs(msg_buf, stderr);
}
/* done with the message, release space */ /* done with the message, release space */
if (fmt_buf != fmt_fixedbuf) if (fmt_buf != fmt_fixedbuf)
free(fmt_buf); free(fmt_buf);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.71 2001/06/14 01:09:22 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.72 2001/06/20 18:07:56 petere Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "catalog/catname.h" #include "catalog/catname.h"
#include "catalog/pg_shadow.h" #include "catalog/pg_shadow.h"
#include "libpq/libpq-be.h"
#include "miscadmin.h" #include "miscadmin.h"
#include "utils/builtins.h" #include "utils/builtins.h"
#include "utils/lsyscache.h" #include "utils/lsyscache.h"
...@@ -279,6 +280,7 @@ SetCharSet() ...@@ -279,6 +280,7 @@ SetCharSet()
int i; int i;
unsigned char FromChar, unsigned char FromChar,
ToChar; ToChar;
char ChTable[80];
for (i = 0; i < 128; i++) for (i = 0; i < 128; i++)
{ {
...@@ -286,11 +288,17 @@ SetCharSet() ...@@ -286,11 +288,17 @@ SetCharSet()
RecodeBackTable[i] = i + 128; RecodeBackTable[i] = i + 128;
} }
if (IsUnderPostmaster)
{
GetCharSetByHost(ChTable, MyProcPort->raddr.in.sin_addr.s_addr, DataDir);
p = ChTable;
}
else
p = getenv("PG_RECODETABLE"); p = getenv("PG_RECODETABLE");
if (p && *p != '\0') if (p && *p != '\0')
{ {
map_file = (char *) malloc((strlen(DataDir) + map_file = malloc(strlen(DataDir) + strlen(p) + 2);
strlen(p) + 2) * sizeof(char));
if (! map_file) if (! map_file)
elog(FATAL, "out of memory"); elog(FATAL, "out of memory");
sprintf(map_file, "%s/%s", DataDir, p); sprintf(map_file, "%s/%s", DataDir, p);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: auth.h,v 1.16 2001/03/22 04:00:47 momjian Exp $ * $Id: auth.h,v 1.17 2001/06/20 18:07:56 petere Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
*---------------------------------------------------------------- *----------------------------------------------------------------
*/ */
void be_recvauth(Port *port); void ClientAuthentication(Port *port);
#define PG_KRB4_VERSION "PGVER4.1" /* at most KRB_SENDAUTH_VLEN chars */ #define PG_KRB4_VERSION "PGVER4.1" /* at most KRB_SENDAUTH_VLEN chars */
#define PG_KRB5_VERSION "PGVER5.1" #define PG_KRB5_VERSION "PGVER5.1"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment