Commit 7414d619 authored by Marc G. Fournier's avatar Marc G. Fournier

From: Massimo Dal Zotto <dz@cs.unitn.it>

> tprintf.patch
>
>       tprintf.patch
>
>       adds functions and macros which implement a conditional trace package
>       with the ability to change flags and numeric options of running
>       backends at runtime.
>       Options/flags can be specified in the command line and/or read from
>       the file pg_options in the data directory.
parent 51e8e187
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtree.c,v 1.29 1998/08/19 02:01:16 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtree.c,v 1.30 1998/08/25 21:33:56 scrappy Exp $
* *
* NOTES * NOTES
* This file contains only the public interface routines. * This file contains only the public interface routines.
...@@ -35,8 +35,8 @@ ...@@ -35,8 +35,8 @@
#ifdef BTREE_BUILD_STATS #ifdef BTREE_BUILD_STATS
#include <tcop/tcopprot.h> #include <tcop/tcopprot.h>
extern int ShowExecutorStats; #include <utils/trace.h>
#define ShowExecutorStats pg_options[TRACE_EXECUTORSTATS]
#endif #endif
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Id: nbtsort.c,v 1.30 1998/06/15 19:27:59 momjian Exp $ * $Id: nbtsort.c,v 1.31 1998/08/25 21:33:57 scrappy Exp $
* *
* NOTES * NOTES
* *
...@@ -64,8 +64,8 @@ ...@@ -64,8 +64,8 @@
#ifdef BTREE_BUILD_STATS #ifdef BTREE_BUILD_STATS
#include "tcop/tcopprot.h" #include "tcop/tcopprot.h"
extern int ShowExecutorStats; #include <utils/trace.h>
#define ShowExecutorStats pg_options[TRACE_EXECUTORSTATS]
#endif #endif
static BTItem _bt_buildadd(Relation index, void *pstate, BTItem bti, int flags); static BTItem _bt_buildadd(Relation index, void *pstate, BTItem bti, int flags);
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.94 1998/08/25 21:04:36 scrappy Exp $ * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.95 1998/08/25 21:33:59 scrappy Exp $
* *
* NOTES * NOTES
* *
...@@ -92,6 +92,7 @@ ...@@ -92,6 +92,7 @@
#include "port-protos.h" /* For gethostname() */ #include "port-protos.h" /* For gethostname() */
#endif #endif
#include "storage/fd.h" #include "storage/fd.h"
#include "utils/trace.h"
#if !defined(MAXINT) #if !defined(MAXINT)
#define MAXINT INT_MAX #define MAXINT INT_MAX
...@@ -116,6 +117,8 @@ typedef struct bkend ...@@ -116,6 +117,8 @@ typedef struct bkend
long cancel_key; /* cancel key for cancels for this backend */ long cancel_key; /* cancel key for cancels for this backend */
} Backend; } Backend;
Port *MyBackendPort = NULL;
/* list of active backends. For garbage collection only now. */ /* list of active backends. For garbage collection only now. */
static Dllist *BackendList; static Dllist *BackendList;
...@@ -232,6 +235,7 @@ static int processCancelRequest(Port *port, PacketLen len, void *pkt); ...@@ -232,6 +235,7 @@ static int processCancelRequest(Port *port, PacketLen len, void *pkt);
static int initMasks(fd_set *rmask, fd_set *wmask); static int initMasks(fd_set *rmask, fd_set *wmask);
static long PostmasterRandom(void); static long PostmasterRandom(void);
static void RandomSalt(char *salt); static void RandomSalt(char *salt);
static void SignalChildren(SIGNAL_ARGS);
#ifdef CYR_RECODE #ifdef CYR_RECODE
void GetCharSetByHost(char *, int, char *); void GetCharSetByHost(char *, int, char *);
...@@ -314,16 +318,16 @@ PostmasterMain(int argc, char *argv[]) ...@@ -314,16 +318,16 @@ PostmasterMain(int argc, char *argv[])
* We need three params so we can display status. If we don't * We need three params so we can display status. If we don't
* get them from the user, let's make them ourselves. * get them from the user, let's make them ourselves.
*/ */
if (argc < 4) if (argc < 5)
{ {
int i; int i;
char *new_argv[5]; char *new_argv[6];
for (i=0; i < argc; i++) for (i=0; i < argc; i++)
new_argv[i] = argv[i]; new_argv[i] = argv[i];
for (; i < 4; i++) for (; i < 5; i++)
new_argv[i] = ""; new_argv[i] = "";
new_argv[4] = NULL; new_argv[5] = NULL;
if (!Execfile[0] && FindExec(Execfile, argv[0], "postmaster") < 0) if (!Execfile[0] && FindExec(Execfile, argv[0], "postmaster") < 0)
{ {
...@@ -363,6 +367,7 @@ PostmasterMain(int argc, char *argv[]) ...@@ -363,6 +367,7 @@ PostmasterMain(int argc, char *argv[])
hostName = hostbuf; hostName = hostbuf;
} }
MyProcPid = getpid();
DataDir = getenv("PGDATA"); /* default value */ DataDir = getenv("PGDATA"); /* default value */
opterr = 0; opterr = 0;
...@@ -424,6 +429,7 @@ PostmasterMain(int argc, char *argv[]) ...@@ -424,6 +429,7 @@ PostmasterMain(int argc, char *argv[])
} }
else else
DebugLvl = 1; DebugLvl = 1;
pg_options[TRACE_VERBOSE] = DebugLvl;
break; break;
case 'i': case 'i':
NetServer = true; NetServer = true;
...@@ -535,14 +541,17 @@ PostmasterMain(int argc, char *argv[]) ...@@ -535,14 +541,17 @@ PostmasterMain(int argc, char *argv[])
* Set up signal handlers for the postmaster process. * Set up signal handlers for the postmaster process.
*/ */
pqsignal(SIGINT, pmdie); pqsignal(SIGHUP, pmdie); /* send SIGHUP, don't die */
pqsignal(SIGCHLD, reaper); pqsignal(SIGINT, pmdie); /* die */
pqsignal(SIGTTIN, SIG_IGN); pqsignal(SIGQUIT, pmdie); /* send SIGTERM and die */
pqsignal(SIGTTOU, SIG_IGN); pqsignal(SIGTERM, pmdie); /* send SIGTERM,SIGKILL and die */
pqsignal(SIGHUP, pmdie); pqsignal(SIGPIPE, SIG_IGN); /* ignored */
pqsignal(SIGTERM, pmdie); pqsignal(SIGUSR1, pmdie); /* send SIGUSR1 and die */
pqsignal(SIGCONT, dumpstatus); pqsignal(SIGUSR2, pmdie); /* send SIGUSR2, don't die */
pqsignal(SIGPIPE, SIG_IGN); pqsignal(SIGCHLD, reaper); /* handle child termination */
pqsignal(SIGTTIN, SIG_IGN); /* ignored */
pqsignal(SIGTTOU, SIG_IGN); /* ignored */
pqsignal(SIGWINCH, dumpstatus); /* dump port status */
status = ServerLoop(); status = ServerLoop();
...@@ -980,6 +989,52 @@ reset_shared(short port) ...@@ -980,6 +989,52 @@ reset_shared(short port)
static void static void
pmdie(SIGNAL_ARGS) pmdie(SIGNAL_ARGS)
{ {
int i;
TPRINTF(TRACE_VERBOSE, "pmdie %d", postgres_signal_arg);
/*
* Kill self and/or children processes depending on signal number.
*/
switch (postgres_signal_arg) {
case SIGHUP:
/* Send SIGHUP to all children (update options flags) */
SignalChildren(SIGHUP);
/* Don't die */
return;
case SIGINT:
/* Die without killing children */
break;
case SIGQUIT:
/* Shutdown all children with SIGTERM */
SignalChildren(SIGTERM);
/* Don't die */
return;
case SIGTERM:
/* Shutdown all children with SIGTERM and SIGKILL, then die */
SignalChildren(SIGTERM);
for (i=0; i<10; i++) {
if (!DLGetHead(BackendList)) {
break;
}
sleep(1);
}
if (DLGetHead(BackendList)) {
SignalChildren(SIGKILL);
}
break;
case SIGUSR1:
/* Quick die all children with SIGUSR1 and die */
SignalChildren(SIGUSR1);
break;
case SIGUSR2:
/* Send SIGUSR2 to all children (AsyncNotifyHandler) */
SignalChildren(SIGUSR2);
/* Don't die */
return;
}
/* exit postmaster */
proc_exit(0); proc_exit(0);
} }
...@@ -1122,6 +1177,35 @@ CleanupProc(int pid, ...@@ -1122,6 +1177,35 @@ CleanupProc(int pid,
} }
} }
/*
* Send a signal to all chidren processes.
*/
static void
SignalChildren(int signal)
{
Dlelem *curr,
*next;
Backend *bp;
int mypid = getpid();
curr = DLGetHead(BackendList);
while (curr)
{
next = DLGetSucc(curr);
bp = (Backend *) DLE_VAL(curr);
if (bp->pid != mypid)
{
TPRINTF(TRACE_VERBOSE,
"SignalChildren: sending signal %d to process %d",
signal, bp->pid);
kill(bp->pid, signal);
}
curr = next;
}
}
/* /*
* BackendStartup -- start backend process * BackendStartup -- start backend process
* *
...@@ -1342,6 +1426,9 @@ DoBackend(Port *port) ...@@ -1342,6 +1426,9 @@ DoBackend(Port *port)
StreamClose(ServerSock_INET); StreamClose(ServerSock_INET);
StreamClose(ServerSock_UNIX); StreamClose(ServerSock_UNIX);
/* Save port for ps status */
MyProcPort = port;
/* /*
* Don't want backend to be able to see the postmaster random number * Don't want backend to be able to see the postmaster random number
* generator state. We have to clobber the static random_seed *and* * generator state. We have to clobber the static random_seed *and*
...@@ -1368,7 +1455,13 @@ DoBackend(Port *port) ...@@ -1368,7 +1455,13 @@ DoBackend(Port *port)
* a big win. * a big win.
*/ */
#ifndef linux
/*
* This doesn't work on linux and overwrites the only valid
* pointer to the argv buffer. See PS_INIT_STATUS macro.
*/
real_argv[0] = Execfile; real_argv[0] = Execfile;
#endif
/* Tell the backend it is being called from the postmaster */ /* Tell the backend it is being called from the postmaster */
av[ac++] = "-p"; av[ac++] = "-p";
...@@ -1386,8 +1479,6 @@ DoBackend(Port *port) ...@@ -1386,8 +1479,6 @@ DoBackend(Port *port)
sprintf(debugbuf, "-d%d", DebugLvl); sprintf(debugbuf, "-d%d", DebugLvl);
av[ac++] = debugbuf; av[ac++] = debugbuf;
} }
else
av[ac++] = "-Q";
/* Pass the requested debugging output file */ /* Pass the requested debugging output file */
if (port->tty[0]) if (port->tty[0])
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/ipc.c,v 1.30 1998/07/12 04:43:28 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/storage/ipc/ipc.c,v 1.31 1998/08/25 21:34:01 scrappy Exp $
* *
* NOTES * NOTES
* *
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#include <sys/shm.h> #include <sys/shm.h>
#include "utils/memutils.h" #include "utils/memutils.h"
#include "libpq/libpq.h" #include "libpq/libpq.h"
#include "utils/trace.h"
#if defined(solaris_sparc) #if defined(solaris_sparc)
#include <string.h> #include <string.h>
...@@ -113,17 +114,26 @@ proc_exit(int code) ...@@ -113,17 +114,26 @@ proc_exit(int code)
{ {
int i; int i;
TPRINTF(TRACE_VERBOSE, "proc_exit(%d) [#%d]", code, proc_exit_inprogress);
/*
* If proc_exit is called too many times something bad is
* happenig, so exit immediately.
*/
if (proc_exit_inprogress > 9) {
elog(ERROR, "infinite recursion in proc_exit");
goto exit;
}
/* ---------------- /* ----------------
* if proc_exit_inprocess is true, then it means that we * if proc_exit_inprocess is true, then it means that we
* are being invoked from within an on_exit() handler * are being invoked from within an on_exit() handler
* and so we return immediately to avoid recursion. * and so we return immediately to avoid recursion.
* ---------------- * ----------------
*/ */
if (proc_exit_inprogress) if (proc_exit_inprogress++)
return; return;
proc_exit_inprogress = 1;
/* do our shared memory exits first */ /* do our shared memory exits first */
shmem_exit(code); shmem_exit(code);
...@@ -134,6 +144,8 @@ proc_exit(int code) ...@@ -134,6 +144,8 @@ proc_exit(int code)
for (i = on_proc_exit_index - 1; i >= 0; --i) for (i = on_proc_exit_index - 1; i >= 0; --i)
(*on_proc_exit_list[i].function) (code, on_proc_exit_list[i].arg); (*on_proc_exit_list[i].function) (code, on_proc_exit_list[i].arg);
exit:
TPRINTF(TRACE_VERBOSE, "exit(%d)", code);
exit(code); exit(code);
} }
...@@ -150,17 +162,27 @@ shmem_exit(int code) ...@@ -150,17 +162,27 @@ shmem_exit(int code)
{ {
int i; int i;
TPRINTF(TRACE_VERBOSE, "shmem_exit(%d) [#%d]",
code, shmem_exit_inprogress);
/*
* If shmem_exit is called too many times something bad is
* happenig, so exit immediately.
*/
if (shmem_exit_inprogress > 9) {
elog(ERROR, "infinite recursion in shmem_exit");
exit(-1);
}
/* ---------------- /* ----------------
* if shmem_exit_inprocess is true, then it means that we * if shmem_exit_inprocess is true, then it means that we
* are being invoked from within an on_exit() handler * are being invoked from within an on_exit() handler
* and so we return immediately to avoid recursion. * and so we return immediately to avoid recursion.
* ---------------- * ----------------
*/ */
if (shmem_exit_inprogress) if (shmem_exit_inprogress++)
return; return;
shmem_exit_inprogress = 1;
/* ---------------- /* ----------------
* call all the callbacks registered before calling exit(). * call all the callbacks registered before calling exit().
* ---------------- * ----------------
...@@ -315,7 +337,7 @@ IpcSemaphoreCreate(IpcSemaphoreKey semKey, ...@@ -315,7 +337,7 @@ IpcSemaphoreCreate(IpcSemaphoreKey semKey,
{ {
*status = IpcSemIdNotExist; /* there doesn't exist a semaphore */ *status = IpcSemIdNotExist; /* there doesn't exist a semaphore */
#ifdef DEBUG_IPC #ifdef DEBUG_IPC
fprintf(stderr, "calling semget with %d, %d , %d\n", EPRINTF("calling semget with %d, %d , %d\n",
semKey, semKey,
semNum, semNum,
IPC_CREAT | permission); IPC_CREAT | permission);
...@@ -324,8 +346,9 @@ IpcSemaphoreCreate(IpcSemaphoreKey semKey, ...@@ -324,8 +346,9 @@ IpcSemaphoreCreate(IpcSemaphoreKey semKey,
if (semId < 0) if (semId < 0)
{ {
perror("semget"); EPRINTF("IpcSemaphoreCreate: semget failed (%s) "
IpcConfigTip(); "key=%d, num=%d, permission=%o",
strerror(errno), semKey, semNum, permission);
proc_exit(3); proc_exit(3);
} }
for (i = 0; i < semNum; i++) for (i = 0; i < semNum; i++)
...@@ -334,8 +357,8 @@ IpcSemaphoreCreate(IpcSemaphoreKey semKey, ...@@ -334,8 +357,8 @@ IpcSemaphoreCreate(IpcSemaphoreKey semKey,
errStatus = semctl(semId, 0, SETALL, semun); errStatus = semctl(semId, 0, SETALL, semun);
if (errStatus == -1) if (errStatus == -1)
{ {
perror("semctl"); EPRINTF("IpcSemaphoreCreate: semctl failed (%s) id=%d",
IpcConfigTip(); strerror(errno), semId);
} }
if (removeOnExit) if (removeOnExit)
...@@ -349,7 +372,7 @@ IpcSemaphoreCreate(IpcSemaphoreKey semKey, ...@@ -349,7 +372,7 @@ IpcSemaphoreCreate(IpcSemaphoreKey semKey,
} }
#ifdef DEBUG_IPC #ifdef DEBUG_IPC
fprintf(stderr, "\nIpcSemaphoreCreate, status %d, returns %d\n", EPRINTF("\nIpcSemaphoreCreate, status %d, returns %d\n",
*status, *status,
semId); semId);
fflush(stdout); fflush(stdout);
...@@ -379,8 +402,8 @@ IpcSemaphoreSet(int semId, int semno, int value) ...@@ -379,8 +402,8 @@ IpcSemaphoreSet(int semId, int semno, int value)
if (errStatus == -1) if (errStatus == -1)
{ {
perror("semctl"); EPRINTF("IpcSemaphoreSet: semctl failed (%s) id=%d",
IpcConfigTip(); strerror(errno), semId);
} }
} }
...@@ -441,8 +464,8 @@ IpcSemaphoreLock(IpcSemaphoreId semId, int sem, int lock) ...@@ -441,8 +464,8 @@ IpcSemaphoreLock(IpcSemaphoreId semId, int sem, int lock)
if (errStatus == -1) if (errStatus == -1)
{ {
perror("semop"); EPRINTF("IpcSemaphoreLock: semop failed (%s) id=%d",
IpcConfigTip(); strerror(errno), semId);
proc_exit(255); proc_exit(255);
} }
} }
...@@ -486,8 +509,8 @@ IpcSemaphoreUnlock(IpcSemaphoreId semId, int sem, int lock) ...@@ -486,8 +509,8 @@ IpcSemaphoreUnlock(IpcSemaphoreId semId, int sem, int lock)
if (errStatus == -1) if (errStatus == -1)
{ {
perror("semop"); EPRINTF("IpcSemaphoreUnlock: semop failed (%s) id=%d",
IpcConfigTip(); strerror(errno), semId);
proc_exit(255); proc_exit(255);
} }
} }
...@@ -534,10 +557,9 @@ IpcMemoryCreate(IpcMemoryKey memKey, uint32 size, int permission) ...@@ -534,10 +557,9 @@ IpcMemoryCreate(IpcMemoryKey memKey, uint32 size, int permission)
if (shmid < 0) if (shmid < 0)
{ {
fprintf(stderr, "IpcMemoryCreate: memKey=%d , size=%d , permission=%d", EPRINTF("IpcMemoryCreate: shmget failed (%s) "
memKey, size, permission); "key=%d, size=%d, permission=%o",
perror("IpcMemoryCreate: shmget(..., create, ...) failed"); strerror(errno), memKey, size, permission);
IpcConfigTip();
return (IpcMemCreationFailed); return (IpcMemCreationFailed);
} }
...@@ -560,10 +582,9 @@ IpcMemoryIdGet(IpcMemoryKey memKey, uint32 size) ...@@ -560,10 +582,9 @@ IpcMemoryIdGet(IpcMemoryKey memKey, uint32 size)
if (shmid < 0) if (shmid < 0)
{ {
fprintf(stderr, "IpcMemoryIdGet: memKey=%d , size=%d , permission=%d", EPRINTF("IpcMemoryIdGet: shmget failed (%s) "
memKey, size, 0); "key=%d, size=%d, permission=%o",
perror("IpcMemoryIdGet: shmget() failed"); strerror(errno), memKey, size, 0);
IpcConfigTip();
return (IpcMemIdGetFailed); return (IpcMemIdGetFailed);
} }
...@@ -602,8 +623,8 @@ IpcMemoryAttach(IpcMemoryId memId) ...@@ -602,8 +623,8 @@ IpcMemoryAttach(IpcMemoryId memId)
/* if ( *memAddress == -1) { XXX ??? */ /* if ( *memAddress == -1) { XXX ??? */
if (memAddress == (char *) -1) if (memAddress == (char *) -1)
{ {
perror("IpcMemoryAttach: shmat() failed"); EPRINTF("IpcMemoryAttach: shmat failed (%s) id=%d",
IpcConfigTip(); strerror(errno), memId);
return (IpcMemAttachFailed); return (IpcMemAttachFailed);
} }
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/Attic/spin.c,v 1.14 1998/06/27 15:47:45 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/storage/ipc/Attic/spin.c,v 1.15 1998/08/25 21:34:03 scrappy Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "storage/shmem.h" #include "storage/shmem.h"
#include "storage/spin.h" #include "storage/spin.h"
#include "storage/proc.h" #include "storage/proc.h"
#include "utils/trace.h"
#ifndef HAS_TEST_AND_SET #ifndef HAS_TEST_AND_SET
#include <sys/sem.h> #include <sys/sem.h>
...@@ -81,10 +82,12 @@ InitSpinLocks(int init, IPCKey key) ...@@ -81,10 +82,12 @@ InitSpinLocks(int init, IPCKey key)
} }
#ifdef LOCKDEBUG #ifdef LOCKDEBUG
#define PRINT_LOCK(LOCK) printf("(locklock = %d, flag = %d, nshlocks = %d, \ #define PRINT_LOCK(LOCK) \
shlock = %d, exlock =%d)\n", LOCK->locklock, \ TPRINTF(TRACE_SPINLOCKS, \
LOCK->flag, LOCK->nshlocks, LOCK->shlock, \ "(locklock = %d, flag = %d, nshlocks = %d, shlock = %d, " \
LOCK->exlock) "exlock =%d)\n", LOCK->locklock, \
LOCK->flag, LOCK->nshlocks, LOCK->shlock, \
LOCK->exlock)
#endif #endif
/* from ipc.c */ /* from ipc.c */
...@@ -98,8 +101,7 @@ SpinAcquire(SPINLOCK lockid) ...@@ -98,8 +101,7 @@ SpinAcquire(SPINLOCK lockid)
/* This used to be in ipc.c, but move here to reduce function calls */ /* This used to be in ipc.c, but move here to reduce function calls */
slckP = &(SLockArray[lockid]); slckP = &(SLockArray[lockid]);
#ifdef LOCKDEBUG #ifdef LOCKDEBUG
printf("SpinAcquire(%d)\n", lockid); TPRINTF(TRACE_SPINLOCKS, "SpinAcquire: %d", lockid);
printf("IN: ");
PRINT_LOCK(slckP); PRINT_LOCK(slckP);
#endif #endif
ex_try_again: ex_try_again:
...@@ -112,7 +114,7 @@ ex_try_again: ...@@ -112,7 +114,7 @@ ex_try_again:
S_LOCK(&(slckP->shlock)); S_LOCK(&(slckP->shlock));
S_UNLOCK(&(slckP->locklock)); S_UNLOCK(&(slckP->locklock));
#ifdef LOCKDEBUG #ifdef LOCKDEBUG
printf("OUT: "); TPRINTF(TRACE_SPINLOCKS, "OUT: ");
PRINT_LOCK(slckP); PRINT_LOCK(slckP);
#endif #endif
break; break;
...@@ -124,6 +126,9 @@ ex_try_again: ...@@ -124,6 +126,9 @@ ex_try_again:
goto ex_try_again; goto ex_try_again;
} }
PROC_INCR_SLOCK(lockid); PROC_INCR_SLOCK(lockid);
#ifdef LOCKDEBUG
TPRINTF(TRACE_SPINLOCKS, "SpinAcquire: got %d", lockid);
#endif
} }
void void
...@@ -131,13 +136,23 @@ SpinRelease(SPINLOCK lockid) ...@@ -131,13 +136,23 @@ SpinRelease(SPINLOCK lockid)
{ {
SLock *slckP; SLock *slckP;
PROC_DECR_SLOCK(lockid);
/* This used to be in ipc.c, but move here to reduce function calls */ /* This used to be in ipc.c, but move here to reduce function calls */
slckP = &(SLockArray[lockid]); slckP = &(SLockArray[lockid]);
#ifdef USE_ASSERT_CHECKING
/*
* Check that we are actually holding the lock we are releasing.
* This can be done only after MyProc has been initialized.
*/
if (MyProc)
Assert(MyProc->sLocks[lockid] > 0);
Assert(slckP->flag != NOLOCK);
#endif
PROC_DECR_SLOCK(lockid);
#ifdef LOCKDEBUG #ifdef LOCKDEBUG
printf("SpinRelease(%d)\n", lockid); TPRINTF("SpinRelease: %d\n", lockid);
printf("IN: ");
PRINT_LOCK(slckP); PRINT_LOCK(slckP);
#endif #endif
S_LOCK(&(slckP->locklock)); S_LOCK(&(slckP->locklock));
...@@ -160,7 +175,7 @@ SpinRelease(SPINLOCK lockid) ...@@ -160,7 +175,7 @@ SpinRelease(SPINLOCK lockid)
S_UNLOCK(&(slckP->exlock)); S_UNLOCK(&(slckP->exlock));
S_UNLOCK(&(slckP->locklock)); S_UNLOCK(&(slckP->locklock));
#ifdef LOCKDEBUG #ifdef LOCKDEBUG
printf("OUT: "); TPRINTF(TRACE_SPINLOCKS, "SpinRelease: released %d", lockid);
PRINT_LOCK(slckP); PRINT_LOCK(slckP);
#endif #endif
} }
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.85 1998/08/25 21:04:38 scrappy Exp $ * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.86 1998/08/25 21:34:04 scrappy Exp $
* *
* NOTES * NOTES
* this is the "main" module of the postgres backend and * this is the "main" module of the postgres backend and
...@@ -36,7 +36,9 @@ ...@@ -36,7 +36,9 @@
#if HAVE_SYS_SELECT_H #if HAVE_SYS_SELECT_H
#include <sys/select.h> #include <sys/select.h>
#endif /* aix */ #endif /* aix */
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include "postgres.h" #include "postgres.h"
#include "miscadmin.h" #include "miscadmin.h"
...@@ -66,6 +68,7 @@ ...@@ -66,6 +68,7 @@
#include "tcop/utility.h" #include "tcop/utility.h"
#include "utils/mcxt.h" #include "utils/mcxt.h"
#include "utils/rel.h" #include "utils/rel.h"
#include "utils/ps_status.h"
#if FALSE #if FALSE
#include "nodes/relation.h" #include "nodes/relation.h"
...@@ -83,27 +86,43 @@ ...@@ -83,27 +86,43 @@
#include "nodes/memnodes.h" #include "nodes/memnodes.h"
#endif #endif
#include "utils/trace.h"
#ifdef MULTIBYTE #ifdef MULTIBYTE
#include "mb/pg_wchar.h" #include "mb/pg_wchar.h"
#endif #endif
/*
* Trace flags, see backend/utils/misc/trace.c
*/
#define Verbose pg_options[TRACE_VERBOSE]
#define DebugPrintQuery pg_options[TRACE_QUERY]
#define DebugPrintPlan pg_options[TRACE_PLAN]
#define DebugPrintParse pg_options[TRACE_PARSE]
#define ShowParserStats pg_options[TRACE_PARSERSTATS]
#define ShowPlannerStats pg_options[TRACE_PLANNERSTATS]
#define ShowExecutorStats pg_options[TRACE_EXECUTORSTATS]
#define DebugPrintRewrittenParsetree \
pg_options[TRACE_REWRITTEN]
#ifdef LOCK_MGR_DEBUG
#define LockDebug pg_options[TRACE_LOCKS]
#endif
#define DeadlockCheckTimer pg_options[OPT_DEADLOCKTIMEOUT]
#define HostnameLookup pg_options[OPT_HOSTLOOKUP]
#define ShowPortNumber pg_options[OPT_SHOWPORTNUMBER]
/* ---------------- /* ----------------
* global variables * global variables
* ---------------- * ----------------
*/ */
static bool DebugPrintQuery = false;
static bool DebugPrintPlan = false;
static bool DebugPrintParse = false;
static bool DebugPrintRewrittenParsetree = false;
/*static bool EnableRewrite = true; , never changes why have it*/ /*static bool EnableRewrite = true; , never changes why have it*/
CommandDest whereToSendOutput; CommandDest whereToSendOutput;
const char **ps_status; /* this is our 'ps' status, argv[3] */
#ifdef LOCK_MGR_DEBUG /* Define status buffer needed by PS_SET_STATUS */
extern int lockDebug; PS_DEFINE_BUFFER;
#endif
extern int lockingOff; extern int lockingOff;
extern int NBuffers; extern int NBuffers;
...@@ -129,9 +148,6 @@ extern int NBuffers; ...@@ -129,9 +148,6 @@ extern int NBuffers;
static int EchoQuery = 0; /* default don't echo */ static int EchoQuery = 0; /* default don't echo */
time_t tim; time_t tim;
char pg_pathname[256]; char pg_pathname[256];
static int ShowParserStats;
static int ShowPlannerStats;
int ShowExecutorStats;
FILE *StatFp; FILE *StatFp;
/* ---------------- /* ----------------
...@@ -260,7 +276,7 @@ InteractiveBackend(char *inBuf) ...@@ -260,7 +276,7 @@ InteractiveBackend(char *inBuf)
if (end) if (end)
{ {
if (!Quiet) if (Verbose)
puts("EOF"); puts("EOF");
IsEmptyQuery = true; IsEmptyQuery = true;
proc_exit(0); proc_exit(0);
...@@ -278,7 +294,7 @@ InteractiveBackend(char *inBuf) ...@@ -278,7 +294,7 @@ InteractiveBackend(char *inBuf)
* ---------------- * ----------------
*/ */
if (EchoQuery) if (EchoQuery)
printf("query is: %s\n", inBuf); printf("query: %s\n", inBuf);
return ('Q'); return ('Q');
} }
...@@ -521,9 +537,9 @@ pg_parse_and_plan(char *query_string, /* string to execute */ ...@@ -521,9 +537,9 @@ pg_parse_and_plan(char *query_string, /* string to execute */
} }
} }
if (DebugPrintRewrittenParsetree == true) if (DebugPrintRewrittenParsetree)
{ {
printf("\n---- \tafter rewriting:\n"); TPRINTF(TRACE_REWRITTEN, "after rewriting:");
for (i = 0; i < querytree_list->len; i++) for (i = 0; i < querytree_list->len; i++)
{ {
...@@ -584,11 +600,10 @@ pg_parse_and_plan(char *query_string, /* string to execute */ ...@@ -584,11 +600,10 @@ pg_parse_and_plan(char *query_string, /* string to execute */
* also for queries in functions. DZ - 27-8-1996 * also for queries in functions. DZ - 27-8-1996
* ---------------- * ----------------
*/ */
if (DebugPrintPlan == true) if (DebugPrintPlan)
{ {
printf("\n---- \tplan is :\n"); TPRINTF(TRACE_PLAN, "plan:");
nodeDisplay(plan); nodeDisplay(plan);
printf("\n");
} }
#endif #endif
} }
...@@ -696,11 +711,11 @@ pg_exec_query_dest(char *query_string, /* string to execute */ ...@@ -696,11 +711,11 @@ pg_exec_query_dest(char *query_string, /* string to execute */
* because that is done in ProcessUtility. * because that is done in ProcessUtility.
* ---------------- * ----------------
*/ */
if (!Quiet) if (DebugPrintQuery) {
{ TPRINTF(TRACE_QUERY, "ProcessUtility: %s", query_string);
time(&tim); } else if (Verbose) {
printf("\tProcessUtility() at %s\n", ctime(&tim)); TPRINTF(TRACE_VERBOSE, "ProcessUtility");
} }
ProcessUtility(querytree->utilityStmt, dest); ProcessUtility(querytree->utilityStmt, dest);
...@@ -726,11 +741,10 @@ pg_exec_query_dest(char *query_string, /* string to execute */ ...@@ -726,11 +741,10 @@ pg_exec_query_dest(char *query_string, /* string to execute */
* print plan if debugging * print plan if debugging
* ---------------- * ----------------
*/ */
if (DebugPrintPlan == true) if (DebugPrintPlan)
{ {
printf("\n---- plan is :\n"); TPRINTF(TRACE_PLAN, "plan:");
nodeDisplay(plan); nodeDisplay(plan);
printf("\n");
} }
#endif #endif
...@@ -743,10 +757,9 @@ pg_exec_query_dest(char *query_string, /* string to execute */ ...@@ -743,10 +757,9 @@ pg_exec_query_dest(char *query_string, /* string to execute */
for (j = 0; j < _exec_repeat_; j++) for (j = 0; j < _exec_repeat_; j++)
{ {
if (!Quiet) if (Verbose)
{ {
time(&tim); TPRINTF(TRACE_VERBOSE, "ProcessQuery");
printf("\tProcessQuery() at %s\n", ctime(&tim));
} }
ProcessQuery(querytree, plan, dest); ProcessQuery(querytree, plan, dest);
} }
...@@ -775,7 +788,7 @@ pg_exec_query_dest(char *query_string, /* string to execute */ ...@@ -775,7 +788,7 @@ pg_exec_query_dest(char *query_string, /* string to execute */
/* -------------------------------- /* --------------------------------
* signal handler routines used in PostgresMain() * signal handler routines used in PostgresMain()
* *
* handle_warn() is used to catch kill(getpid(), SIGHUP) which * handle_warn() is used to catch kill(getpid(),SIGQUIT) which
* occurs when elog(ERROR) is called. * occurs when elog(ERROR) is called.
* *
* quickdie() occurs when signalled by the postmaster. * quickdie() occurs when signalled by the postmaster.
...@@ -887,17 +900,20 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[]) ...@@ -887,17 +900,20 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
flagEu = false; flagEu = false;
int flag; int flag;
char *DBName = NULL; char *DBName = NULL;
int errs = 0; int errs = 0;
char firstchar; char firstchar;
char parser_input[MAX_PARSE_BUFFER]; char parser_input[MAX_PARSE_BUFFER];
char *userName; char *userName;
char *remote_info;
char *remote_host;
unsigned short remote_port = 0;
char *DBDate = NULL; char *DBDate = NULL;
extern int optind; extern int optind;
extern char *optarg; extern char *optarg;
extern short DebugLvl; extern short DebugLvl;
/* ---------------- /* ----------------
* parse command line arguments * parse command line arguments
...@@ -909,8 +925,9 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[]) ...@@ -909,8 +925,9 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
*/ */
ShowStats = 0; ShowStats = 0;
ShowParserStats = ShowPlannerStats = ShowExecutorStats = 0; ShowParserStats = ShowPlannerStats = ShowExecutorStats = 0;
DeadlockCheckTimer = DEADLOCK_CHECK_TIMER;
#ifdef LOCK_MGR_DEBUG #ifdef LOCK_MGR_DEBUG
lockDebug = 0; LockDebug = 0;
#endif #endif
/* /*
...@@ -944,6 +961,11 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[]) ...@@ -944,6 +961,11 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
else if (strcasecmp(DBDate, "EURO") == 0) else if (strcasecmp(DBDate, "EURO") == 0)
EuroDates = TRUE; EuroDates = TRUE;
} }
/*
* Read default pg_options from file $DATADIR/pg_options.
*/
read_pg_options(0);
optind = 1; /* reset after postmaster usage */ optind = 1; /* reset after postmaster usage */
...@@ -994,10 +1016,20 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[]) ...@@ -994,10 +1016,20 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
case 'd': /* debug level */ case 'd': /* debug level */
flagQ = false; flagQ = false;
DebugLvl = (short) atoi(optarg); DebugLvl = (short) atoi(optarg);
if (DebugLvl > 1) if (DebugLvl >= 1)
DebugPrintQuery = true; {
if (DebugLvl > 2) Verbose = DebugLvl;
}
if (DebugLvl >= 2)
{
DebugPrintQuery = true;
}
if (DebugLvl >= 3)
{ {
DebugPrintQuery = DebugLvl;
}
if (DebugLvl >= 4)
{
DebugPrintParse = true; DebugPrintParse = true;
DebugPrintPlan = true; DebugPrintPlan = true;
DebugPrintRewrittenParsetree = true; DebugPrintRewrittenParsetree = true;
...@@ -1061,7 +1093,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[]) ...@@ -1061,7 +1093,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
case 'K': case 'K':
#ifdef LOCK_MGR_DEBUG #ifdef LOCK_MGR_DEBUG
lockDebug = atoi(optarg); LockDebug = atoi(optarg);
#else #else
fprintf(stderr, "Lock debug not compiled in\n"); fprintf(stderr, "Lock debug not compiled in\n");
#endif #endif
...@@ -1122,6 +1154,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[]) ...@@ -1122,6 +1154,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
* ---------------- * ----------------
*/ */
flagQ = true; flagQ = true;
Verbose = 0;
break; break;
case 'S': case 'S':
...@@ -1147,6 +1180,10 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[]) ...@@ -1147,6 +1180,10 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
StatFp = stderr; StatFp = stderr;
break; break;
case 'T':
parse_options(optarg);
break;
case 't': case 't':
/* ---------------- /* ----------------
* tell postgres to report usage statistics (timings) for * tell postgres to report usage statistics (timings) for
...@@ -1278,47 +1315,79 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[]) ...@@ -1278,47 +1315,79 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
} }
Noversion = flagC; Noversion = flagC;
Quiet = flagQ;
EchoQuery = flagE; EchoQuery = flagE;
EuroDates = flagEu; EuroDates = flagEu;
/*
* Find remote host name or address.
*/
if (IsUnderPostmaster) {
switch (MyProcPort->raddr.sa.sa_family) {
struct hostent *host_ent;
case AF_INET:
remote_info = remote_host = malloc(48);
remote_port = ntohs(MyProcPort->raddr.in.sin_port);
strcpy(remote_host, inet_ntoa(MyProcPort->raddr.in.sin_addr));
if (HostnameLookup) {
host_ent = \
gethostbyaddr((char *)&MyProcPort->raddr.in.sin_addr,
sizeof(MyProcPort->raddr.in.sin_addr),
AF_INET);
if (host_ent) {
strncpy(remote_host, host_ent->h_name, 48);
*(remote_host+47) = '\0';
}
}
if (ShowPortNumber) {
remote_info = malloc(strlen(remote_host)+6);
sprintf(remote_info, "%s:%d", remote_host, remote_port);
}
break;
case AF_UNIX:
remote_info = remote_host = "localhost";
break;
default:
remote_info = remote_host = "unknown";
break;
}
}
/* ---------------- /* ----------------
* print flags * set process params for ps
* ---------------- * ----------------
*/ */
if (!Quiet) if (IsUnderPostmaster) {
{ PS_INIT_STATUS(real_argc, real_argv, argv[0],
puts("\t---debug info---"); remote_info, userName, DBName);
printf("\tQuiet = %c\n", Quiet ? 't' : 'f'); PS_SET_STATUS("idle");
printf("\tNoversion = %c\n", Noversion ? 't' : 'f');
printf("\ttimings = %c\n", ShowStats ? 't' : 'f');
printf("\tdates = %s\n", EuroDates ? "European" : "Normal");
printf("\tbufsize = %d\n", NBuffers);
printf("\tsortmem = %d\n", SortMem);
printf("\tquery echo = %c\n", EchoQuery ? 't' : 'f');
printf("\tDatabaseName = [%s]\n", DBName);
puts("\t----------------\n");
} }
/* ---------------- /* ----------------
* set process params for ps * print flags
* ---------------- * ----------------
*/ */
if (IsUnderPostmaster) if (Verbose)
{ {
int i; if (Verbose == 1) {
TPRINTF(TRACE_VERBOSE, "started: host=%s user=%s database=%s",
Assert(real_argc >= 4); remote_host, userName, DBName);
real_argv[1] = userName; } else {
real_argv[2] = DBName; TPRINTF(TRACE_VERBOSE, "debug info:");
ps_status = (const char **)&real_argv[3]; TPRINTF(TRACE_VERBOSE, "\tUser = %s", userName);
*ps_status = "idle"; TPRINTF(TRACE_VERBOSE, "\tRemoteHost = %s", remote_host);
for (i = 4; i < real_argc; i++) TPRINTF(TRACE_VERBOSE, "\tRemotePort = %d", remote_port);
real_argv[i] = ""; /* blank them */ TPRINTF(TRACE_VERBOSE, "\tDatabaseName = %s", DBName);
TPRINTF(TRACE_VERBOSE, "\tVerbose = %d", Verbose);
TPRINTF(TRACE_VERBOSE, "\tNoversion = %c", Noversion ? 't' : 'f');
TPRINTF(TRACE_VERBOSE, "\ttimings = %c", ShowStats ? 't' : 'f');
TPRINTF(TRACE_VERBOSE, "\tdates = %s",
EuroDates ? "European" : "Normal");
TPRINTF(TRACE_VERBOSE, "\tbufsize = %d", NBuffers);
TPRINTF(TRACE_VERBOSE, "\tsortmem = %d", SortMem);
TPRINTF(TRACE_VERBOSE, "\tquery echo = %c", EchoQuery ? 't' : 'f');
}
} }
/* we just put a dummy here so we don't have to test everywhere */
else ps_status = malloc(sizeof(char *));
/* ---------------- /* ----------------
* initialize portal file descriptors * initialize portal file descriptors
...@@ -1341,19 +1410,19 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[]) ...@@ -1341,19 +1410,19 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
SetProcessingMode(InitProcessing); SetProcessingMode(InitProcessing);
/* initialize */ /* initialize */
if (!Quiet) if (Verbose)
puts("\tInitPostgres().."); TPRINTF(TRACE_VERBOSE, "InitPostgres");
InitPostgres(DBName); InitPostgres(DBName);
#ifdef MULTIBYTE #ifdef MULTIBYTE
/* set default client encoding */ /* set default client encoding */
if (!Quiet) if (Verbose)
{ {
puts("\treset_client_encoding().."); puts("\treset_client_encoding()..");
} }
reset_client_encoding(); reset_client_encoding();
if (!Quiet) if (Verbose)
{ {
puts("\treset_client_encoding() done."); puts("\treset_client_encoding() done.");
} }
...@@ -1366,7 +1435,15 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[]) ...@@ -1366,7 +1435,15 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
* ---------------- * ----------------
*/ */
pqsignal(SIGINT, QueryCancelHandler); pqsignal(SIGHUP, read_pg_options); /* upate pg_options from file */
pqsignal(SIGINT, QueryCancelHandler); /* cancel current query */
pqsignal(SIGQUIT, handle_warn); /* handle error */
pqsignal(SIGTERM, die);
pqsignal(SIGPIPE, die);
pqsignal(SIGUSR1, quickdie);
pqsignal(SIGUSR2, Async_NotifyHandler); /* flush also sinval cache */
pqsignal(SIGCHLD, SIG_IGN); /* ignored, sent by LockOwners */
pqsignal(SIGFPE, FloatExceptionHandler);
if (whereToSendOutput == Remote && if (whereToSendOutput == Remote &&
PG_PROTOCOL_MAJOR(FrontendProtocol) >= 2) PG_PROTOCOL_MAJOR(FrontendProtocol) >= 2)
...@@ -1384,21 +1461,19 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[]) ...@@ -1384,21 +1461,19 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
* so that the slaves signal the master to abort the transaction * so that the slaves signal the master to abort the transaction
* rather than calling AbortCurrentTransaction() themselves. * rather than calling AbortCurrentTransaction() themselves.
* *
* Note: elog(ERROR) causes a kill(getpid(), SIGHUP) to occur sending * Note: elog(ERROR) causes a kill(getpid(),SIGQUIT) to occur
* us back here. * sending us back here.
* ---------------- * ----------------
*/ */
pqsignal(SIGHUP, handle_warn);
if (sigsetjmp(Warn_restart, 1) != 0) if (sigsetjmp(Warn_restart, 1) != 0)
{ {
InError = true; InError = true;
time(&tim); time(&tim);
if (!Quiet) if (Verbose)
printf("\tAbortCurrentTransaction() at %s\n", ctime(&tim)); TPRINTF(TRACE_VERBOSE, "AbortCurrentTransaction");
MemSet(parser_input, 0, MAX_PARSE_BUFFER); MemSet(parser_input, 0, MAX_PARSE_BUFFER);
...@@ -1415,7 +1490,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[]) ...@@ -1415,7 +1490,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
if (!IsUnderPostmaster) if (!IsUnderPostmaster)
{ {
puts("\nPOSTGRES backend interactive interface"); puts("\nPOSTGRES backend interactive interface");
puts("$Revision: 1.85 $ $Date: 1998/08/25 21:04:38 $"); puts("$Revision: 1.86 $ $Date: 1998/08/25 21:34:04 $");
} }
/* ---------------- /* ----------------
...@@ -1457,15 +1532,14 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[]) ...@@ -1457,15 +1532,14 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
IsEmptyQuery = false; IsEmptyQuery = false;
/* start an xact for this function invocation */ /* start an xact for this function invocation */
if (!Quiet) if (Verbose)
{ {
time(&tim); TPRINTF(TRACE_VERBOSE, "StartTransactionCommand");
printf("\tStartTransactionCommand() at %s\n", ctime(&tim));
} }
StartTransactionCommand(); StartTransactionCommand();
HandleFunctionRequest(); HandleFunctionRequest();
*ps_status = "idle"; PS_SET_STATUS("idle");
break; break;
/* ---------------- /* ----------------
...@@ -1495,16 +1569,15 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[]) ...@@ -1495,16 +1569,15 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
ResetUsage(); ResetUsage();
/* start an xact for this query */ /* start an xact for this query */
if (!Quiet) if (Verbose)
{ {
time(&tim); TPRINTF(TRACE_VERBOSE, "StartTransactionCommand");
printf("\tStartTransactionCommand() at %s\n", ctime(&tim));
} }
StartTransactionCommand(); StartTransactionCommand();
pg_exec_query(parser_input); pg_exec_query(parser_input);
*ps_status = "idle"; PS_SET_STATUS("idle");
if (ShowStats) if (ShowStats)
ShowUsage(); ShowUsage();
...@@ -1533,12 +1606,13 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[]) ...@@ -1533,12 +1606,13 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
*/ */
if (!IsEmptyQuery) if (!IsEmptyQuery)
{ {
if (!Quiet) if (Verbose)
{ {
time(&tim); TPRINTF(TRACE_VERBOSE, "CommitTransactionCommand");
printf("\tCommitTransactionCommand() at %s\n", ctime(&tim));
} }
PS_SET_STATUS("commit");
CommitTransactionCommand(); CommitTransactionCommand();
PS_SET_STATUS("idle");
} }
else else
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/error/assert.c,v 1.9 1998/06/18 16:35:38 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/error/assert.c,v 1.10 1998/08/25 21:34:06 scrappy Exp $
* *
* NOTE * NOTE
* This should eventually work with elog(), dlog(), etc. * This should eventually work with elog(), dlog(), etc.
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "utils/module.h" #include "utils/module.h"
#include "utils/exc.h" #include "utils/exc.h"
#include "utils/trace.h"
int int
ExceptionalCondition(char *conditionName, ExceptionalCondition(char *conditionName,
...@@ -39,7 +40,7 @@ ExceptionalCondition(char *conditionName, ...@@ -39,7 +40,7 @@ ExceptionalCondition(char *conditionName,
|| !PointerIsValid(fileName) || !PointerIsValid(fileName)
|| !PointerIsValid(exceptionP)) || !PointerIsValid(exceptionP))
{ {
fprintf(stderr, "ExceptionalCondition: bad arguments\n"); EPRINTF("TRAP: ExceptionalCondition: bad arguments\n");
ExcAbort(exceptionP, ExcAbort(exceptionP,
(ExcDetail) detail, (ExcDetail) detail,
...@@ -48,9 +49,9 @@ ExceptionalCondition(char *conditionName, ...@@ -48,9 +49,9 @@ ExceptionalCondition(char *conditionName,
} }
else else
{ {
fprintf(stderr, EPRINTF("TRAP: %s(\"%s:%s\", File: \"%s\", Line: %d)\n",
"%s(\"%s:%s\", File: \"%s\", Line: %d)\n", exceptionP->message, conditionName,
exceptionP->message, conditionName, detail == NULL ? "" : detail, (detail == NULL ? "" : detail),
fileName, lineNumber); fileName, lineNumber);
} }
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.31 1998/07/07 22:00:31 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.32 1998/08/25 21:34:08 scrappy Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -24,10 +24,29 @@ ...@@ -24,10 +24,29 @@
#include <unistd.h> #include <unistd.h>
#include <signal.h> #include <signal.h>
#ifdef USE_SYSLOG
#include <syslog.h>
#endif
#include "postgres.h" #include "postgres.h"
#include "miscadmin.h" #include "miscadmin.h"
#include "libpq/libpq.h" #include "libpq/libpq.h"
#include "storage/proc.h" #include "storage/proc.h"
#include "utils/trace.h"
#ifdef USE_SYSLOG
/*
* Global option to control the use of syslog(3) for logging:
*
* 0 stdout/stderr only
* 1 stdout/stderr + syslog
* 2 syslog only
*/
#define UseSyslog pg_options[OPT_SYSLOG]
#define PG_LOG_FACILITY LOG_LOCAL0
#else
#define UseSyslog 0
#endif
static int Debugfile = -1; static int Debugfile = -1;
static int Err_file = -1; static int Err_file = -1;
...@@ -52,12 +71,12 @@ elog(int lev, const char *fmt,...) ...@@ -52,12 +71,12 @@ elog(int lev, const char *fmt,...)
#ifndef PG_STANDALONE #ifndef PG_STANDALONE
extern FILE *Pfout; extern FILE *Pfout;
#endif
#endif /* !PG_STANDALONE */ #ifdef USE_SYSLOG
#ifdef ELOG_TIMESTAMPS int log_level;
time_t tim;
#endif #endif
int len; int len;
int i = 0; int i = 0;
...@@ -72,7 +91,7 @@ elog(int lev, const char *fmt,...) ...@@ -72,7 +91,7 @@ elog(int lev, const char *fmt,...)
i = 0; i = 0;
if (i > 30) if (i > 30)
i = i % 30; i = i % 30;
cp = "DEBUG: "; cp = "DEBUG: ";
break; break;
case DEBUG: case DEBUG:
i = ElogDebugIndentLevel; i = ElogDebugIndentLevel;
...@@ -80,27 +99,25 @@ elog(int lev, const char *fmt,...) ...@@ -80,27 +99,25 @@ elog(int lev, const char *fmt,...)
i = 0; i = 0;
if (i > 30) if (i > 30)
i = i % 30; i = i % 30;
cp = "DEBUG: "; cp = "DEBUG: ";
break; break;
case NOTICE: case NOTICE:
cp = "NOTICE: "; cp = "NOTICE: ";
break; break;
case ERROR: case ERROR:
cp = "ERROR: "; cp = "ERROR: ";
break; break;
default: default:
sprintf(line, "FATAL %d: ", lev); sprintf(line, "FATAL %d: ", lev);
cp = line; cp = line;
} }
#ifdef ELOG_TIMESTAMPS #ifdef ELOG_TIMESTAMPS
time(&tim); strcpy(buf, tprintf_timestamp());
strcat(strcpy(buf, cp), ctime(&tim) + 4); strcat(buf, cp);
bp = buf + strlen(buf) - 6;
*bp++ = ':';
#else #else
strcpy(buf, cp); strcpy(buf, cp);
bp = buf + strlen(buf);
#endif #endif
bp = buf + strlen(buf);
while (i-- > 0) while (i-- > 0)
*bp++ = ' '; *bp++ = ' ';
for (cp = fmt; *cp; cp++) for (cp = fmt; *cp; cp++)
...@@ -118,8 +135,31 @@ elog(int lev, const char *fmt,...) ...@@ -118,8 +135,31 @@ elog(int lev, const char *fmt,...)
*bp = '\0'; *bp = '\0';
vsprintf(line, buf, ap); vsprintf(line, buf, ap);
va_end(ap); va_end(ap);
#ifdef USE_SYSLOG
switch (lev) {
case NOIND:
log_level = LOG_DEBUG;
break;
case DEBUG:
log_level = LOG_DEBUG;
break;
case NOTICE:
log_level = LOG_NOTICE;
break;
case ERROR:
log_level = LOG_WARNING;
break;
case FATAL:
default:
log_level = LOG_ERR;
break;
}
write_syslog(log_level, line+TIMESTAMP_SIZE);
#endif
len = strlen(strcat(line, "\n")); len = strlen(strcat(line, "\n"));
if (Debugfile > -1) if ((Debugfile > -1) && (UseSyslog <= 1))
write(Debugfile, line, len); write(Debugfile, line, len);
if (lev == DEBUG || lev == NOIND) if (lev == DEBUG || lev == NOIND)
return; return;
...@@ -135,7 +175,7 @@ elog(int lev, const char *fmt,...) ...@@ -135,7 +175,7 @@ elog(int lev, const char *fmt,...)
* log. This is a major pain. * log. This is a major pain.
*/ */
if (Err_file > -1 && Debugfile != Err_file) if (Err_file > -1 && Debugfile != Err_file && (UseSyslog <= 1))
{ {
if (write(Err_file, line, len) < 0) if (write(Err_file, line, len) < 0)
{ {
...@@ -157,7 +197,7 @@ elog(int lev, const char *fmt,...) ...@@ -157,7 +197,7 @@ elog(int lev, const char *fmt,...)
else else
pq_putnchar("E", 1); pq_putnchar("E", 1);
/* pq_putint(-101, 4); *//* should be query id */ /* pq_putint(-101, 4); *//* should be query id */
pq_putstr(line); pq_putstr(line+TIMESTAMP_SIZE); /* don't show timestamps */
pq_flush(); pq_flush();
} }
if (Pfout == NULL) if (Pfout == NULL)
...@@ -178,7 +218,7 @@ elog(int lev, const char *fmt,...) ...@@ -178,7 +218,7 @@ elog(int lev, const char *fmt,...)
ProcReleaseSpins(NULL); /* get rid of spinlocks we hold */ ProcReleaseSpins(NULL); /* get rid of spinlocks we hold */
if (!InError) if (!InError)
{ {
kill(MyProcPid, SIGHUP); /* abort to traffic cop */ kill(MyProcPid, SIGQUIT); /* abort to traffic cop */
pause(); pause();
} }
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
# Makefile for utils/misc # Makefile for utils/misc
# #
# IDENTIFICATION # IDENTIFICATION
# $Header: /cvsroot/pgsql/src/backend/utils/misc/Makefile,v 1.8 1998/07/26 04:31:06 scrappy Exp $ # $Header: /cvsroot/pgsql/src/backend/utils/misc/Makefile,v 1.9 1998/08/25 21:34:10 scrappy Exp $
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
...@@ -17,7 +17,7 @@ ifdef MULTIBYTE ...@@ -17,7 +17,7 @@ ifdef MULTIBYTE
CFLAGS+= $(MBFLAGS) CFLAGS+= $(MBFLAGS)
endif endif
OBJS = database.o superuser.o OBJS = database.o superuser.o trace.o
all: SUBSYS.o all: SUBSYS.o
......
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