Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 7414d61

Browse files
committed
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.
1 parent 51e8e18 commit 7414d61

File tree

9 files changed

+428
-186
lines changed

9 files changed

+428
-186
lines changed

src/backend/access/nbtree/nbtree.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtree.c,v 1.29 1998/08/19 02:01:16 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtree.c,v 1.30 1998/08/25 21:33:56 scrappy Exp $
1212
*
1313
* NOTES
1414
* This file contains only the public interface routines.
@@ -35,8 +35,8 @@
3535

3636
#ifdef BTREE_BUILD_STATS
3737
#include <tcop/tcopprot.h>
38-
extern int ShowExecutorStats;
39-
38+
#include <utils/trace.h>
39+
#define ShowExecutorStats pg_options[TRACE_EXECUTORSTATS]
4040
#endif
4141

4242

src/backend/access/nbtree/nbtsort.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
*
77
* IDENTIFICATION
8-
* $Id: nbtsort.c,v 1.30 1998/06/15 19:27:59 momjian Exp $
8+
* $Id: nbtsort.c,v 1.31 1998/08/25 21:33:57 scrappy Exp $
99
*
1010
* NOTES
1111
*
@@ -64,8 +64,8 @@
6464

6565
#ifdef BTREE_BUILD_STATS
6666
#include "tcop/tcopprot.h"
67-
extern int ShowExecutorStats;
68-
67+
#include <utils/trace.h>
68+
#define ShowExecutorStats pg_options[TRACE_EXECUTORSTATS]
6969
#endif
7070

7171
static BTItem _bt_buildadd(Relation index, void *pstate, BTItem bti, int flags);

src/backend/postmaster/postmaster.c

+106-15
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.94 1998/08/25 21:04:36 scrappy Exp $
13+
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.95 1998/08/25 21:33:59 scrappy Exp $
1414
*
1515
* NOTES
1616
*
@@ -92,6 +92,7 @@
9292
#include "port-protos.h" /* For gethostname() */
9393
#endif
9494
#include "storage/fd.h"
95+
#include "utils/trace.h"
9596

9697
#if !defined(MAXINT)
9798
#define MAXINT INT_MAX
@@ -116,6 +117,8 @@ typedef struct bkend
116117
long cancel_key; /* cancel key for cancels for this backend */
117118
} Backend;
118119

120+
Port *MyBackendPort = NULL;
121+
119122
/* list of active backends. For garbage collection only now. */
120123

121124
static Dllist *BackendList;
@@ -232,6 +235,7 @@ static int processCancelRequest(Port *port, PacketLen len, void *pkt);
232235
static int initMasks(fd_set *rmask, fd_set *wmask);
233236
static long PostmasterRandom(void);
234237
static void RandomSalt(char *salt);
238+
static void SignalChildren(SIGNAL_ARGS);
235239

236240
#ifdef CYR_RECODE
237241
void GetCharSetByHost(char *, int, char *);
@@ -314,16 +318,16 @@ PostmasterMain(int argc, char *argv[])
314318
* We need three params so we can display status. If we don't
315319
* get them from the user, let's make them ourselves.
316320
*/
317-
if (argc < 4)
321+
if (argc < 5)
318322
{
319323
int i;
320-
char *new_argv[5];
324+
char *new_argv[6];
321325

322326
for (i=0; i < argc; i++)
323327
new_argv[i] = argv[i];
324-
for (; i < 4; i++)
328+
for (; i < 5; i++)
325329
new_argv[i] = "";
326-
new_argv[4] = NULL;
330+
new_argv[5] = NULL;
327331

328332
if (!Execfile[0] && FindExec(Execfile, argv[0], "postmaster") < 0)
329333
{
@@ -363,6 +367,7 @@ PostmasterMain(int argc, char *argv[])
363367
hostName = hostbuf;
364368
}
365369

370+
MyProcPid = getpid();
366371
DataDir = getenv("PGDATA"); /* default value */
367372

368373
opterr = 0;
@@ -424,6 +429,7 @@ PostmasterMain(int argc, char *argv[])
424429
}
425430
else
426431
DebugLvl = 1;
432+
pg_options[TRACE_VERBOSE] = DebugLvl;
427433
break;
428434
case 'i':
429435
NetServer = true;
@@ -535,14 +541,17 @@ PostmasterMain(int argc, char *argv[])
535541
* Set up signal handlers for the postmaster process.
536542
*/
537543

