diff --git a/contrib/pgbench/pgbench.c b/contrib/pgbench/pgbench.c
index d5f8f73190d116857dec5233a027ca8d9420661b..8deabe4a5a8387ab433a1bf42b87c69223ee1872 100644
--- a/contrib/pgbench/pgbench.c
+++ b/contrib/pgbench/pgbench.c
@@ -35,7 +35,6 @@
 
 #include "getopt_long.h"
 #include "libpq-fe.h"
-#include "libpq/pqsignal.h"
 #include "portability/instr_time.h"
 
 #include <ctype.h>
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index a02eebcb27af04176f6984803b6ff2d263ecbd80..8e7341ba45ca2cbf77e44f0fa76155a9dd04f64a 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -35,7 +35,6 @@
 #include "catalog/catversion.h"
 #include "catalog/pg_control.h"
 #include "catalog/pg_database.h"
-#include "libpq/pqsignal.h"
 #include "miscadmin.h"
 #include "pgstat.h"
 #include "postmaster/bgwriter.h"
diff --git a/src/backend/libpq/pqsignal.c b/src/backend/libpq/pqsignal.c
index d088daeb7dd8f4bd8c81db37511f1882446dff8e..b621ba7addc1e8419574fe7d7082f3d45afd5ea0 100644
--- a/src/backend/libpq/pqsignal.c
+++ b/src/backend/libpq/pqsignal.c
@@ -1,8 +1,7 @@
 /*-------------------------------------------------------------------------
  *
  * pqsignal.c
- *	  reliable BSD-style signal(2) routine stolen from RWW who stole it
- *	  from Stevens...
+ *	  Backend signal(2) support (see also src/port/pqsignal.c)
  *
  * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
@@ -11,38 +10,11 @@
  * IDENTIFICATION
  *	  src/backend/libpq/pqsignal.c
  *
- * NOTES
- *		This shouldn't be in libpq, but the monitor and some other
- *		things need it...
- *
- *	A NOTE ABOUT SIGNAL HANDLING ACROSS THE VARIOUS PLATFORMS.
- *
- *	pg_config.h defines the macro HAVE_POSIX_SIGNALS for some platforms and
- *	not for others.  This file and pqsignal.h use that macro to decide
- *	how to handle signalling.
- *
- *	signal(2) handling - this is here because it affects some of
- *	the frontend commands as well as the backend processes.
- *
- *	Ultrix and SunOS provide BSD signal(2) semantics by default.
- *
- *	SVID2 and POSIX signal(2) semantics differ from BSD signal(2)
- *	semantics.	We can use the POSIX sigaction(2) on systems that
- *	allow us to request restartable signals (SA_RESTART).
- *
- *	Some systems don't allow restartable signals at all unless we
- *	link to a special BSD library.
- *
- *	We devoutly hope that there aren't any systems that provide
- *	neither POSIX signals nor BSD signals.	The alternative
- *	is to do signal-handler reinstallation, which doesn't work well
- *	at all.
- * ------------------------------------------------------------------------*/
+ * ------------------------------------------------------------------------
+ */
 
 #include "postgres.h"
 
-#include <signal.h>
-
 #include "libpq/pqsignal.h"
 
 
@@ -145,36 +117,3 @@ pqinitmask(void)
 		sigmask(SIGWINCH) | sigmask(SIGFPE);
 #endif
 }
-
-
-/* Win32 signal handling is in backend/port/win32/signal.c */
-#ifndef WIN32
-
-/*
- * Set up a signal handler
- */
-pqsigfunc
-pqsignal(int signo, pqsigfunc func)
-{
-#if !defined(HAVE_POSIX_SIGNALS)
-	return signal(signo, func);
-#else
-	struct sigaction act,
-				oact;
-
-	act.sa_handler = func;
-	sigemptyset(&act.sa_mask);
-	act.sa_flags = 0;
-	if (signo != SIGALRM)
-		act.sa_flags |= SA_RESTART;
-#ifdef SA_NOCLDSTOP
-	if (signo == SIGCHLD)
-		act.sa_flags |= SA_NOCLDSTOP;
-#endif
-	if (sigaction(signo, &act, &oact) < 0)
-		return SIG_ERR;
-	return oact.sa_handler;
-#endif   /* !HAVE_POSIX_SIGNALS */
-}
-
-#endif   /* WIN32 */
diff --git a/src/backend/main/main.c b/src/backend/main/main.c
index 1173bda62088dbaa6b913742be9c83b8d85e7388..8d4218e00bf980b42023dc75b10a3d9676a852f5 100644
--- a/src/backend/main/main.c
+++ b/src/backend/main/main.c
@@ -41,9 +41,6 @@
 #include "utils/help_config.h"
 #include "utils/pg_locale.h"
 #include "utils/ps_status.h"
