PostgreSQL Source Code git master
Loading...
Searching...
No Matches
syslogger.c File Reference
#include "postgres.h"
#include <fcntl.h>
#include <limits.h>
#include <signal.h>
#include <time.h>
#include <unistd.h>
#include <sys/stat.h>
#include "common/file_perm.h"
#include "lib/stringinfo.h"
#include "libpq/pqsignal.h"
#include "miscadmin.h"
#include "nodes/pg_list.h"
#include "pgstat.h"
#include "pgtime.h"
#include "port/pg_bitutils.h"
#include "postmaster/interrupt.h"
#include "postmaster/postmaster.h"
#include "postmaster/syslogger.h"
#include "storage/dsm.h"
#include "storage/fd.h"
#include "storage/ipc.h"
#include "storage/latch.h"
#include "storage/pg_shmem.h"
#include "tcop/tcopprot.h"
#include "utils/guc.h"
#include "utils/memutils.h"
#include "utils/ps_status.h"
Include dependency graph for syslogger.c:

Go to the source code of this file.

Data Structures

struct  save_buffer
 
struct  SysloggerStartupData
 

Macros

#define READ_BUF_SIZE   (2 * PIPE_CHUNK_SIZE)
 
#define LOGROTATE_SIGNAL_FILE   "logrotate"
 
#define NBUFFER_LISTS   256
 

Functions

static void process_pipe_input (char *logbuffer, int *bytes_in_logbuffer)
 
static void flush_pipe_input (char *logbuffer, int *bytes_in_logbuffer)
 
static FILElogfile_open (const char *filename, const char *mode, bool allow_errors)
 
static void logfile_rotate (bool time_based_rotation, int size_rotation_for)
 
static bool logfile_rotate_dest (bool time_based_rotation, int size_rotation_for, pg_time_t fntime, int target_dest, char **last_file_name, FILE **logFile)
 
static charlogfile_getname (pg_time_t timestamp, const char *suffix)
 
static void set_next_rotation_time (void)
 
static void sigUsr1Handler (SIGNAL_ARGS)
 
static void update_metainfo_datafile (void)
 
void SysLoggerMain (const void *startup_data, size_t startup_data_len)
 
int SysLogger_Start (int child_slot)
 
void write_syslogger_file (const char *buffer, int count, int destination)
 
bool CheckLogrotateSignal (void)
 
void RemoveLogrotateSignalFiles (void)
 

Variables

bool Logging_collector = false
 
int Log_RotationAge = HOURS_PER_DAY * MINS_PER_HOUR
 
int Log_RotationSize = 10 * 1024
 
charLog_directory = NULL
 
charLog_filename = NULL
 
bool Log_truncate_on_rotation = false
 
int Log_file_mode = S_IRUSR | S_IWUSR
 
static pg_time_t next_rotation_time
 
static bool pipe_eof_seen = false
 
static bool rotation_disabled = false
 
static FILEsyslogFile = NULL
 
static FILEcsvlogFile = NULL
 
static FILEjsonlogFile = NULL
 
NON_EXEC_STATIC pg_time_t first_syslogger_file_time = 0
 
static charlast_sys_file_name = NULL
 
static charlast_csv_file_name = NULL
 
static charlast_json_file_name = NULL
 
static Listbuffer_lists [NBUFFER_LISTS]
 
int syslogPipe [2] = {-1, -1}
 
static volatile sig_atomic_t rotation_requested = false
 

Macro Definition Documentation

◆ LOGROTATE_SIGNAL_FILE

#define LOGROTATE_SIGNAL_FILE   "logrotate"

Definition at line 63 of file syslogger.c.

◆ NBUFFER_LISTS

#define NBUFFER_LISTS   256

Definition at line 109 of file syslogger.c.

◆ READ_BUF_SIZE

#define READ_BUF_SIZE   (2 * PIPE_CHUNK_SIZE)

Definition at line 60 of file syslogger.c.

Function Documentation

◆ CheckLogrotateSignal()

bool CheckLogrotateSignal ( void  )

Definition at line 1573 of file syslogger.c.

1574{
1575 struct stat stat_buf;
1576
1578 return true;
1579
1580 return false;
1581}
static int fb(int x)
#define LOGROTATE_SIGNAL_FILE
Definition syslogger.c:63
#define stat
Definition win32_port.h:74

References fb(), LOGROTATE_SIGNAL_FILE, and stat.

Referenced by process_pm_pmsignal().

◆ flush_pipe_input()

static void flush_pipe_input ( char logbuffer,
int bytes_in_logbuffer 
)
static

Definition at line 1041 of file syslogger.c.

