diff --git a/src/backend/libpq/pqsignal.c b/src/backend/libpq/pqsignal.c
index 9bdcd27b703690ca6590f68a444704ec04f0e5d7..028db1040896121c8a9cd8b973a86761638d5e96 100644
--- a/src/backend/libpq/pqsignal.c
+++ b/src/backend/libpq/pqsignal.c
@@ -9,7 +9,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/libpq/pqsignal.c,v 1.21 2001/08/24 14:07:49 petere Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/libpq/pqsignal.c,v 1.22 2001/09/07 16:12:48 wieck Exp $
  *
  * NOTES
  *		This shouldn't be in libpq, but the monitor and some other
@@ -61,6 +61,7 @@ pqinitmask(void)
 #ifdef HAVE_SIGPROCMASK
 	sigemptyset(&UnBlockSig);
 	sigfillset(&BlockSig);
+	sigfillset(&AuthBlockSig);
 
 	/*
 	 * Unmark those signals that should never be blocked. Some of these
@@ -69,27 +70,41 @@ pqinitmask(void)
 	 */
 #ifdef SIGTRAP
 	sigdelset(&BlockSig, SIGTRAP);
+	sigdelset(&AuthBlockSig, SIGTRAP);
 #endif
 #ifdef SIGABRT
 	sigdelset(&BlockSig, SIGABRT);
+	sigdelset(&AuthBlockSig, SIGABRT);
 #endif
 #ifdef SIGILL
 	sigdelset(&BlockSig, SIGILL);
+	sigdelset(&AuthBlockSig, SIGILL);
 #endif
 #ifdef SIGFPE
 	sigdelset(&BlockSig, SIGFPE);
+	sigdelset(&AuthBlockSig, SIGFPE);
 #endif
 #ifdef SIGSEGV
 	sigdelset(&BlockSig, SIGSEGV);
+	sigdelset(&AuthBlockSig, SIGSEGV);
 #endif
 #ifdef SIGBUS
 	sigdelset(&BlockSig, SIGBUS);
+	sigdelset(&AuthBlockSig, SIGBUS);
 #endif
 #ifdef SIGSYS
 	sigdelset(&BlockSig, SIGSYS);
+	sigdelset(&AuthBlockSig, SIGSYS);
 #endif
 #ifdef SIGCONT
 	sigdelset(&BlockSig, SIGCONT);
+	sigdelset(&AuthBlockSig, SIGCONT);
+#endif
+#ifdef SIGTERM
+	sigdelset(&AuthBlockSig, SIGTERM);
+#endif
+#ifdef SIGQUIT
+	sigdelset(&AuthBlockSig, SIGQUIT);
 #endif
 #else
 	UnBlockSig = 0;
@@ -98,6 +113,10 @@ pqinitmask(void)
 		sigmask(SIGINT) | sigmask(SIGUSR1) |
 		sigmask(SIGUSR2) | sigmask(SIGCHLD) |
 		sigmask(SIGWINCH) | sigmask(SIGFPE);
+	AuthBlockSig = sigmask(SIGHUP) | sigmask(SIGALRM) |
+		sigmask(SIGINT) | sigmask(SIGUSR1) |
+		sigmask(SIGUSR2) | sigmask(SIGCHLD) |
+		sigmask(SIGWINCH) | sigmask(SIGFPE);
 #endif
 }
 
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index 5cdf81cd8fadfd7fa8a94a4732f9c4f91307a7ab..0de3ad6b12b83e1fddf010d450a4e6a23285925b 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -37,7 +37,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.239 2001/09/07 00:46:42 tgl Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.240 2001/09/07 16:12:48 wieck Exp $
  *
  * NOTES
  *
@@ -112,10 +112,12 @@
 
 #ifdef HAVE_SIGPROCMASK
 sigset_t	UnBlockSig,
-			BlockSig;
+			BlockSig,
+			AuthBlockSig;
 #else
 int			UnBlockSig,
-			BlockSig;
+			BlockSig,
+			AuthBlockSig;
 #endif
 
 /*
@@ -1932,6 +1934,16 @@ DoBackend(Port *port)
 
 	whereToSendOutput = Remote;	/* XXX probably doesn't belong here */
 