-#ifdef WIN32
-#include "libpq/pqsignal.h"
-#endif
 
 
 const char *progname;
diff --git a/src/backend/port/win32/signal.c b/src/backend/port/win32/signal.c
index 2c406bc7f28a1a9c315752b1c0823fbaac4d057f..8b2d98141b5faa09620dc87bf765179d90819b84 100644
--- a/src/backend/port/win32/signal.c
+++ b/src/backend/port/win32/signal.c
@@ -13,7 +13,7 @@
 
 #include "postgres.h"
 
-#include <libpq/pqsignal.h>
+#include "libpq/pqsignal.h"
 
 /*
  * These are exported for use by the UNBLOCKED_SIGNAL_QUEUE() macro.
@@ -158,7 +158,11 @@ pqsigsetmask(int mask)
 }
 
 
-/* signal manipulation. Only called on main thread, no sync required */
+/*
+ * Unix-like signal handler installation
+ *
+ * Only called on main thread, no sync required
+ */
 pqsigfunc
 pqsignal(int signum, pqsigfunc handler)
 {
diff --git a/src/backend/port/win32/timer.c b/src/backend/port/win32/timer.c
index 13941044560973e2e2e4322f4eaced85e5a2c6d6..333beb44a84903465944d98d532bcbd4b3f02519 100644
--- a/src/backend/port/win32/timer.c
+++ b/src/backend/port/win32/timer.c
@@ -18,8 +18,6 @@
 
 #include "postgres.h"
 
-#include "libpq/pqsignal.h"
-
 
 /* Communication area for inter-thread communication */
 typedef struct timerCA
diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c
index 266cd64f6fa5b627e41761be3bb957c7f699dc5b..c05bb1e081841c11e70e37bdac0ddb1d2c55c4d4 100644
--- a/src/backend/replication/walsender.c
+++ b/src/backend/replication/walsender.c
@@ -49,7 +49,6 @@
 #include "funcapi.h"
 #include "libpq/libpq.h"
 #include "libpq/pqformat.h"
-#include "libpq/pqsignal.h"
 #include "miscadmin.h"
 #include "nodes/replnodes.h"
 #include "replication/basebackup.h"
diff --git a/src/backend/utils/misc/timeout.c b/src/backend/utils/misc/timeout.c
index 2ee6e00ed28c23b11bd7b7713daf682745db163f..b5a3c8f5df94af864ba4dfea039d860b70ca96c1 100644
--- a/src/backend/utils/misc/timeout.c
+++ b/src/backend/utils/misc/timeout.c
@@ -16,7 +16,6 @@
 
 #include <sys/time.h>
 
-#include "libpq/pqsignal.h"
 #include "storage/proc.h"
 #include "utils/timeout.h"
 #include "utils/timestamp.h"
diff --git a/src/bin/initdb/.gitignore b/src/bin/initdb/.gitignore
index c0ed2e8d169ef8401f54d5d6c85d0789a5013638..0f74727d8f6732d20333a2f13cea1f4d9c0e16a3 100644
--- a/src/bin/initdb/.gitignore
+++ b/src/bin/initdb/.gitignore
@@ -1,5 +1,4 @@
 /encnames.c
-/pqsignal.c
 /localtime.c
 
 /initdb
diff --git a/src/bin/initdb/Makefile b/src/bin/initdb/Makefile
index 4a6037933e148097da39e234616293bd70a2d174..458b4553738a63014539129b415a2be8c3b814b6 100644
--- a/src/bin/initdb/Makefile
+++ b/src/bin/initdb/Makefile
@@ -23,23 +23,20 @@ ifneq (,$(with_system_tzdata))
 override CPPFLAGS += '-DSYSTEMTZDIR="$(with_system_tzdata)"'
 endif
 
-OBJS=	initdb.o findtimezone.o localtime.o encnames.o pqsignal.o $(WIN32RES)
+OBJS=	initdb.o findtimezone.o localtime.o encnames.o $(WIN32RES)
 
 all: initdb
 
 initdb: $(OBJS) | submake-libpgport
 	$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
 
-# We used to pull in all of libpq to get encnames and pqsignal, but that
+# We used to pull in all of libpq to get encnames.c, but that
 # exposes us to risks of version skew if we link to a shared library.
 # Do it the hard way, instead, so that we're statically linked.
 
 encnames.c: % : $(top_srcdir)/src/backend/utils/mb/%
 	rm -f $@ && $(LN_S) $< .
 
-pqsignal.c: % : $(top_srcdir)/src/interfaces/libpq/%
-	rm -f $@ && $(LN_S) $< .
-
 # Likewise, pull in localtime.c from src/timezones
 
 localtime.c: % : $(top_srcdir)/src/timezone/%
@@ -55,7 +52,7 @@ uninstall:
 	rm -f '$(DESTDIR)$(bindir)/initdb$(X)'
 
 clean distclean maintainer-clean:
-	rm -f initdb$(X) $(OBJS) encnames.c pqsignal.c localtime.c
+	rm -f initdb$(X) $(OBJS) encnames.c localtime.c
 
 
 # ensure that changes in datadir propagate into object file
diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index b0b346f72a1f73e6959fe3f305eb2cae58406a04..e16f3e3c80a91188ee8be4048ae1e2db40b9cdf3 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -56,7 +56,6 @@
 #include <signal.h>
 #include <time.h>
 
-#include "libpq/pqsignal.h"
 #include "mb/pg_wchar.h"
 #include "getaddrinfo.h"
 #include "getopt_long.h"
diff --git a/src/bin/pg_basebackup/pg_receivexlog.c b/src/bin/pg_basebackup/pg_receivexlog.c
index 352ff3537688caddacfc5e68c8ec890cc83d78ca..e65f127d1d86a08dd9dfa4b0eb636dc6b13d1c24 100644
--- a/src/bin/pg_basebackup/pg_receivexlog.c
+++ b/src/bin/pg_basebackup/pg_receivexlog.c
@@ -14,7 +14,6 @@
 
 #include "postgres_fe.h"
 #include "libpq-fe.h"
-#include "libpq/pqsignal.h"
 #include "access/xlog_internal.h"
 
 #include "receivelog.h"
diff --git a/src/bin/pg_ctl/pg_ctl.c b/src/bin/pg_ctl/pg_ctl.c
index 7d5e16856e98b0282961f025ceab881a522af925..537d173e893b0a56d99e0015dd7764dc7c76c5af 100644
--- a/src/bin/pg_ctl/pg_ctl.c
+++ b/src/bin/pg_ctl/pg_ctl.c
@@ -33,7 +33,6 @@
 #include <sys/resource.h>
 #endif
 
-#include "libpq/pqsignal.h"
 #include "getopt_long.h"
 #include "miscadmin.h"
 
diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c
index dd183cacc142ee06c6d0390bd5c7535cb1bc3a05..be5e34a369a24f7b69ff1629dfdc5cedf74e3f93 100644
--- a/src/bin/psql/common.c
+++ b/src/bin/psql/common.c
@@ -19,8 +19,6 @@
 
 #include "portability/instr_time.h"
 
-#include "pqsignal.h"
-
 #include "settings.h"
 #include "command.h"
 #include "copy.h"
diff --git a/src/bin/psql/copy.c b/src/bin/psql/copy.c
index a97795f943e1c97e0c840eca2f83240a2f80d56b..57cbf92816176bf5a6da973b2259bce7506dc311 100644
--- a/src/bin/psql/copy.c
+++ b/src/bin/psql/copy.c
@@ -18,7 +18,6 @@
 
 #include "libpq-fe.h"
 #include "pqexpbuffer.h"
-#include "pqsignal.h"
 #include "dumputils.h"
 
 #include "settings.h"
diff --git a/src/bin/psql/print.c b/src/bin/psql/print.c
index 0722c984a8261f130d2ab8f983369c9c09701abe..7e1f27ac9e224a6e52a09ce97fad12d11d3516bf 100644
--- a/src/bin/psql/print.c
+++ b/src/bin/psql/print.c
@@ -23,7 +23,6 @@
 #include <locale.h>
 
 #include "catalog/pg_type.h"
-#include "pqsignal.h"
 
 #include "common.h"
 #include "mbprint.h"
diff --git a/src/bin/scripts/common.c b/src/bin/scripts/common.c
index 03193b6fcdc78c3a7a49273008a9eec7f21aba24..4645bc137f94aebb9d089e66fd7960aa1300d283 100644
--- a/src/bin/scripts/common.c
+++ b/src/bin/scripts/common.c
@@ -19,7 +19,6 @@
 #include <unistd.h>
 
 #include "common.h"
-#include "libpq/pqsignal.h"
 
 static void SetCancelConn(PGconn *conn);
 static void ResetCancelConn(void);
diff --git a/src/include/libpq/pqsignal.h b/src/include/libpq/pqsignal.h
index bc0bcef040c3d8a065e4188ad8f7a4a3a8d929f6..1889dca4b9e5040b6e0bb5f8467dc59fe7396ced 100644
--- a/src/include/libpq/pqsignal.h
+++ b/src/include/libpq/pqsignal.h
@@ -1,18 +1,13 @@
 /*-------------------------------------------------------------------------
  *
  * pqsignal.h
- *	  prototypes for the reliable BSD-style signal(2) routine.
- *
+ *	  Backend signal(2) support (see also src/port/pqsignal.c)
  *
  * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * src/include/libpq/pqsignal.h
  *
- * NOTES
- *	  This shouldn't be in libpq, but the monitor and some other
- *	  things need it...
- *
  *-------------------------------------------------------------------------
  */
 #ifndef PQSIGNAL_H
@@ -42,10 +37,6 @@ int			pqsigsetmask(int mask);
 #define sigdelset(set, signum)	(*(set) &= ~(sigmask(signum)))
 #endif   /* not HAVE_SIGPROCMASK */
 
-typedef void (*pqsigfunc) (int);
-
 extern void pqinitmask(void);
 
-extern pqsigfunc pqsignal(int signo, pqsigfunc func);
-
 #endif   /* PQSIGNAL_H */
diff --git a/src/include/port.h b/src/include/port.h
index c5d0e0a9709e197dbd99f7e26e8bec36e6e45b88..cde4ad5607567235ac784fab824c4c5f2ff174f9 100644
--- a/src/include/port.h
+++ b/src/include/port.h
@@ -462,6 +462,13 @@ extern int	pg_check_dir(const char *dir);
 /* port/pgmkdirp.c */
 extern int	pg_mkdir_p(char *path, int omode);
 
+/* port/pqsignal.c */
+/* On Windows, we can emulate pqsignal in the backend, but not frontend */
+#if !defined(WIN32) || !defined(FRONTEND)
+typedef void (*pqsigfunc) (int signo);
+extern pqsigfunc pqsignal(int signo, pqsigfunc func);
+#endif
+
 /* port/quotes.c */
 extern char *escape_single_quotes_ascii(const char *src);
 
diff --git a/src/interfaces/libpq/Makefile b/src/interfaces/libpq/Makefile
index f594f7e499b9a3a529cfa931ba801a2818a3bcb3..c45856efb6bad1fe4770cb546f0f0bd3be621b03 100644
--- a/src/interfaces/libpq/Makefile
+++ b/src/interfaces/libpq/Makefile
@@ -32,7 +32,7 @@ LIBS := $(LIBS:-lpgport=)
 # We can't use Makefile variables here because the MSVC build system scrapes
 # OBJS from this file.
 OBJS=	fe-auth.o fe-connect.o fe-exec.o fe-misc.o fe-print.o fe-lobj.o \
-	fe-protocol2.o fe-protocol3.o pqexpbuffer.o pqsignal.o fe-secure.o \
+	fe-protocol2.o fe-protocol3.o pqexpbuffer.o fe-secure.o \
 	libpq-events.o
 # libpgport C files we always use
 OBJS += chklocale.o inet_net_ntop.o noblock.o pgstrcasecmp.o thread.o
diff --git a/src/interfaces/libpq/bcc32.mak b/src/interfaces/libpq/bcc32.mak
index 441fb5e76fb68b2ccda18b6c5f3aa5747b6ecb68..6282196446949044c1c57125f865069351077302 100644
--- a/src/interfaces/libpq/bcc32.mak
+++ b/src/interfaces/libpq/bcc32.mak
@@ -95,7 +95,6 @@ CLEAN :
 	-@erase "$(INTDIR)\fe-secure.obj"
 	-@erase "$(INTDIR)\libpq-events.obj"
 	-@erase "$(INTDIR)\pqexpbuffer.obj"
-	-@erase "$(INTDIR)\pqsignal.obj"
 	-@erase "$(INTDIR)\win32.obj"
 	-@erase "$(INTDIR)\wchar.obj"
 	-@erase "$(INTDIR)\encnames.obj"
@@ -140,7 +139,6 @@ LIB32_OBJS= \
 	"$(INTDIR)\fe-secure.obj" \
 	"$(INTDIR)\libpq-events.obj" \
 	"$(INTDIR)\pqexpbuffer.obj" \
-	"$(INTDIR)\pqsignal.obj" \
 	"$(INTDIR)\wchar.obj" \
 	"$(INTDIR)\encnames.obj" \
 	"$(INTDIR)\snprintf.obj" \
diff --git a/src/interfaces/libpq/fe-misc.c b/src/interfaces/libpq/fe-misc.c
index cea3776c33c0f00f7eaa5572309c5f5b1ffceae2..6be3249638ce5909fe0a6f411144dc0707154430 100644
--- a/src/interfaces/libpq/fe-misc.c
+++ b/src/interfaces/libpq/fe-misc.c
@@ -55,7 +55,6 @@
 
 #include "libpq-fe.h"
 #include "libpq-int.h"
-#include "pqsignal.h"
 #include "mb/pg_wchar.h"
 #include "pg_config_paths.h"
 
diff --git a/src/interfaces/libpq/fe-print.c b/src/interfaces/libpq/fe-print.c
index 5c86f037d712085f0a91941deb20b7ccc67ad5ba..b0fab6a839f7a9e86b744a698fe72c59bce0daae 100644
--- a/src/interfaces/libpq/fe-print.c
+++ b/src/interfaces/libpq/fe-print.c
@@ -35,7 +35,6 @@
 
 #include "libpq-fe.h"
 #include "libpq-int.h"
-#include "pqsignal.h"
 
 
 static void do_field(const PQprintOpt *po, const PGresult *res,
diff --git a/src/interfaces/libpq/fe-secure.c b/src/interfaces/libpq/fe-secure.c
index 574d3bae8f4717ce21acfb055ca87e19bd17d2db..174cf426f06f3d00c4849c605c164e56b6a7b111 100644
--- a/src/interfaces/libpq/fe-secure.c
+++ b/src/interfaces/libpq/fe-secure.c
@@ -30,7 +30,6 @@
 
 #include "libpq-fe.h"
 #include "fe-auth.h"
-#include "pqsignal.h"
 #include "libpq-int.h"
 
 #ifdef WIN32
diff --git a/src/interfaces/libpq/pqsignal.c b/src/interfaces/libpq/pqsignal.c
deleted file mode 100644
index 26e203b6690fd17f5ec3bbeae8a56281a738a14e..0000000000000000000000000000000000000000
--- a/src/interfaces/libpq/pqsignal.c
+++ /dev/null
@@ -1,49 +0,0 @@
-/*-------------------------------------------------------------------------
- *
- * pqsignal.c
- *	  reliable BSD-style signal(2) routine stolen from RWW who stole it
- *	  from Stevens...
- *
- * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
- * Portions Copyright (c) 1994, Regents of the University of California
- *
- *
- * IDENTIFICATION
- *	  src/interfaces/libpq/pqsignal.c
- *
- * NOTES
- *		This shouldn't be in libpq, but the monitor and some other
- *		things need it...
- *
- *-------------------------------------------------------------------------
- */
-#include "postgres_fe.h"
-
-#include <signal.h>
-
-#include "pqsignal.h"
-
-
-pqsigfunc
-pqsignal(int signo, pqsigfunc func)
-{
-#if !defined(HAVE_POSIX_SIGNALS)
-	return signal(signo, func);
-#else
-	struct sigaction act,
-				oact;
-
-	act.sa_handler = func;
-	sigemptyset(&act.sa_mask);
-	act.sa_flags = 0;
-	if (signo != SIGALRM)
-		act.sa_flags |= SA_RESTART;
-#ifdef SA_NOCLDSTOP
-	if (signo == SIGCHLD)
-		act.sa_flags |= SA_NOCLDSTOP;
-#endif
-	if (sigaction(signo, &act, &oact) < 0)
-		return SIG_ERR;
-	return oact.sa_handler;
-#endif   /* !HAVE_POSIX_SIGNALS */
-}
diff --git a/src/interfaces/libpq/pqsignal.h b/src/interfaces/libpq/pqsignal.h
deleted file mode 100644
index 2a72327d796633241ce22b22759fbf3d8f0c8403..0000000000000000000000000000000000000000
--- a/src/interfaces/libpq/pqsignal.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/*-------------------------------------------------------------------------
- *
- * pqsignal.h
- *	  prototypes for the reliable BSD-style signal(2) routine.
- *
- *
- * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
- * Portions Copyright (c) 1994, Regents of the University of California
- *
- * src/interfaces/libpq/pqsignal.h
- *
- * NOTES
- *	  This shouldn't be in libpq, but the monitor and some other
- *	  things need it...
- *
- *-------------------------------------------------------------------------
- */
-#ifndef PQSIGNAL_H
-#define PQSIGNAL_H
-
-typedef void (*pqsigfunc) (int);
-
-extern pqsigfunc pqsignal(int signo, pqsigfunc func);
-
-#endif   /* PQSIGNAL_H */
diff --git a/src/interfaces/libpq/win32.mak b/src/interfaces/libpq/win32.mak
index 9355de23cefe0f3477c0a2dd200de192ef03774a..49d51d11fb93c9d51a9f762a9f4d755a3f63ae84 100644
--- a/src/interfaces/libpq/win32.mak
+++ b/src/interfaces/libpq/win32.mak
@@ -102,7 +102,6 @@ CLEAN :
 	-@erase "$(INTDIR)\fe-secure.obj"
 	-@erase "$(INTDIR)\libpq-events.obj"
 	-@erase "$(INTDIR)\pqexpbuffer.obj"
-	-@erase "$(INTDIR)\pqsignal.obj"
 	-@erase "$(INTDIR)\win32.obj"
 	-@erase "$(INTDIR)\wchar.obj"
 	-@erase "$(INTDIR)\encnames.obj"
@@ -150,7 +149,6 @@ LIB32_OBJS= \
 	"$(INTDIR)\fe-secure.obj" \
 	"$(INTDIR)\libpq-events.obj" \
 	"$(INTDIR)\pqexpbuffer.obj" \
-	"$(INTDIR)\pqsignal.obj" \
 	"$(INTDIR)\wchar.obj" \
 	"$(INTDIR)\encnames.obj" \
 	"$(INTDIR)\snprintf.obj" \
diff --git a/src/pl/plperl/plperl.c b/src/pl/plperl/plperl.c
index 1463618e420bac84dc62446040fea960b33ff5dc..ef56a4fab4c6ada3f0530509d889579d82bbaf8f 100644
--- a/src/pl/plperl/plperl.c
+++ b/src/pl/plperl/plperl.c
@@ -24,7 +24,6 @@
 #include "commands/trigger.h"
 #include "executor/spi.h"
 #include "funcapi.h"
-#include "libpq/pqsignal.h"
 #include "mb/pg_wchar.h"
 #include "miscadmin.h"
 #include "nodes/makefuncs.h"
diff --git a/src/port/Makefile b/src/port/Makefile
index 0774e33f9fb4a2d3a275f3b0383e09a66e79d190..a032acca1c26be025aef180e9f52911790dc2fbc 100644
--- a/src/port/Makefile
+++ b/src/port/Makefile
@@ -32,7 +32,8 @@ LIBS += $(PTHREAD_LIBS)
 
 OBJS = $(LIBOBJS) chklocale.o dirmod.o erand48.o exec.o fls.o inet_net_ntop.o \
 	noblock.o path.o pgcheckdir.o pg_crc.o pgmkdirp.o pgsleep.o \
-	pgstrcasecmp.o qsort.o qsort_arg.o quotes.o sprompt.o tar.o thread.o \
+	pgstrcasecmp.o pqsignal.o \
+	qsort.o qsort_arg.o quotes.o sprompt.o tar.o thread.o \
 	wait_error.o
 
 # foo_srv.o and foo.o are both built from foo.c, but only foo.o has -DFRONTEND
diff --git a/src/port/pqsignal.c b/src/port/pqsignal.c
new file mode 100644
index 0000000000000000000000000000000000000000..ffb6f84330896645f332e6bf961a36de3982d96c
--- /dev/null
+++ b/src/port/pqsignal.c
@@ -0,0 +1,76 @@
+/*-------------------------------------------------------------------------
+ *
+ * pqsignal.c
+ *	  reliable BSD-style signal(2) routine stolen from RWW who stole it
+ *	  from Stevens...
+ *
+ * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ *
+ * IDENTIFICATION
+ *	  src/port/pqsignal.c
+ *
+ *	A NOTE ABOUT SIGNAL HANDLING ACROSS THE VARIOUS PLATFORMS.
+ *
+ *	pg_config.h defines the macro HAVE_POSIX_SIGNALS for some platforms and
+ *	not for others.  We use that here to decide how to handle signalling.
+ *
+ *	Ultrix and SunOS provide BSD signal(2) semantics by default.
+ *
+ *	SVID2 and POSIX signal(2) semantics differ from BSD signal(2)
+ *	semantics.	We can use the POSIX sigaction(2) on systems that
+ *	allow us to request restartable signals (SA_RESTART).
+ *
+ *	Some systems don't allow restartable signals at all unless we
+ *	link to a special BSD library.
+ *
+ *	We devoutly hope that there aren't any Unix-oid systems that provide
+ *	neither POSIX signals nor BSD signals.	The alternative is to do
+ *	signal-handler reinstallation, which doesn't work well at all.
+ *
+ *	Windows, of course, is resolutely in a class by itself.  This file
+ *	should not get compiled at all on Windows.  We have an emulation of
+ *	pqsignal() in src/backend/port/win32/signal.c for the backend
+ *	environment; frontend programs are out of luck.
+ * ------------------------------------------------------------------------
+ */
+
+#include "c.h"
+
+#include <signal.h>
+
+#ifndef WIN32
+
+/*
+ * Set up a signal handler for signal "signo"
+ *
+ * Returns the previous handler.  It's expected that the installed handler
+ * will persist across multiple deliveries of the signal (unlike the original
+ * POSIX definition of signal(2)).
+ */
+pqsigfunc
+pqsignal(int signo, pqsigfunc func)
+{
+#if !defined(HAVE_POSIX_SIGNALS)
+	return signal(signo, func);
+#else
+	struct sigaction act,
+				oact;
+
+	act.sa_handler = func;
+	sigemptyset(&act.sa_mask);
+	act.sa_flags = 0;
+	if (signo != SIGALRM)
+		act.sa_flags |= SA_RESTART;
+#ifdef SA_NOCLDSTOP
+	if (signo == SIGCHLD)
+		act.sa_flags |= SA_NOCLDSTOP;
+#endif
+	if (sigaction(signo, &act, &oact) < 0)
+		return SIG_ERR;
+	return oact.sa_handler;
+#endif   /* !HAVE_POSIX_SIGNALS */
+}
+
+#endif /* WIN32 */