1042{
1043 int i;
1044
1045 /* Dump any incomplete protocol messages */
1046 for (i = 0; i < NBUFFER_LISTS; i++)
1047 {
1048 List *list = buffer_lists[i];
1049 ListCell *cell;
1050
1051 foreach(cell, list)
1052 {
1053 save_buffer *buf = (save_buffer *) lfirst(cell);
1054
1055 if (buf->pid != 0)
1056 {
1057 StringInfo str = &(buf->data);
1058
1059 write_syslogger_file(str->data, str->len,
1061 /* Mark the buffer unused, and reclaim string storage */
1062 buf->pid = 0;
1063 pfree(str->data);
1064 }
1065 }
1066 }
1067
1068 /*
1069 * Force out any remaining pipe data as-is; we don't bother trying to
1070 * remove any protocol headers that may exist in it.
1071 */
1072 if (*bytes_in_logbuffer > 0)
1075 *bytes_in_logbuffer = 0;
1076}
#define LOG_DESTINATION_STDERR
Definition elog.h:485
const char * str
int i
Definition isn.c:77
void pfree(void *pointer)
Definition mcxt.c:1616
#define lfirst(lc)
Definition pg_list.h:172
static char buf[DEFAULT_XLOG_SEG_SIZE]
Definition pg_list.h:54
#define NBUFFER_LISTS
Definition syslogger.c:109
void write_syslogger_file(const char *buffer, int count, int destination)
Definition syslogger.c:1092
static List * buffer_lists[NBUFFER_LISTS]
Definition syslogger.c:110

References buf, buffer_lists, fb(), i, lfirst, LOG_DESTINATION_STDERR, NBUFFER_LISTS, pfree(), str, and write_syslogger_file().

Referenced by SysLoggerMain().

◆ logfile_getname()

static char * logfile_getname ( pg_time_t  timestamp,
const char suffix 
)
static

Definition at line 1411 of file syslogger.c.

1412{
1413 char *filename;
1414 int len;
1415
1417
1419
1420 len = strlen(filename);
1421
1422 /* treat Log_filename as a strftime pattern */
1425
1426 if (suffix != NULL)
1427 {
1428 len = strlen(filename);
1429 if (len > 4 && (strcmp(filename + (len - 4), ".log") == 0))
1430 len -= 4;
1431 strlcpy(filename + len, suffix, MAXPGPATH - len);
1432 }
1433
1434 return filename;
1435}
void * palloc(Size size)
Definition mcxt.c:1387
#define MAXPGPATH
const void size_t len
static char * filename
Definition pg_dumpall.c:120
size_t pg_strftime(char *s, size_t maxsize, const char *format, const struct pg_tm *t)
Definition strftime.c:128
struct pg_tm * pg_localtime(const pg_time_t *timep, const pg_tz *tz)
Definition localtime.c:1345
PGDLLIMPORT pg_tz * log_timezone
Definition pgtz.c:31
int64 timestamp
#define snprintf
Definition port.h:260
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition strlcpy.c:45
char * Log_directory
Definition syslogger.c:73
char * Log_filename
Definition syslogger.c:74

References fb(), filename, len, Log_directory, Log_filename, log_timezone, MAXPGPATH, palloc(), pg_localtime(), pg_strftime(), snprintf, and strlcpy().

Referenced by logfile_rotate_dest(), SysLogger_Start(), and SysLoggerMain().

◆ logfile_open()

static FILE * logfile_open ( const char filename,
const char mode,
bool  allow_errors 
)
static

Definition at line 1218 of file syslogger.c.

1219{
1220 FILE *fh;
1221 mode_t oumask;
1222
1223 /*
1224 * Note we do not let Log_file_mode disable IWUSR, since we certainly want
1225 * to be able to write the files ourselves.
1226 */
1228 fh = fopen(filename, mode);
1229 umask(oumask);
1230
1231 if (fh)
1232 {
1233 setvbuf(fh, NULL, PG_IOLBF, 0);
1234
1235#ifdef WIN32
1236 /* use CRLF line endings on Windows */
1238#endif
1239 }
1240 else
1241 {
1242 int save_errno = errno;
1243
1246 errmsg("could not open log file \"%s\": %m",
1247 filename)));
1248 errno = save_errno;
1249 }
1250
1251 return fh;
1252}
int errcode_for_file_access(void)
Definition elog.c:886
int errmsg(const char *fmt,...)
Definition elog.c:1080
#define LOG
Definition elog.h:31
#define FATAL
Definition elog.h:41
#define ereport(elevel,...)
Definition elog.h:150
static PgChecksumMode mode
#define PG_IOLBF
Definition port.h:409
int Log_file_mode
Definition syslogger.c:76
#define S_IRWXG
Definition win32_port.h:300
#define S_IRWXO
Definition win32_port.h:312
#define S_IWUSR
Definition win32_port.h:282
#define S_IRWXU
Definition win32_port.h:288

References ereport, errcode_for_file_access(), errmsg(), FATAL, fb(), filename, LOG, Log_file_mode, mode, PG_IOLBF, S_IRWXG, S_IRWXO, S_IRWXU, and S_IWUSR.

Referenced by logfile_rotate_dest(), and SysLogger_Start().

◆ logfile_rotate()

static void logfile_rotate ( bool  time_based_rotation,
int  size_rotation_for 
)
static

Definition at line 1362 of file syslogger.c.

1363{
1365
1366 rotation_requested = false;
1367
1368 /*
1369 * When doing a time-based rotation, invent the new logfile name based on
1370 * the planned rotation time, not current time, to avoid "slippage" in the
1371 * file name when we don't do the rotation immediately.
1372 */
1375 else
1376 fntime = time(NULL);
1377
1378 /* file rotation for stderr */
1381 &syslogFile))
1382 return;
1383
1384 /* file rotation for csvlog */
1387 &csvlogFile))
1388 return;
1389
1390 /* file rotation for jsonlog */
1393 &jsonlogFile))
1394 return;
1395
1397
1399}
#define LOG_DESTINATION_JSONLOG
Definition elog.h:489
#define LOG_DESTINATION_CSVLOG
Definition elog.h:488
int64 pg_time_t
Definition pgtime.h:23
static bool logfile_rotate_dest(bool time_based_rotation, int size_rotation_for, pg_time_t fntime, int target_dest, char **last_file_name, FILE **logFile)
Definition syslogger.c:1263
static void update_metainfo_datafile(void)
Definition syslogger.c:1476
static char * last_csv_file_name
Definition syslogger.c:89
static FILE * syslogFile
Definition syslogger.c:84
static pg_time_t next_rotation_time
Definition syslogger.c:81
static volatile sig_atomic_t rotation_requested
Definition syslogger.c:127
static FILE * csvlogFile
Definition syslogger.c:85
static void set_next_rotation_time(void)
Definition syslogger.c:1441
static FILE * jsonlogFile
Definition syslogger.c:86
static char * last_json_file_name
Definition syslogger.c:90
static char * last_sys_file_name
Definition syslogger.c:88

References csvlogFile, fb(), jsonlogFile, last_csv_file_name, last_json_file_name, last_sys_file_name, LOG_DESTINATION_CSVLOG, LOG_DESTINATION_JSONLOG, LOG_DESTINATION_STDERR, logfile_rotate_dest(), next_rotation_time, rotation_requested, set_next_rotation_time(), syslogFile, and update_metainfo_datafile().

Referenced by SysLoggerMain().

◆ logfile_rotate_dest()

static bool logfile_rotate_dest ( bool  time_based_rotation,
int  size_rotation_for,
pg_time_t  fntime,
int  target_dest,
char **  last_file_name,
FILE **  logFile 
)
static

Definition at line 1263 of file syslogger.c.