538-
pqsignal(SIGINT, pmdie);
539-
pqsignal(SIGCHLD, reaper);
540-
pqsignal(SIGTTIN, SIG_IGN);
541-
pqsignal(SIGTTOU, SIG_IGN);
542-
pqsignal(SIGHUP, pmdie);
543-
pqsignal(SIGTERM, pmdie);
544-
pqsignal(SIGCONT, dumpstatus);
545-
pqsignal(SIGPIPE, SIG_IGN);
544+
pqsignal(SIGHUP, pmdie); /* send SIGHUP, don't die */
545+
pqsignal(SIGINT, pmdie); /* die */
546+
pqsignal(SIGQUIT, pmdie); /* send SIGTERM and die */
547+
pqsignal(SIGTERM, pmdie); /* send SIGTERM,SIGKILL and die */
548+
pqsignal(SIGPIPE, SIG_IGN); /* ignored */
549+
pqsignal(SIGUSR1, pmdie); /* send SIGUSR1 and die */
550+
pqsignal(SIGUSR2, pmdie); /* send SIGUSR2, don't die */
551+
pqsignal(SIGCHLD, reaper); /* handle child termination */
552+
pqsignal(SIGTTIN, SIG_IGN); /* ignored */
553+
pqsignal(SIGTTOU, SIG_IGN); /* ignored */
554+
pqsignal(SIGWINCH, dumpstatus); /* dump port status */
546555

547556
status = ServerLoop();
548557

@@ -980,6 +989,52 @@ reset_shared(short port)
980989
static void
981990
pmdie(SIGNAL_ARGS)
982991
{
992+
int i;
993+
994+
TPRINTF(TRACE_VERBOSE, "pmdie %d", postgres_signal_arg);
995+
996+
/*
997+
* Kill self and/or children processes depending on signal number.
998+
*/
999+
switch (postgres_signal_arg) {
1000+
case SIGHUP:
1001+
/* Send SIGHUP to all children (update options flags) */
1002+
SignalChildren(SIGHUP);
1003+
/* Don't die */
1004+
return;
1005+
case SIGINT:
1006+
/* Die without killing children */
1007+
break;
1008+
case SIGQUIT:
1009+
/* Shutdown all children with SIGTERM */
1010+
SignalChildren(SIGTERM);
1011+
/* Don't die */
1012+
return;
1013+
case SIGTERM:
1014+
/* Shutdown all children with SIGTERM and SIGKILL, then die */
1015+
SignalChildren(SIGTERM);
1016+
for (i=0; i<10; i++) {
1017+
if (!DLGetHead(BackendList)) {
1018+
break;
1019+
}
1020+
sleep(1);
1021+
}
1022+
if (DLGetHead(BackendList)) {
1023+
SignalChildren(SIGKILL);
1024+
}
1025+
break;
1026+
case SIGUSR1:
1027+
/* Quick die all children with SIGUSR1 and die */
1028+
SignalChildren(SIGUSR1);
1029+
break;
1030+
case SIGUSR2:
1031+
/* Send SIGUSR2 to all children (AsyncNotifyHandler) */
1032+
SignalChildren(SIGUSR2);
1033+
/* Don't die */
1034+
return;
1035+
}
1036+
1037+
/* exit postmaster */
9831038
proc_exit(0);
9841039
}
9851040

@@ -1122,6 +1177,35 @@ CleanupProc(int pid,
11221177
}
11231178
}
11241179

1180+
/*
1181+
* Send a signal to all chidren processes.
1182+
*/
1183+
static void
1184+
SignalChildren(int signal)
1185+
{
1186+
Dlelem *curr,
1187+
*next;
1188+
Backend *bp;
1189+
int mypid = getpid();
1190+
1191+
curr = DLGetHead(BackendList);
1192+
while (curr)
1193+
{
1194+
next = DLGetSucc(curr);
1195+
bp = (Backend *) DLE_VAL(curr);
1196+
1197+
if (bp->pid != mypid)
1198+
{
1199+
TPRINTF(TRACE_VERBOSE,
1200+
"SignalChildren: sending signal %d to process %d",
1201+
signal, bp->pid);
1202+
kill(bp->pid, signal);
1203+
}
1204+
1205+
curr = next;
1206+
}
1207+
}
1208+
11251209
/*
11261210
* BackendStartup -- start backend process
11271211
*
@@ -1342,6 +1426,9 @@ DoBackend(Port *port)
13421426
StreamClose(ServerSock_INET);
13431427
StreamClose(ServerSock_UNIX);
13441428

1429+
/* Save port for ps status */
1430+
MyProcPort = port;
1431+
13451432
/*
13461433
* Don't want backend to be able to see the postmaster random number
13471434
* generator state. We have to clobber the static random_seed *and*
@@ -1368,7 +1455,13 @@ DoBackend(Port *port)
13681455
* a big win.
13691456
*/
13701457

1458+
#ifndef linux
1459+
/*
1460+
* This doesn't work on linux and overwrites the only valid
1461+
* pointer to the argv buffer. See PS_INIT_STATUS macro.
1462+
*/
13711463
real_argv[0] = Execfile;
1464+
#endif
13721465

13731466
/* Tell the backend it is being called from the postmaster */
13741467
av[ac++] = "-p";
@@ -1386,8 +1479,6 @@ DoBackend(Port *port)
13861479
sprintf(debugbuf, "-d%d", DebugLvl);
13871480
av[ac++] = debugbuf;
13881481
}
1389-
else
1390-
av[ac++] = "-Q";
13911482

13921483
/* Pass the requested debugging output file */
13931484
if (port->tty[0])

0 commit comments

Comments
 (0)