+	/*
+	 * We arrange for a simple exit(0) if we receive SIGTERM or SIGQUIT
+	 * during any client authentication related communication. Otherwise
+	 * the postmaster cannot shutdown the database FAST or IMMED cleanly
+	 * if a buggy client blocks a backend during authentication.
+	 */
+	pqsignal(SIGTERM, authdie);
+	pqsignal(SIGQUIT, authdie);
+	PG_SETMASK(&AuthBlockSig);
+
 	/*
 	 * Receive the startup packet (which might turn out to be a cancel
 	 * request packet); then perform client authentication.
@@ -1943,6 +1955,8 @@ DoBackend(Port *port)
 
 	ClientAuthentication(MyProcPort); /* might not return, if failure */
 
+	PG_SETMASK(&BlockSig);
+
 	/*
 	 * Don't want backend to be able to see the postmaster random number
 	 * generator state.  We have to clobber the static random_seed *and*
diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c
index ac701704c16756b94822fb23277afa1d38867531..b8c57bb4d7d325c8a475a27a99ed4063efa216f7 100644
--- a/src/backend/tcop/postgres.c
+++ b/src/backend/tcop/postgres.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.230 2001/08/04 00:14:43 tgl Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.231 2001/09/07 16:12:48 wieck Exp $
  *
  * NOTES
  *	  this is the "main" module of the postgres backend and
@@ -965,6 +965,16 @@ die(SIGNAL_ARGS)
 	errno = save_errno;
 }
 
+/*
+ * Shutdown signal from postmaster during client authentication.
+ * Simply exit(0).
+ */
+void
+authdie(SIGNAL_ARGS)
+{
+	exit(0);
+}
+
 /*
  * Query-cancel signal from postmaster: abort current transaction
  * at soonest convenient time
@@ -1713,7 +1723,7 @@ PostgresMain(int argc, char *argv[],
 	if (!IsUnderPostmaster)
 	{
 		puts("\nPOSTGRES backend interactive interface ");
-		puts("$Revision: 1.230 $ $Date: 2001/08/04 00:14:43 $\n");
+		puts("$Revision: 1.231 $ $Date: 2001/09/07 16:12:48 $\n");
 	}
 
 	/*
diff --git a/src/include/libpq/pqsignal.h b/src/include/libpq/pqsignal.h
index ec22aa4b990cf72a4ade641d93e40020aab121de..812377186fca26e619d6a43207ef2f810d63ec6f 100644
--- a/src/include/libpq/pqsignal.h
+++ b/src/include/libpq/pqsignal.h
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: pqsignal.h,v 1.15 2001/01/24 19:43:25 momjian Exp $
+ * $Id: pqsignal.h,v 1.16 2001/09/07 16:12:49 wieck Exp $
  *
  * NOTES
  *	  This shouldn't be in libpq, but the monitor and some other
@@ -22,7 +22,8 @@
 
 #ifdef HAVE_SIGPROCMASK
 extern sigset_t UnBlockSig,
-			BlockSig;
+			BlockSig,
+			AuthBlockSig;
 
 #define PG_SETMASK(mask)	sigprocmask(SIG_SETMASK, mask, NULL)
 #else
diff --git a/src/include/tcop/tcopprot.h b/src/include/tcop/tcopprot.h
index d29dddd40ada409c35b1e8767c3010eb8c1de2c6..dccea51fe253edc572948bcd95d78390ec076d57 100644
--- a/src/include/tcop/tcopprot.h
+++ b/src/include/tcop/tcopprot.h
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: tcopprot.h,v 1.41 2001/06/08 21:16:48 petere Exp $
+ * $Id: tcopprot.h,v 1.42 2001/09/07 16:12:49 wieck Exp $
  *
  * OLD COMMENTS
  *	  This file was created so that other c files could get the two
@@ -44,6 +44,7 @@ extern void pg_exec_query_string(char *query_string,
 
 extern void die(SIGNAL_ARGS);
 extern void quickdie(SIGNAL_ARGS);
+extern void authdie(SIGNAL_ARGS);
 extern int PostgresMain(int argc, char *argv[],
 			 int real_argc, char *real_argv[], const char *username);
 extern void ResetUsage(void);