1266{
1267 char *logFileExt = NULL;
1268 char *filename;
1269 FILE *fh;
1270
1271 /*
1272 * If the target destination was just turned off, close the previous file
1273 * and unregister its data. This cannot happen for stderr as syslogFile
1274 * is assumed to be always opened even if stderr is disabled in
1275 * log_destination.
1276 */
1277 if ((Log_destination & target_dest) == 0 &&
1279 {
1280 if (*logFile != NULL)
1281 fclose(*logFile);
1282 *logFile = NULL;
1283 if (*last_file_name != NULL)
1286 return true;
1287 }
1288
1289 /*
1290 * Leave if it is not time for a rotation or if the target destination has
1291 * no need to do a rotation based on the size of its file.
1292 */
1294 return true;
1295
1296 /* file extension depends on the destination type */
1298 logFileExt = NULL;
1300 logFileExt = ".csv";
1302 logFileExt = ".json";
1303 else
1304 {
1305 /* cannot happen */
1306 Assert(false);
1307 }
1308
1309 /* build the new file name */
1311
1312 /*
1313 * Decide whether to overwrite or append. We can overwrite if (a)
1314 * Log_truncate_on_rotation is set, (b) the rotation was triggered by
1315 * elapsed time and not something else, and (c) the computed file name is
1316 * different from what we were previously logging into.
1317 */
1319 *last_file_name != NULL &&
1321 fh = logfile_open(filename, "w", true);
1322 else
1323 fh = logfile_open(filename, "a", true);
1324
1325 if (!fh)
1326 {
1327 /*
1328 * ENFILE/EMFILE are not too surprising on a busy system; just keep
1329 * using the old file till we manage to get a new one. Otherwise,
1330 * assume something's wrong with Log_directory and stop trying to
1331 * create files.
1332 */
1333 if (errno != ENFILE && errno != EMFILE)
1334 {
1335 ereport(LOG,
1336 (errmsg("disabling automatic rotation (use SIGHUP to re-enable)")));
1337 rotation_disabled = true;
1338 }
1339
1340 if (filename)
1341 pfree(filename);
1342 return false;
1343 }
1344
1345 /* fill in the new information */
1346 if (*logFile != NULL)
1347 fclose(*logFile);
1348 *logFile = fh;
1349
1350 /* instead of pfree'ing filename, remember it for next time */
1351 if (*last_file_name != NULL)
1354
1355 return true;
1356}
#define Assert(condition)
Definition c.h:873
int Log_destination
Definition elog.c:111
bool Log_truncate_on_rotation
Definition syslogger.c:75
static bool rotation_disabled
Definition syslogger.c:83
static char * logfile_getname(pg_time_t timestamp, const char *suffix)
Definition syslogger.c:1411
static FILE * logfile_open(const char *filename, const char *mode, bool allow_errors)
Definition syslogger.c:1218

References Assert, ereport, errmsg(), fb(), filename, LOG, Log_destination, LOG_DESTINATION_CSVLOG, LOG_DESTINATION_JSONLOG, LOG_DESTINATION_STDERR, Log_truncate_on_rotation, logfile_getname(), logfile_open(), pfree(), and rotation_disabled.

Referenced by logfile_rotate().

◆ process_pipe_input()

static void process_pipe_input ( char logbuffer,
int bytes_in_logbuffer 
)
static

Definition at line 878 of file syslogger.c.

879{
880 char *cursor = logbuffer;
881 int count = *bytes_in_logbuffer;
883
884 /* While we have enough for a header, process data... */
885 while (count >= (int) (offsetof(PipeProtoHeader, data) + 1))
886 {
888 int chunklen;
890
891 /* Do we have a valid header? */
896 if (p.nuls[0] == '\0' && p.nuls[1] == '\0' &&
897 p.len > 0 && p.len <= PIPE_MAX_PAYLOAD &&
898 p.pid != 0 &&
900 {
902 ListCell *cell;
904 *free_slot = NULL;
906
908
909 /* Fall out of loop if we don't have the whole chunk yet */
910 if (count < chunklen)
911 break;
912
913 if ((p.flags & PIPE_PROTO_DEST_STDERR) != 0)
915 else if ((p.flags & PIPE_PROTO_DEST_CSVLOG) != 0)
917 else if ((p.flags & PIPE_PROTO_DEST_JSONLOG) != 0)
919 else
920 {
921 /* this should never happen as of the header validation */
922 Assert(false);
923 }
924
925 /* Locate any existing buffer for this source pid */
927 foreach(cell, buffer_list)
928 {
929 save_buffer *buf = (save_buffer *) lfirst(cell);
930
931 if (buf->pid == p.pid)
932 {
934 break;
935 }
936 if (buf->pid == 0 && free_slot == NULL)
937 free_slot = buf;
938 }
939
940 if ((p.flags & PIPE_PROTO_IS_LAST) == 0)
941 {
942 /*
943 * Save a complete non-final chunk in a per-pid buffer
944 */
945 if (existing_slot != NULL)
946 {
947 /* Add chunk to data from preceding chunks */
948 str = &(existing_slot->data);
951 p.len);
952 }
953 else
954 {
955 /* First chunk of message, save in a new buffer */
956 if (free_slot == NULL)
957 {
958 /*
959 * Need a free slot, but there isn't one in the list,
960 * so create a new one and extend the list with it.
961 */
965 }
966 free_slot->pid = p.pid;
967 str = &(free_slot->data);
971 p.len);
972 }
973 }
974 else
975 {
976 /*
977 * Final chunk --- add it to anything saved for that pid, and
978 * either way write the whole thing out.
979 */
980 if (existing_slot != NULL)
981 {
982 str = &(existing_slot->data);
985 p.len);
986 write_syslogger_file(str->data, str->len, dest);
987 /* Mark the buffer unused, and reclaim string storage */
988 existing_slot->pid = 0;
989 pfree(str->data);
990 }
991 else
992 {
993 /* The whole message was one chunk, evidently. */
995 dest);
996 }
997 }
998
999 /* Finished processing this chunk */
1000 cursor += chunklen;
1001 count -= chunklen;
1002 }
1003 else
1004 {
1005 /* Process non-protocol data */
1006
1007 /*
1008 * Look for the start of a protocol header. If found, dump data
1009 * up to there and repeat the loop. Otherwise, dump it all and
1010 * fall out of the loop. (Note: we want to dump it all if at all
1011 * possible, so as to avoid dividing non-protocol messages across
1012 * logfiles. We expect that in many scenarios, a non-protocol
1013 * message will arrive all in one read(), and we want to respect
1014 * the read() boundary if possible.)
1015 */
1016 for (chunklen = 1; chunklen < count; chunklen++)
1017 {
1018 if (cursor[chunklen] == '\0')
1019 break;
1020 }
1021 /* fall back on the stderr log as the destination */
1023 cursor += chunklen;
1024 count -= chunklen;
1025 }
1026 }
1027
1028 /* We don't have a full chunk, so left-align what remains in the buffer */
1029 if (count > 0 && cursor != logbuffer)
1030 memmove(logbuffer, cursor, count);
1031 *bytes_in_logbuffer = count;
1032}
uint8 bits8
Definition c.h:553
#define palloc_object(type)
Definition fe_memutils.h:74
List * lappend(List *list, void *datum)
Definition list.c:339
PGDLLIMPORT const uint8 pg_number_of_ones[256]
Definition pg_bitutils.c:80
const void * data
void appendBinaryStringInfo(StringInfo str, const void *data, int datalen)
Definition stringinfo.c:281
void initStringInfo(StringInfo str)
Definition stringinfo.c:97
Definition type.h:138
#define PIPE_PROTO_DEST_JSONLOG
Definition syslogger.h:67
#define PIPE_PROTO_IS_LAST
Definition syslogger.h:63
#define PIPE_PROTO_DEST_CSVLOG
Definition syslogger.h:66
#define PIPE_PROTO_DEST_STDERR
Definition syslogger.h:65
#define PIPE_MAX_PAYLOAD
Definition syslogger.h:60
#define PIPE_HEADER_SIZE
Definition syslogger.h:59

