Commit e8f10973 authored by Tom Lane's avatar Tom Lane

Endeavor to make pgstats buffer process (a) safe and (b) useful.

Make sure it exits immediately when collector process dies --- in old code,
buffer process would hang around and compete with the new buffer process
for packets.  Make sure it doesn't block on writing the pipe when the
collector falls more than a pipeload behind.  Avoid leaking pgstats FDs
into every backend.
parent 5181d37e
This diff is collapsed.
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.234 2001/08/04 00:14:43 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.235 2001/08/05 02:06:50 tgl Exp $
* *
* NOTES * NOTES
* *
...@@ -227,7 +227,6 @@ extern int optreset; ...@@ -227,7 +227,6 @@ extern int optreset;
static void pmdaemonize(int argc, char *argv[]); static void pmdaemonize(int argc, char *argv[]);
static Port *ConnCreate(int serverFd); static Port *ConnCreate(int serverFd);
static void ConnFree(Port *port); static void ConnFree(Port *port);
static void ClosePostmasterPorts(void);
static void reset_shared(unsigned short port); static void reset_shared(unsigned short port);
static void SIGHUP_handler(SIGNAL_ARGS); static void SIGHUP_handler(SIGNAL_ARGS);
static void pmdie(SIGNAL_ARGS); static void pmdie(SIGNAL_ARGS);
...@@ -1241,8 +1240,8 @@ ConnFree(Port *conn) ...@@ -1241,8 +1240,8 @@ ConnFree(Port *conn)
* that are not needed by that child process. The postmaster still has * that are not needed by that child process. The postmaster still has
* them open, of course. * them open, of course.
*/ */
static void void
ClosePostmasterPorts(void) ClosePostmasterPorts(bool pgstat_too)
{ {
/* Close the listen sockets */ /* Close the listen sockets */
if (NetServer) if (NetServer)
...@@ -1252,6 +1251,9 @@ ClosePostmasterPorts(void) ...@@ -1252,6 +1251,9 @@ ClosePostmasterPorts(void)
StreamClose(ServerSock_UNIX); StreamClose(ServerSock_UNIX);
ServerSock_UNIX = INVALID_SOCK; ServerSock_UNIX = INVALID_SOCK;
#endif #endif
/* Close pgstat control sockets, unless we're starting pgstat itself */
if (pgstat_too)
pgstat_close_sockets();
} }
...@@ -1900,7 +1902,7 @@ DoBackend(Port *port) ...@@ -1900,7 +1902,7 @@ DoBackend(Port *port)
*/ */
/* Close the postmaster's other sockets */ /* Close the postmaster's other sockets */
ClosePostmasterPorts(); ClosePostmasterPorts(true);
/* Save port etc. for ps status */ /* Save port etc. for ps status */
MyProcPort = port; MyProcPort = port;
...@@ -2224,7 +2226,7 @@ SSDataBase(int xlop) ...@@ -2224,7 +2226,7 @@ SSDataBase(int xlop)
on_exit_reset(); on_exit_reset();
/* Close the postmaster's sockets */ /* Close the postmaster's sockets */
ClosePostmasterPorts(); ClosePostmasterPorts(true);
/* Set up command-line arguments for subprocess */ /* Set up command-line arguments for subprocess */
av[ac++] = "postgres"; av[ac++] = "postgres";
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: miscadmin.h,v 1.87 2001/06/18 21:38:02 momjian Exp $ * $Id: miscadmin.h,v 1.88 2001/08/05 02:06:50 tgl Exp $
* *
* NOTES * NOTES
* some of the information in this file should be moved to * some of the information in this file should be moved to
...@@ -108,6 +108,7 @@ extern void ProcessInterrupts(void); ...@@ -108,6 +108,7 @@ extern void ProcessInterrupts(void);
* from postmaster/postmaster.c * from postmaster/postmaster.c
*/ */
extern int PostmasterMain(int argc, char *argv[]); extern int PostmasterMain(int argc, char *argv[]);
extern void ClosePostmasterPorts(bool pgstat_too);
/* /*
* from utils/init/globals.c * from utils/init/globals.c
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* *
* Copyright (c) 2001, PostgreSQL Global Development Group * Copyright (c) 2001, PostgreSQL Global Development Group
* *
* $Id: pgstat.h,v 1.5 2001/08/04 00:14:43 tgl Exp $ * $Id: pgstat.h,v 1.6 2001/08/05 02:06:50 tgl Exp $
* ---------- * ----------
*/ */
#ifndef PGSTAT_H #ifndef PGSTAT_H
...@@ -24,11 +24,11 @@ ...@@ -24,11 +24,11 @@
* ---------- * ----------
*/ */
#define PGSTAT_STAT_INTERVAL 500 /* How often to write the status */ #define PGSTAT_STAT_INTERVAL 500 /* How often to write the status */
/* file in milliseconds. */ /* file, in milliseconds. */
#define PGSTAT_DESTROY_DELAY 10000 /* How long to keep destroyed */ #define PGSTAT_DESTROY_DELAY 10000 /* How long to keep destroyed */
/* objects known to give delayed */ /* objects known to give delayed */
/* UDP packets time to arrive */ /* UDP packets time to arrive, */
/* in milliseconds. */ /* in milliseconds. */
#define PGSTAT_DESTROY_COUNT (PGSTAT_DESTROY_DELAY \ #define PGSTAT_DESTROY_COUNT (PGSTAT_DESTROY_DELAY \
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
/* ---------- /* ----------
* How much of the actual query to send to the collector. * How much of the actual query string to send to the collector.
* ---------- * ----------
*/ */
#define PGSTAT_ACTIVITY_SIZE 256 #define PGSTAT_ACTIVITY_SIZE 256
...@@ -56,13 +56,10 @@ ...@@ -56,13 +56,10 @@
#define PGSTAT_MTYPE_RESETCOUNTER 7 #define PGSTAT_MTYPE_RESETCOUNTER 7
/* ---------- /* ----------
* TODO * Amount of space reserved in pgstat_recvbuffer().
* For simplicity now, the number of messages buffered in
* pgstat_recvbuffer(). Should be an amount of bytes used
* for a gapless wraparound buffer.
* ---------- * ----------
*/ */
#define PGSTAT_RECVBUFFERSZ 1024 #define PGSTAT_RECVBUFFERSZ ((int) (1024 * sizeof(PgStat_Msg)))
/* ---------- /* ----------
...@@ -338,6 +335,7 @@ extern bool pgstat_collect_blocklevel; ...@@ -338,6 +335,7 @@ extern bool pgstat_collect_blocklevel;
extern int pgstat_init(void); extern int pgstat_init(void);
extern int pgstat_start(int real_argc, char *real_argv[]); extern int pgstat_start(int real_argc, char *real_argv[]);
extern int pgstat_ispgstat(int pid); extern int pgstat_ispgstat(int pid);
extern void pgstat_close_sockets(void);
extern void pgstat_beterm(int pid); extern void pgstat_beterm(int pid);
/* ---------- /* ----------
......
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