summaryrefslogtreecommitdiff
path: root/src/backend/libpq
diff options
context:
space:
mode:
authorTom Lane2000-06-28 03:33:33 +0000
committerTom Lane2000-06-28 03:33:33 +0000
commit1aebc3618a0be13451918581ad390ad9a3518702 (patch)
treee8ab228245c43ff086bd8e9d65baf3d1d9a5f96a /src/backend/libpq
parentb601c8d8828ee02ffb195dead82b233b9572fe32 (diff)
First phase of memory management rewrite (see backend/utils/mmgr/README
for details). It doesn't really do that much yet, since there are no short-term memory contexts in the executor, but the infrastructure is in place and long-term contexts are handled reasonably. A few long- standing bugs have been fixed, such as 'VACUUM; anything' in a single query string crashing. Also, out-of-memory is now considered a recoverable ERROR, not FATAL. Eliminate a large amount of crufty, now-dead code in and around memory management. Fix problem with holding off SIGTRAP, SIGSEGV, etc in postmaster and backend startup.
Diffstat (limited to 'src/backend/libpq')
-rw-r--r--src/backend/libpq/be-fsstubs.c41
-rw-r--r--src/backend/libpq/be-pqexec.c6
-rw-r--r--src/backend/libpq/pqsignal.c40
3 files changed, 69 insertions, 18 deletions
diff --git a/src/backend/libpq/be-fsstubs.c b/src/backend/libpq/be-fsstubs.c
index a12ae3a8a82..75f6562a8f6 100644
--- a/src/backend/libpq/be-fsstubs.c
+++ b/src/backend/libpq/be-fsstubs.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/libpq/be-fsstubs.c,v 1.46 2000/06/09 01:11:06 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/libpq/be-fsstubs.c,v 1.47 2000/06/28 03:31:41 tgl Exp $
*
* NOTES
* This should be moved to a more appropriate place. It is here
@@ -16,7 +16,7 @@
*
* Builtin functions for open/close/read/write operations on large objects.
*
- * These functions operate in a private GlobalMemoryContext, which means
+ * These functions operate in a private MemoryContext, which means
* that large object descriptors hang around until we destroy the context.
* That happens in lo_commit(). It'd be possible to prolong the lifetime
* of the context so that LO FDs are good across transactions (for example,
@@ -24,8 +24,10 @@
* But we'd need additional state in order to do the right thing at the
* end of an aborted transaction. FDs opened during an aborted xact would
* still need to be closed, since they might not be pointing at valid
- * relations at all. For now, we'll stick with the existing documented
- * semantics of LO FDs: they're only good within a transaction.
+ * relations at all. Locking semantics are also an interesting problem
+ * if LOs stay open across transactions. For now, we'll stick with the
+ * existing documented semantics of LO FDs: they're only good within a
+ * transaction.
*
*-------------------------------------------------------------------------
*/
@@ -56,7 +58,7 @@
*/
static LargeObjectDesc *cookies[MAX_LOBJ_FDS];
-static GlobalMemory fscxt = NULL;
+static MemoryContext fscxt = NULL;
static int newLOfd(LargeObjectDesc *lobjCookie);
@@ -80,8 +82,13 @@ lo_open(PG_FUNCTION_ARGS)
#endif
if (fscxt == NULL)
- fscxt = CreateGlobalMemory("Filesystem");
- currentContext = MemoryContextSwitchTo((MemoryContext) fscxt);
+ fscxt = AllocSetContextCreate(TopMemoryContext,
+ "Filesystem",
+ ALLOCSET_DEFAULT_MINSIZE,
+ ALLOCSET_DEFAULT_INITSIZE,
+ ALLOCSET_DEFAULT_MAXSIZE);
+
+ currentContext = MemoryContextSwitchTo(fscxt);
lobjDesc = inv_open(lobjId, mode);
@@ -128,7 +135,7 @@ lo_close(PG_FUNCTION_ARGS)
#endif
Assert(fscxt != NULL);
- currentContext = MemoryContextSwitchTo((MemoryContext) fscxt);
+ currentContext = MemoryContextSwitchTo(fscxt);
inv_close(cookies[fd]);
@@ -166,7 +173,7 @@ lo_read(int fd, char *buf, int len)
}
Assert(fscxt != NULL);
- currentContext = MemoryContextSwitchTo((MemoryContext) fscxt);
+ currentContext = MemoryContextSwitchTo(fscxt);
status = inv_read(cookies[fd], buf, len);
@@ -193,7 +200,7 @@ lo_write(int fd, char *buf, int len)
}
Assert(fscxt != NULL);
- currentContext = MemoryContextSwitchTo((MemoryContext) fscxt);
+ currentContext = MemoryContextSwitchTo(fscxt);
status = inv_write(cookies[fd], buf, len);
@@ -224,7 +231,7 @@ lo_lseek(PG_FUNCTION_ARGS)
}
Assert(fscxt != NULL);
- currentContext = MemoryContextSwitchTo((MemoryContext) fscxt);
+ currentContext = MemoryContextSwitchTo(fscxt);
status = inv_seek(cookies[fd], offset, whence);
@@ -242,9 +249,13 @@ lo_creat(PG_FUNCTION_ARGS)
Oid lobjId;
if (fscxt == NULL)
- fscxt = CreateGlobalMemory("Filesystem");
+ fscxt = AllocSetContextCreate(TopMemoryContext,
+ "Filesystem",
+ ALLOCSET_DEFAULT_MINSIZE,
+ ALLOCSET_DEFAULT_INITSIZE,
+ ALLOCSET_DEFAULT_MAXSIZE);
- currentContext = MemoryContextSwitchTo((MemoryContext) fscxt);
+ currentContext = MemoryContextSwitchTo(fscxt);
lobjDesc = inv_create(mode);
@@ -493,7 +504,7 @@ lo_commit(bool isCommit)
if (fscxt == NULL)
return; /* no LO operations in this xact */
- currentContext = MemoryContextSwitchTo((MemoryContext) fscxt);
+ currentContext = MemoryContextSwitchTo(fscxt);
/*
* Clean out still-open index scans (not necessary if aborting) and
@@ -512,7 +523,7 @@ lo_commit(bool isCommit)
MemoryContextSwitchTo(currentContext);
/* Release the LO memory context to prevent permanent memory leaks. */
- GlobalMemoryDestroy(fscxt);
+ MemoryContextDelete(fscxt);
fscxt = NULL;
}
diff --git a/src/backend/libpq/be-pqexec.c b/src/backend/libpq/be-pqexec.c
index 42d48281e08..c76889a7a72 100644
--- a/src/backend/libpq/be-pqexec.c
+++ b/src/backend/libpq/be-pqexec.c
@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/libpq/Attic/be-pqexec.c,v 1.32 2000/05/28 17:55:56 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/libpq/Attic/be-pqexec.c,v 1.33 2000/06/28 03:31:41 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -135,9 +135,11 @@ PQexec(char *query)
/* ----------------
* pg_exec_query_dest will put the query results in a portal which will
* end up on the top of the portal stack.
+ *
+ * XXX memory context manipulation needs thought here.
* ----------------
*/
- pg_exec_query_dest(query, Local, FALSE);
+ pg_exec_query_dest(query, Local, CurrentMemoryContext);
/* ----------------
* pop the portal off the portal stack and return the
diff --git a/src/backend/libpq/pqsignal.c b/src/backend/libpq/pqsignal.c
index 04ebd7dd57c..4648fe455f7 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.15 2000/06/11 11:39:50 petere Exp $
+ * $Header: /cvsroot/pgsql/src/backend/libpq/pqsignal.c,v 1.16 2000/06/28 03:31:41 tgl Exp $
*
* NOTES
* This shouldn't be in libpq, but the monitor and some other
@@ -44,6 +44,44 @@
#include "libpq/pqsignal.h"
+
+/*
+ * Initialize BlockSig and UnBlockSig.
+ *
+ * BlockSig is the set of signals to block when we are trying to block
+ * signals. This includes all signals we normally expect to get, but NOT
+ * signals that should never be turned off.
+ *
+ * UnBlockSig is the set of signals to block when we don't want to block
+ * signals (is this ever nonzero??)
+ */
+void
+pqinitmask(void)
+{
+#ifdef HAVE_SIGPROCMASK
+ sigemptyset(&UnBlockSig);
+ sigfillset(&BlockSig);
+ sigdelset(&BlockSig, SIGABRT);
+ sigdelset(&BlockSig, SIGILL);
+ sigdelset(&BlockSig, SIGSEGV);
+ sigdelset(&BlockSig, SIGBUS);
+ sigdelset(&BlockSig, SIGTRAP);
+ sigdelset(&BlockSig, SIGCONT);
+ sigdelset(&BlockSig, SIGSYS);
+#else
+ UnBlockSig = 0;
+ BlockSig = sigmask(SIGHUP) | sigmask(SIGQUIT) |
+ sigmask(SIGTERM) | sigmask(SIGALRM) |
+ sigmask(SIGINT) | sigmask(SIGUSR1) |
+ sigmask(SIGUSR2) | sigmask(SIGCHLD) |
+ sigmask(SIGWINCH) | sigmask(SIGFPE);
+#endif
+}
+
+
+/*
+ * Set up a signal handler
+ */
pqsigfunc
pqsignal(int signo, pqsigfunc func)
{