References appendBinaryStringInfo(), Assert, buf, buffer_lists, data, fb(), PipeProtoHeader::flags, initStringInfo(), lappend(), PipeProtoHeader::len, lfirst, LOG_DESTINATION_CSVLOG, LOG_DESTINATION_JSONLOG, LOG_DESTINATION_STDERR, NBUFFER_LISTS, PipeProtoHeader::nuls, palloc_object, pfree(), pg_number_of_ones, PipeProtoHeader::pid, PIPE_HEADER_SIZE, PIPE_MAX_PAYLOAD, PIPE_PROTO_DEST_CSVLOG, PIPE_PROTO_DEST_JSONLOG, PIPE_PROTO_DEST_STDERR, PIPE_PROTO_IS_LAST, str, and write_syslogger_file().

Referenced by SysLoggerMain().

◆ RemoveLogrotateSignalFiles()

void RemoveLogrotateSignalFiles ( void  )

Definition at line 1587 of file syslogger.c.

1588{
1590}

References fb(), and LOGROTATE_SIGNAL_FILE.

Referenced by PostmasterMain(), and process_pm_pmsignal().

◆ set_next_rotation_time()

static void set_next_rotation_time ( void  )
static

Definition at line 1441 of file syslogger.c.

1442{
1443 pg_time_t now;
1444 struct pg_tm *tm;
1445 int rotinterval;
1446
1447 /* nothing to do if time-based rotation is disabled */
1448 if (Log_RotationAge <= 0)
1449 return;
1450
1451 /*
1452 * The requirements here are to choose the next time > now that is a
1453 * "multiple" of the log rotation interval. "Multiple" can be interpreted
1454 * fairly loosely. In this version we align to log_timezone rather than
1455 * GMT.
1456 */
1457 rotinterval = Log_RotationAge * SECS_PER_MINUTE; /* convert to seconds */
1458 now = (pg_time_t) time(NULL);
1460 now += tm->tm_gmtoff;
1461 now -= now % rotinterval;
1462 now += rotinterval;
1463 now -= tm->tm_gmtoff;
1465}
Datum now(PG_FUNCTION_ARGS)
Definition timestamp.c:1609
#define SECS_PER_MINUTE
Definition timestamp.h:128
static struct pg_tm tm
Definition localtime.c:104
Definition pgtime.h:35
long int tm_gmtoff
Definition pgtime.h:45
int Log_RotationAge
Definition syslogger.c:71

References fb(), Log_RotationAge, log_timezone, next_rotation_time, now(), pg_localtime(), SECS_PER_MINUTE, tm, and pg_tm::tm_gmtoff.

Referenced by logfile_rotate(), and SysLoggerMain().

◆ sigUsr1Handler()

static void sigUsr1Handler ( SIGNAL_ARGS  )
static

Definition at line 1594 of file syslogger.c.

1595{
1596 rotation_requested = true;
1598}
struct Latch * MyLatch
Definition globals.c:63
void SetLatch(Latch *latch)
Definition latch.c:290

References MyLatch, rotation_requested, and SetLatch().

Referenced by SysLoggerMain().

◆ SysLogger_Start()

int SysLogger_Start ( int  child_slot)

Definition at line 592 of file syslogger.c.

593{
595 char *filename;
596#ifdef EXEC_BACKEND
598#endif /* EXEC_BACKEND */
599
601
602 /*
603 * If first time through, create the pipe which will receive stderr
604 * output.
605 *
606 * If the syslogger crashes and needs to be restarted, we continue to use
607 * the same pipe (indeed must do so, since extant backends will be writing
608 * into that pipe).
609 *
610 * This means the postmaster must continue to hold the read end of the
611 * pipe open, so we can pass it down to the reincarnated syslogger. This
612 * is a bit klugy but we have little choice.
613 *
614 * Also note that we don't bother counting the pipe FDs by calling
615 * Reserve/ReleaseExternalFD. There's no real need to account for them
616 * accurately in the postmaster or syslogger process, and both ends of the
617 * pipe will wind up closed in all other postmaster children.
618 */
619#ifndef WIN32
620 if (syslogPipe[0] < 0)
621 {
622 if (pipe(syslogPipe) < 0)
625 errmsg("could not create pipe for syslog: %m")));
626 }
627#else
628 if (!syslogPipe[0])
629 {
631
632 memset(&sa, 0, sizeof(SECURITY_ATTRIBUTES));
633 sa.nLength = sizeof(SECURITY_ATTRIBUTES);
634 sa.bInheritHandle = TRUE;
635
636 if (!CreatePipe(&syslogPipe[0], &syslogPipe[1], &sa, 32768))
639 errmsg("could not create pipe for syslog: %m")));
640 }
641#endif
642
643 /*
644 * Create log directory if not present; ignore errors
645 */
647
648 /*
649 * The initial logfile is created right in the postmaster, to verify that
650 * the Log_directory is writable. We save the reference time so that the
651 * syslogger child process can recompute this file name.
652 *
653 * It might look a bit strange to re-do this during a syslogger restart,
654 * but we must do so since the postmaster closed syslogFile after the
655 * previous fork (and remembering that old file wouldn't be right anyway).
656 * Note we always append here, we won't overwrite any existing file. This
657 * is consistent with the normal rules, because by definition this is not
658 * a time-based rotation.
659 */
661
663
664 syslogFile = logfile_open(filename, "a", false);
665
667
668 /*
669 * Likewise for the initial CSV log file, if that's enabled. (Note that
670 * we open syslogFile even when only CSV output is nominally enabled,
671 * since some code paths will write to syslogFile anyway.)
672 */
674 {
676
677 csvlogFile = logfile_open(filename, "a", false);
678
680 }
681
682 /*
683 * Likewise for the initial JSON log file, if that's enabled. (Note that
684 * we open syslogFile even when only JSON output is nominally enabled,
685 * since some code paths will write to syslogFile anyway.)
686 */
688 {
690
691 jsonlogFile = logfile_open(filename, "a", false);
692
694 }
695
696#ifdef EXEC_BACKEND
701 &startup_data, sizeof(startup_data), NULL);
702#else
704 NULL, 0, NULL);
705#endif /* EXEC_BACKEND */
706
707 if (sysloggerPid == -1)
708 {
709 ereport(LOG,
710 (errmsg("could not fork system logger: %m")));
711 return 0;
712 }
713
714 /* success, in postmaster */
715
716 /* now we redirect stderr, if not done already */
717 if (!redirection_done)
718 {
719#ifdef WIN32
720 int fd;
721#endif
722
723 /*
724 * Leave a breadcrumb trail when redirecting, in case the user forgets
725 * that redirection is active and looks only at the original stderr
726 * target file.
727 */
728 ereport(LOG,
729 (errmsg("redirecting log output to logging collector process"),
730 errhint("Future log output will appear in directory \"%s\".",
731 Log_directory)));
732
733#ifndef WIN32
734 fflush(stdout);
735 if (dup2(syslogPipe[1], STDOUT_FILENO) < 0)
738 errmsg("could not redirect stdout: %m")));
739 fflush(stderr);
740 if (dup2(syslogPipe[1], STDERR_FILENO) < 0)
743 errmsg("could not redirect stderr: %m")));
744 /* Now we are done with the write end of the pipe. */
745 close(syslogPipe[1]);
746 syslogPipe[1] = -1;
747#else
748
749 /*
750 * open the pipe in binary mode and make sure stderr is binary after
751 * it's been dup'ed into, to avoid disturbing the pipe chunking
752 * protocol.
753 */
754 fflush(stderr);
757 if (dup2(fd, STDERR_FILENO) < 0)
760 errmsg("could not redirect stderr: %m")));
761 close(fd);
763
764 /*
765 * Now we are done with the write end of the pipe. CloseHandle() must
766 * not be called because the preceding close() closes the underlying
767 * handle.
768 */
769 syslogPipe[1] = 0;
770#endif
771 redirection_done = true;
772 }
773
774 /* postmaster will never write the file(s); close 'em */
777 if (csvlogFile != NULL)
778 {
781 }
782 if (jsonlogFile != NULL)
783 {
786 }
787 return (int) sysloggerPid;
788}
int errcode_for_socket_access(void)
Definition elog.c:963
int errhint(const char *fmt,...)
Definition elog.c:1330
int MakePGDirectory(const char *directoryName)
Definition fd.c:3962
#define close(a)
Definition win32.h:12
pid_t postmaster_child_launch(BackendType child_type, int child_slot, void *startup_data, size_t startup_data_len, ClientSocket *client_sock)
@ B_LOGGER
Definition miscadmin.h:374
bool redirection_done
Definition postmaster.c:375
static int fd(const char *x, int i)
NON_EXEC_STATIC pg_time_t first_syslogger_file_time
Definition syslogger.c:87
int syslogPipe[2]
Definition syslogger.c:114
bool Logging_collector
Definition syslogger.c:70
#define STDOUT_FILENO
Definition unistd.h:8
#define STDERR_FILENO
Definition unistd.h:9

References Assert, B_LOGGER, close, csvlogFile, ereport, errcode_for_file_access(), errcode_for_socket_access(), errhint(), errmsg(), FATAL, fb(), fd(), filename, first_syslogger_file_time, jsonlogFile, LOG, Log_destination, LOG_DESTINATION_CSVLOG, LOG_DESTINATION_JSONLOG, Log_directory, logfile_getname(), logfile_open(), Logging_collector, MakePGDirectory(), pfree(), postmaster_child_launch(), redirection_done, STDERR_FILENO, STDOUT_FILENO, syslogFile, and syslogPipe.

Referenced by StartSysLogger().

◆ SysLoggerMain()

void SysLoggerMain ( const void startup_data,
size_t  startup_data_len 
)

Definition at line 165 of file syslogger.c.

166{
167#ifndef WIN32
169 int bytes_in_logbuffer = 0;
170#endif
171 char *currentLogDir;
172 char *currentLogFilename;
176
177 /*
178 * Re-open the error output files that were opened by SysLogger_Start().
179 *
180 * We expect this will always succeed, which is too optimistic, but if it
181 * fails there's not a lot we can do to report the problem anyway. As
182 * coded, we'll just crash on a null pointer dereference after failure...
183 */
184#ifdef EXEC_BACKEND
185 {
187
188 Assert(startup_data_len == sizeof(*slsdata));
189 syslogFile = syslogger_fdopen(slsdata->syslogFile);
190 csvlogFile = syslogger_fdopen(slsdata->csvlogFile);
191 jsonlogFile = syslogger_fdopen(slsdata->jsonlogFile);
192 }
193#else
195#endif
196
197 /*
198 * Now that we're done reading the startup data, release postmaster's
199 * working memory context.
200 */
202 {
205 }
206
208
210
211 /*
212 * If we restarted, our stderr is already redirected into our own input
213 * pipe. This is of course pretty useless, not to mention that it
214 * interferes with detecting pipe EOF. Point stderr to /dev/null. This
215 * assumes that all interesting messages generated in the syslogger will
216 * come through elog.c and will be sent to write_syslogger_file.
217 */
219 {
220 int fd = open(DEVNULL, O_WRONLY, 0);
221
222 /*
223 * The closes might look redundant, but they are not: we want to be
224 * darn sure the pipe gets closed even if the open failed. We can
225 * survive running with stderr pointing nowhere, but we can't afford
226 * to have extra pipe input descriptors hanging around.
227 *
228 * As we're just trying to reset these to go to DEVNULL, there's not
229 * much point in checking for failure from the close/dup2 calls here,
230 * if they fail then presumably the file descriptors are closed and
231 * any writes will go into the bitbucket anyway.
232 */
235 if (fd != -1)
236 {
239 close(fd);
240 }
241 }
242
243 /*
244 * Syslogger's own stderr can't be the syslogPipe, so set it back to text
245 * mode if we didn't just close it. (It was set to binary in
246 * SubPostmasterMain).
247 */
248#ifdef WIN32
249 else
251#endif
252
253 /*
254 * Also close our copy of the write end of the pipe. This is needed to
255 * ensure we can detect pipe EOF correctly. (But note that in the restart
256 * case, the postmaster already did this.)
257 */
258#ifndef WIN32
259 if (syslogPipe[1] >= 0)
260 close(syslogPipe[1]);
261 syslogPipe[1] = -1;
262#else
263 if (syslogPipe[1])
265 syslogPipe[1] = 0;
266#endif
267
268 /*
269 * Properly accept or ignore signals the postmaster might send us
270 *
271 * Note: we ignore all termination signals, and instead exit only when all
272 * upstream processes are gone, to ensure we don't miss any dying gasps of
273 * broken backends...
274 */
275
276 pqsignal(SIGHUP, SignalHandlerForConfigReload); /* set flag to read config
277 * file */
283 pqsignal(SIGUSR1, sigUsr1Handler); /* request log rotation */
285
286 /*
287 * Reset some signals that are accepted by postmaster but not here
288 */
290
292
293#ifdef WIN32
294 /* Fire up separate data transfer thread */
297
299 if (threadHandle == 0)
300 elog(FATAL, "could not create syslogger data transfer thread: %m");
301#endif /* WIN32 */
302
303 /*
304 * Remember active logfiles' name(s). We recompute 'em from the reference
305 * time because passing down just the pg_time_t is a lot cheaper than
306 * passing a whole file path in the EXEC_BACKEND case.
307 */
309 if (csvlogFile != NULL)
311 if (jsonlogFile != NULL)
313
314 /* remember active logfile parameters */
318 /* set next planned rotation time */
321
322 /*
323 * Reset whereToSendOutput, as the postmaster will do (but hasn't yet, at
324 * the point where we forked). This prevents duplicate output of messages
325 * from syslogger itself.
326 */
328
329 /*
330 * Set up a reusable WaitEventSet object we'll use to wait for our latch,
331 * and (except on Windows) our socket.
332 *
333 * Unlike all other postmaster child processes, we'll ignore postmaster
334 * death because we want to collect final log output from all backends and
335 * then exit last. We'll do that by running until we see EOF on the
336 * syslog pipe, which implies that all other backends have exited
337 * (including the postmaster).
338 */
341#ifndef WIN32
343#endif
344
345 /* main worker loop */
346 for (;;)
347 {
348 bool time_based_rotation = false;
349 int size_rotation_for = 0;
350 long cur_timeout;
351 WaitEvent event;
352
353#ifndef WIN32
354 int rc;
355#endif
356
357 /* Clear any already-pending wakeups */
359
360 /*
361 * Process any requests or signals received recently.
362 */
364 {
365 ConfigReloadPending = false;
367
368 /*
369 * Check if the log directory or filename pattern changed in
370 * postgresql.conf. If so, force rotation to make sure we're
371 * writing the logfiles in the right place.
372 */
374 {
377 rotation_requested = true;
378
379 /*
380 * Also, create new directory if not present; ignore errors
381 */
383 }
385 {
388 rotation_requested = true;
389 }
390
391 /*
392 * Force a rotation if CSVLOG output was just turned on or off and
393 * we need to open or close csvlogFile accordingly.
394 */
396 (csvlogFile != NULL))
397 rotation_requested = true;
398
399 /*
400 * Force a rotation if JSONLOG output was just turned on or off
401 * and we need to open or close jsonlogFile accordingly.
402 */
404 (jsonlogFile != NULL))
405 rotation_requested = true;
406
407 /*
408 * If rotation time parameter changed, reset next rotation time,
409 * but don't immediately force a rotation.
410 */
412 {
415 }
416
417 /*
418 * If we had a rotation-disabling failure, re-enable rotation
419 * attempts after SIGHUP, and force one immediately.
420 */
422 {
423 rotation_disabled = false;
424 rotation_requested = true;
425 }
426
427 /*
428 * Force rewriting last log filename when reloading configuration.
429 * Even if rotation_requested is false, log_destination may have
430 * been changed and we don't want to wait the next file rotation.
431 */
433 }
434
436 {
437 /* Do a logfile rotation if it's time */
438 now = (pg_time_t) time(NULL);
439 if (now >= next_rotation_time)
441 }
442
444 {
445 /* Do a rotation if file is too big */
446 if (ftello(syslogFile) >= Log_RotationSize * (pgoff_t) 1024)
447 {
448 rotation_requested = true;
450 }
451 if (csvlogFile != NULL &&
453 {
454 rotation_requested = true;
456 }
457 if (jsonlogFile != NULL &&
459 {
460 rotation_requested = true;
462 }
463 }
464
466 {
467 /*
468 * Force rotation when both values are zero. It means the request
469 * was sent by pg_rotate_logfile() or "pg_ctl logrotate".
470 */
476 }
477
478 /*
479 * Calculate time till next time-based rotation, so that we don't
480 * sleep longer than that. We assume the value of "now" obtained
481 * above is still close enough. Note we can't make this calculation
482 * until after calling logfile_rotate(), since it will advance
483 * next_rotation_time.
484 *
485 * Also note that we need to beware of overflow in calculation of the
486 * timeout: with large settings of Log_RotationAge, next_rotation_time
487 * could be more than INT_MAX msec in the future. In that case we'll
488 * wait no more than INT_MAX msec, and try again.
489 */
491 {
493
495 if (delay > 0)
496 {
497 if (delay > INT_MAX / 1000)
498 delay = INT_MAX / 1000;
499 cur_timeout = delay * 1000L; /* msec */
500 }
501 else
502 cur_timeout = 0;
503 }
504 else
505 cur_timeout = -1L;
506
507 /*
508 * Sleep until there's something to do
509 */
510#ifndef WIN32
511 rc = WaitEventSetWait(wes, cur_timeout, &event, 1,
513
514 if (rc == 1 && event.events == WL_SOCKET_READABLE)
515 {
516 int bytesRead;
517
520 sizeof(logbuffer) - bytes_in_logbuffer);
521 if (bytesRead < 0)
522 {
523 if (errno != EINTR)
524 ereport(LOG,
526 errmsg("could not read from logger pipe: %m")));
527 }
528 else if (bytesRead > 0)
529 {
532 continue;
533 }
534 else
535 {
536 /*
537 * Zero bytes read when select() is saying read-ready means
538 * EOF on the pipe: that is, there are no longer any processes
539 * with the pipe write end open. Therefore, the postmaster
540 * and all backends are shut down, and we are done.
541 */
542 pipe_eof_seen = true;
543
544 /* if there's any data left then force it out now */
546 }
547 }
548#else /* WIN32 */
549
550 /*
551 * On Windows we leave it to a separate thread to transfer data and
552 * detect pipe EOF. The main thread just wakes up to handle SIGHUP
553 * and rotation conditions.
554 *
555 * Server code isn't generally thread-safe, so we ensure that only one
556 * of the threads is active at a time by entering the critical section
557 * whenever we're not sleeping.
558 */
560
561 (void) WaitEventSetWait(wes, cur_timeout, &event, 1,
563
565#endif /* WIN32 */
566
567 if (pipe_eof_seen)
568 {
569 /*
570 * seeing this message on the real stderr is annoying - so we make
571 * it DEBUG1 to suppress in normal use.
572 */
574 (errmsg_internal("logger shutting down")));
575
576 /*
577 * Normal exit from the syslogger is here. Note that we
578 * deliberately do not close syslogFile before exiting; this is to
579 * allow for the possibility of elog messages being generated
580 * inside proc_exit. Regular exit() will take care of flushing
581 * and closing stdio channels.
582 */
583 proc_exit(0);
584 }
585 }
586}
sigset_t UnBlockSig
Definition pqsignal.c:22
@ DestNone
Definition dest.h:87
int errmsg_internal(const char *fmt,...)
Definition elog.c:1170
#define DEBUG1
Definition elog.h:30
#define elog(elevel,...)
Definition elog.h:226
pg_time_t MyStartTime
Definition globals.c:48
void ProcessConfigFile(GucContext context)
Definition guc-file.l:120
@ PGC_SIGHUP
Definition guc.h:75
#define read(a, b, c)
Definition win32.h:13
volatile sig_atomic_t ConfigReloadPending
Definition interrupt.c:27
void SignalHandlerForConfigReload(SIGNAL_ARGS)
Definition interrupt.c:61
void proc_exit(int code)
Definition ipc.c:105
void ResetLatch(Latch *latch)
Definition latch.c:374
char * pstrdup(const char *in)
Definition mcxt.c:1781
MemoryContext PostmasterContext
Definition mcxt.c:168
void MemoryContextDelete(MemoryContext context)
Definition mcxt.c:472
#define pqsignal
Definition port.h:547
#define DEVNULL
Definition port.h:161
#define PGINVALID_SOCKET
Definition port.h:31
off_t pgoff_t
Definition port.h:421
CommandDest whereToSendOutput
Definition postgres.c:92
void init_ps_display(const char *fixed_part)
Definition ps_status.c:285
uint32 events
static void logfile_rotate(bool time_based_rotation, int size_rotation_for)
Definition syslogger.c:1362
static bool pipe_eof_seen
Definition syslogger.c:82
#define READ_BUF_SIZE
Definition syslogger.c:60
static void process_pipe_input(char *logbuffer, int *bytes_in_logbuffer)
Definition syslogger.c:878
int Log_RotationSize
Definition syslogger.c:72
static void sigUsr1Handler(SIGNAL_ARGS)
Definition syslogger.c:1594
static void flush_pipe_input(char *logbuffer, int *bytes_in_logbuffer)
Definition syslogger.c:1041
int AddWaitEventToSet(WaitEventSet *set, uint32 events, pgsocket fd, Latch *latch, void *user_data)
int WaitEventSetWait(WaitEventSet *set, long timeout, WaitEvent *occurred_events, int nevents, uint32 wait_event_info)
WaitEventSet * CreateWaitEventSet(ResourceOwner resowner, int nevents)
#define WL_SOCKET_READABLE
#define WL_LATCH_SET
#define SIGCHLD
Definition win32_port.h:168
#define SIGHUP
Definition win32_port.h:158
#define EINTR
Definition win32_port.h:361
#define SIGPIPE
Definition win32_port.h:163
#define SIGQUIT
Definition win32_port.h:159
#define ftello(stream)
Definition win32_port.h:209
#define SIGUSR1
Definition win32_port.h:170
#define SIGALRM
Definition win32_port.h:164
#define SIGUSR2
Definition win32_port.h:171

References AddWaitEventToSet(), Assert, close, ConfigReloadPending, CreateWaitEventSet(), csvlogFile, DEBUG1, DestNone, DEVNULL, EINTR, elog, ereport, errcode_for_socket_access(), errmsg(), errmsg_internal(), WaitEvent::events, FATAL, fb(), fd(), first_syslogger_file_time, flush_pipe_input(), ftello, init_ps_display(), jsonlogFile, last_csv_file_name, last_json_file_name, last_sys_file_name, LOG, Log_destination, LOG_DESTINATION_CSVLOG, LOG_DESTINATION_JSONLOG, LOG_DESTINATION_STDERR, Log_directory, Log_filename, Log_RotationAge, Log_RotationSize, logfile_getname(), logfile_rotate(), MakePGDirectory(), MemoryContextDelete(), MyLatch, MyStartTime, next_rotation_time, now(), pfree(), PGC_SIGHUP, PGINVALID_SOCKET, pipe_eof_seen, PostmasterContext, pqsignal, proc_exit(), process_pipe_input(), ProcessConfigFile(), pstrdup(), read, READ_BUF_SIZE, redirection_done, ResetLatch(), rotation_disabled, rotation_requested, set_next_rotation_time(), SIGALRM, SIGCHLD, SIGHUP, SignalHandlerForConfigReload(), SIGPIPE, SIGQUIT, SIGUSR1, sigUsr1Handler(), SIGUSR2, STDERR_FILENO, STDOUT_FILENO, syslogFile, syslogPipe, UnBlockSig, update_metainfo_datafile(), WaitEventSetWait(), whereToSendOutput, WL_LATCH_SET, and WL_SOCKET_READABLE.

◆ update_metainfo_datafile()

static void update_metainfo_datafile ( void  )
static

Definition at line 1476 of file syslogger.c.

1477{
1478 FILE *fh;
1479 mode_t oumask;
1480
1484 {
1486 ereport(LOG,
1488 errmsg("could not remove file \"%s\": %m",
1490 return;
1491 }
1492
1493 /* use the same permissions as the data directory for the new file */
1496 umask(oumask);
1497
1498 if (fh)
1499 {
1500 setvbuf(fh, NULL, PG_IOLBF, 0);
1501
1502#ifdef WIN32
1503 /* use CRLF line endings on Windows */
1505#endif
1506 }
1507 else
1508 {
1509 ereport(LOG,
1511 errmsg("could not open file \"%s\": %m",
1513 return;
1514 }
1515
1517 {
1518 if (fprintf(fh, "stderr %s\n", last_sys_file_name) < 0)
1519 {
1520 ereport(LOG,
1522 errmsg("could not write file \"%s\": %m",
1524 fclose(fh);
1525 return;
1526 }
1527 }
1528
1530 {
1531 if (fprintf(fh, "csvlog %s\n", last_csv_file_name) < 0)
1532 {
1533 ereport(LOG,
1535 errmsg("could not write file \"%s\": %m",
1537 fclose(fh);
1538 return;
1539 }
1540 }
1541
1543 {
1544 if (fprintf(fh, "jsonlog %s\n", last_json_file_name) < 0)
1545 {
1546 ereport(LOG,
1548 errmsg("could not write file \"%s\": %m",
1550 fclose(fh);
1551 return;
1552 }
1553 }
1554 fclose(fh);
1555
1557 ereport(LOG,
1559 errmsg("could not rename file \"%s\" to \"%s\": %m",
1561}
#define fprintf(file, fmt, msg)
Definition cubescan.l:21
int pg_mode_mask
Definition file_perm.c:25
#define LOG_METAINFO_DATAFILE_TMP
Definition syslogger.h:103
#define LOG_METAINFO_DATAFILE
Definition syslogger.h:102

References ereport, errcode_for_file_access(), errmsg(), fb(), fprintf, last_csv_file_name, last_json_file_name, last_sys_file_name, LOG, Log_destination, LOG_DESTINATION_CSVLOG, LOG_DESTINATION_JSONLOG, LOG_DESTINATION_STDERR, LOG_METAINFO_DATAFILE, LOG_METAINFO_DATAFILE_TMP, PG_IOLBF, and pg_mode_mask.

Referenced by logfile_rotate(), and SysLoggerMain().

◆ write_syslogger_file()

void write_syslogger_file ( const char buffer,
int  count,
int  destination 
)

Definition at line 1092 of file syslogger.c.

1093{
1094 int rc;
1095 FILE *logfile;
1096
1097 /*
1098 * If we're told to write to a structured log file, but it's not open,
1099 * dump the data to syslogFile (which is always open) instead. This can
1100 * happen if structured output is enabled after postmaster start and we've
1101 * been unable to open logFile. There are also race conditions during a
1102 * parameter change whereby backends might send us structured output
1103 * before we open the logFile or after we close it. Writing formatted
1104 * output to the regular log file isn't great, but it beats dropping log
1105 * output on the floor.
1106 *
1107 * Think not to improve this by trying to open logFile on-the-fly. Any
1108 * failure in that would lead to recursion.
1109 */
1114 else
1116
1117 rc = fwrite(buffer, 1, count, logfile);
1118
1119 /*
1120 * Try to report any failure. We mustn't use ereport because it would
1121 * just recurse right back here, but write_stderr is OK: it will write
1122 * either to the postmaster's original stderr, or to /dev/null, but never
1123 * to our input pipe which would result in a different sort of looping.
1124 */
1125 if (rc != count)
1126 write_stderr("could not write to log file: %m\n");
1127}
#define write_stderr(str)
Definition parallel.c:186
static FILE * logfile
Definition pg_regress.c:126

References csvlogFile, fb(), jsonlogFile, LOG_DESTINATION_CSVLOG, LOG_DESTINATION_JSONLOG, logfile, syslogFile, and write_stderr.

Referenced by flush_pipe_input(), process_pipe_input(), send_message_to_server_log(), write_csvlog(), and write_jsonlog().

Variable Documentation

◆ buffer_lists

List* buffer_lists[NBUFFER_LISTS]
static

Definition at line 110 of file syslogger.c.

Referenced by flush_pipe_input(), and process_pipe_input().

◆ csvlogFile

FILE* csvlogFile = NULL
static

Definition at line 85 of file syslogger.c.

Referenced by logfile_rotate(), SysLogger_Start(), SysLoggerMain(), and write_syslogger_file().

◆ first_syslogger_file_time

NON_EXEC_STATIC pg_time_t first_syslogger_file_time = 0

Definition at line 87 of file syslogger.c.

Referenced by SysLogger_Start(), and SysLoggerMain().

◆ jsonlogFile

FILE* jsonlogFile = NULL
static

Definition at line 86 of file syslogger.c.

Referenced by logfile_rotate(), SysLogger_Start(), SysLoggerMain(), and write_syslogger_file().

◆ last_csv_file_name

char* last_csv_file_name = NULL
static

Definition at line 89 of file syslogger.c.

Referenced by logfile_rotate(), SysLoggerMain(), and update_metainfo_datafile().

◆ last_json_file_name

char* last_json_file_name = NULL
static

Definition at line 90 of file syslogger.c.

Referenced by logfile_rotate(), SysLoggerMain(), and update_metainfo_datafile().

◆ last_sys_file_name

char* last_sys_file_name = NULL
static

Definition at line 88 of file syslogger.c.

Referenced by logfile_rotate(), SysLoggerMain(), and update_metainfo_datafile().

◆ Log_directory

char* Log_directory = NULL

◆ Log_file_mode

int Log_file_mode = S_IRUSR | S_IWUSR

Definition at line 76 of file syslogger.c.

Referenced by logfile_open(), and show_log_file_mode().

◆ Log_filename

char* Log_filename = NULL

Definition at line 74 of file syslogger.c.

Referenced by logfile_getname(), and SysLoggerMain().

◆ Log_RotationAge

int Log_RotationAge = HOURS_PER_DAY * MINS_PER_HOUR

Definition at line 71 of file syslogger.c.

Referenced by set_next_rotation_time(), and SysLoggerMain().

◆ Log_RotationSize

int Log_RotationSize = 10 * 1024

Definition at line 72 of file syslogger.c.

Referenced by SysLoggerMain().

◆ Log_truncate_on_rotation

bool Log_truncate_on_rotation = false

Definition at line 75 of file syslogger.c.

Referenced by logfile_rotate_dest().

◆ Logging_collector

◆ next_rotation_time

pg_time_t next_rotation_time
static

Definition at line 81 of file syslogger.c.

Referenced by logfile_rotate(), set_next_rotation_time(), and SysLoggerMain().

◆ pipe_eof_seen

bool pipe_eof_seen = false
static

Definition at line 82 of file syslogger.c.

Referenced by SysLoggerMain().

◆ rotation_disabled

bool rotation_disabled = false
static

Definition at line 83 of file syslogger.c.

Referenced by logfile_rotate_dest(), and SysLoggerMain().

◆ rotation_requested

volatile sig_atomic_t rotation_requested = false
static

Definition at line 127 of file syslogger.c.

Referenced by logfile_rotate(), sigUsr1Handler(), and SysLoggerMain().

◆ syslogFile

FILE* syslogFile = NULL
static

Definition at line 84 of file syslogger.c.

Referenced by logfile_rotate(), SysLogger_Start(), SysLoggerMain(), and write_syslogger_file().

◆ syslogPipe

int syslogPipe[2] = {-1, -1}

Definition at line 114 of file syslogger.c.

114{-1, -1};

Referenced by ClosePostmasterPorts(), SysLogger_Start(), and SysLoggerMain().