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 "utils/wait_event.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
 
bool syslogger_setup_done = false
 
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 64 of file syslogger.c.

◆ NBUFFER_LISTS

#define NBUFFER_LISTS   256

Definition at line 116 of file syslogger.c.

◆ READ_BUF_SIZE

#define READ_BUF_SIZE   (2 * PIPE_CHUNK_SIZE)

Definition at line 61 of file syslogger.c.

Function Documentation

◆ CheckLogrotateSignal()

bool CheckLogrotateSignal ( void  )

Definition at line 1593 of file syslogger.c.

1594{
1595 struct stat stat_buf;
1596
1598 return true;
1599
1600 return false;
1601}
static int fb(int x)
#define LOGROTATE_SIGNAL_FILE
Definition syslogger.c:64
#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 1061 of file syslogger.c.

1062{
1063 int i;
1064
1065 /* Dump any incomplete protocol messages */
1066 for (i = 0; i < NBUFFER_LISTS; i++)
1067 {
1068 List *list = buffer_lists[i];
1069 ListCell *cell;
1070
1071 foreach(cell, list)
1072 {
1073 save_buffer *buf = (save_buffer *) lfirst(cell);
1074
1075 if (buf->pid != 0)
1076 {
1077 StringInfo str = &(buf->data);
1078
1079 write_syslogger_file(str->data, str->len,
1081 /* Mark the buffer unused, and reclaim string storage */
1082 buf->pid = 0;
1083 pfree(str->data);
1084 }
1085 }
1086 }
1087
1088 /*
1089 * Force out any remaining pipe data as-is; we don't bother trying to
1090 * remove any protocol headers that may exist in it.
1091 */
1092 if (*bytes_in_logbuffer > 0)
1095 *bytes_in_logbuffer = 0;
1096}
#define LOG_DESTINATION_STDERR
Definition elog.h:487
const char * str
int i
Definition isn.c:77
void pfree(void *pointer)
Definition mcxt.c:1619
#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:116
void write_syslogger_file(const char *buffer, int count, int destination)
Definition syslogger.c:1112
static List * buffer_lists[NBUFFER_LISTS]
Definition syslogger.c:117

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 1431 of file syslogger.c.

1432{
1433 char *filename;
1434 int len;
1435
1437
1439
1440 len = strlen(filename);
1441
1442 /* treat Log_filename as a strftime pattern */
1445
1446 if (suffix != NULL)
1447 {
1448 len = strlen(filename);
1449 if (len > 4 && (strcmp(filename + (len - 4), ".log") == 0))
1450 len -= 4;
1451 strlcpy(filename + len, suffix, MAXPGPATH - len);
1452 }
1453
1454 return filename;
1455}
void * palloc(Size size)
Definition mcxt.c:1390
#define MAXPGPATH
const void size_t len
static char * filename
Definition pg_dumpall.c:133
size_t pg_strftime(char *s, size_t maxsize, const char *format, const struct pg_tm *t)
Definition strftime.c:135
struct pg_tm * pg_localtime(const pg_time_t *timep, const pg_tz *tz)
Definition localtime.c:1347
PGDLLIMPORT pg_tz * log_timezone
Definition pgtz.c:31
int64 timestamp
#define snprintf
Definition port.h:261
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition strlcpy.c:45
char * Log_directory
Definition syslogger.c:74
char * Log_filename
Definition syslogger.c:75

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 1238 of file syslogger.c.

1239{
1240 FILE *fh;
1241 mode_t oumask;
1242
1243 /*
1244 * Note we do not let Log_file_mode disable IWUSR, since we certainly want
1245 * to be able to write the files ourselves.
1246 */
1248 fh = fopen(filename, mode);
1249 umask(oumask);
1250
1251 if (fh)
1252 {
1253 setvbuf(fh, NULL, PG_IOLBF, 0);
1254
1255#ifdef WIN32
1256 /* use CRLF line endings on Windows */
1258#endif
1259 }
1260 else
1261 {
1262 int save_errno = errno;
1263
1266 errmsg("could not open log file \"%s\": %m",
1267 filename)));
1268 errno = save_errno;
1269 }
1270
1271 return fh;
1272}
int errcode_for_file_access(void)
Definition elog.c:898
#define LOG
Definition elog.h:32
#define FATAL
Definition elog.h:42
#define ereport(elevel,...)
Definition elog.h:152
static char * errmsg
static PgChecksumMode mode
#define PG_IOLBF
Definition port.h:410
int Log_file_mode
Definition syslogger.c:77
#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 1382 of file syslogger.c.

1383{
1385
1386 rotation_requested = false;
1387
1388 /*
1389 * When doing a time-based rotation, invent the new logfile name based on
1390 * the planned rotation time, not current time, to avoid "slippage" in the
1391 * file name when we don't do the rotation immediately.
1392 */
1395 else
1396 fntime = time(NULL);
1397
1398 /* file rotation for stderr */
1401 &syslogFile))
1402 return;
1403
1404 /* file rotation for csvlog */
1407 &csvlogFile))
1408 return;
1409
1410 /* file rotation for jsonlog */
1413 &jsonlogFile))
1414 return;
1415
1417
1419}
#define LOG_DESTINATION_JSONLOG
Definition elog.h:491
#define LOG_DESTINATION_CSVLOG
Definition elog.h:490
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:1283
static void update_metainfo_datafile(void)
Definition syslogger.c:1496
static char * last_csv_file_name
Definition syslogger.c:96
static FILE * syslogFile
Definition syslogger.c:91
static pg_time_t next_rotation_time
Definition syslogger.c:88
static volatile sig_atomic_t rotation_requested
Definition syslogger.c:134
static FILE * csvlogFile
Definition syslogger.c:92
static void set_next_rotation_time(void)
Definition syslogger.c:1461
static FILE * jsonlogFile
Definition syslogger.c:93
static char * last_json_file_name
Definition syslogger.c:97
static char * last_sys_file_name
Definition syslogger.c:95

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 1283 of file syslogger.c.

1286{
1287 char *logFileExt = NULL;
1288 char *filename;
1289 FILE *fh;
1290
1291 /*
1292 * If the target destination was just turned off, close the previous file
1293 * and unregister its data. This cannot happen for stderr as syslogFile
1294 * is assumed to be always opened even if stderr is disabled in
1295 * log_destination.
1296 */
1297 if ((Log_destination & target_dest) == 0 &&
1299 {
1300 if (*logFile != NULL)
1301 fclose(*logFile);
1302 *logFile = NULL;
1303 if (*last_file_name != NULL)
1306 return true;
1307 }
1308
1309 /*
1310 * Leave if it is not time for a rotation or if the target destination has
1311 * no need to do a rotation based on the size of its file.
1312 */
1314 return true;
1315
1316 /* file extension depends on the destination type */
1318 logFileExt = NULL;
1320 logFileExt = ".csv";
1322 logFileExt = ".json";
1323 else
1324 {
1325 /* cannot happen */
1326 Assert(false);
1327 }
1328
1329 /* build the new file name */
1331
1332 /*
1333 * Decide whether to overwrite or append. We can overwrite if (a)
1334 * Log_truncate_on_rotation is set, (b) the rotation was triggered by
1335 * elapsed time and not something else, and (c) the computed file name is
1336 * different from what we were previously logging into.
1337 */
1339 *last_file_name != NULL &&
1341 fh = logfile_open(filename, "w", true);
1342 else
1343 fh = logfile_open(filename, "a", true);
1344
1345 if (!fh)
1346 {
1347 /*
1348 * ENFILE/EMFILE are not too surprising on a busy system; just keep
1349 * using the old file till we manage to get a new one. Otherwise,
1350 * assume something's wrong with Log_directory and stop trying to
1351 * create files.
1352 */
1353 if (errno != ENFILE && errno != EMFILE)
1354 {
1355 ereport(LOG,
1356 (errmsg("disabling automatic rotation (use SIGHUP to re-enable)")));
1357 rotation_disabled = true;
1358 }
1359
1360 if (filename)
1361 pfree(filename);
1362 return false;
1363 }
1364
1365 /* fill in the new information */
1366 if (*logFile != NULL)
1367 fclose(*logFile);
1368 *logFile = fh;
1369
1370 /* instead of pfree'ing filename, remember it for next time */
1371 if (*last_file_name != NULL)
1374
1375 return true;
1376}
#define Assert(condition)
Definition c.h:943
int Log_destination
Definition elog.c:116
bool Log_truncate_on_rotation
Definition syslogger.c:76
static bool rotation_disabled
Definition syslogger.c:90
static char * logfile_getname(pg_time_t timestamp, const char *suffix)
Definition syslogger.c:1431
static FILE * logfile_open(const char *filename, const char *mode, bool allow_errors)
Definition syslogger.c:1238

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 898 of file syslogger.c.

899{
900 char *cursor = logbuffer;
901 int count = *bytes_in_logbuffer;
903
904 /* While we have enough for a header, process data... */
905 while (count >= (int) (offsetof(PipeProtoHeader, data) + 1))
906 {
908 int chunklen;
910
911 /* Do we have a valid header? */
916 if (p.nuls[0] == '\0' && p.nuls[1] == '\0' &&
917 p.len > 0 && p.len <= PIPE_MAX_PAYLOAD &&
918 p.pid != 0 &&
920 {
922 ListCell *cell;
924 *free_slot = NULL;
926
928
929 /* Fall out of loop if we don't have the whole chunk yet */
930 if (count < chunklen)
931 break;
932
933 if ((p.flags & PIPE_PROTO_DEST_STDERR) != 0)
935 else if ((p.flags & PIPE_PROTO_DEST_CSVLOG) != 0)
937 else if ((p.flags & PIPE_PROTO_DEST_JSONLOG) != 0)
939 else
940 {
941 /* this should never happen as of the header validation */
942 Assert(false);
943 }
944
945 /* Locate any existing buffer for this source pid */
947 foreach(cell, buffer_list)
948 {
949 save_buffer *buf = (save_buffer *) lfirst(cell);
950
951 if (buf->pid == p.pid)
952 {
954 break;
955 }
956 if (buf->pid == 0 && free_slot == NULL)
957 free_slot = buf;
958 }
959
960 if ((p.flags & PIPE_PROTO_IS_LAST) == 0)
961 {
962 /*
963 * Save a complete non-final chunk in a per-pid buffer
964 */
965 if (existing_slot != NULL)
966 {
967 /* Add chunk to data from preceding chunks */
968 str = &(existing_slot->data);
971 p.len);
972 }
973 else
974 {
975 /* First chunk of message, save in a new buffer */
976 if (free_slot == NULL)
977 {
978 /*
979 * Need a free slot, but there isn't one in the list,
980 * so create a new one and extend the list with it.
981 */
985 }
986 free_slot->pid = p.pid;
987 str = &(free_slot->data);
991 p.len);
992 }
993 }
994 else
995 {
996 /*
997 * Final chunk --- add it to anything saved for that pid, and
998 * either way write the whole thing out.
999 */
1000 if (existing_slot != NULL)
1001 {
1002 str = &(existing_slot->data);
1005 p.len);
1006 write_syslogger_file(str->data, str->len, dest);
1007 /* Mark the buffer unused, and reclaim string storage */
1008 existing_slot->pid = 0;
1009 pfree(str->data);
1010 }
1011 else
1012 {
1013 /* The whole message was one chunk, evidently. */
1015 dest);
1016 }
1017 }
1018
1019 /* Finished processing this chunk */
1020 cursor += chunklen;
1021 count -= chunklen;
1022 }
1023 else
1024 {
1025 /* Process non-protocol data */
1026
1027 /*
1028 * Look for the start of a protocol header. If found, dump data
1029 * up to there and repeat the loop. Otherwise, dump it all and
1030 * fall out of the loop. (Note: we want to dump it all if at all
1031 * possible, so as to avoid dividing non-protocol messages across
1032 * logfiles. We expect that in many scenarios, a non-protocol
1033 * message will arrive all in one read(), and we want to respect
1034 * the read() boundary if possible.)
1035 */
1036 for (chunklen = 1; chunklen < count; chunklen++)
1037 {
1038 if (cursor[chunklen] == '\0')
1039 break;
1040 }
1041 /* fall back on the stderr log as the destination */
1043 cursor += chunklen;
1044 count -= chunklen;
1045 }
1046 }
1047
1048 /* We don't have a full chunk, so left-align what remains in the buffer */
1049 if (count > 0 && cursor != logbuffer)
1050 memmove(logbuffer, cursor, count);
1051 *bytes_in_logbuffer = count;
1052}
uint8_t uint8
Definition c.h:622
memcpy(sums, checksumBaseOffsets, sizeof(checksumBaseOffsets))
#define palloc_object(type)
Definition fe_memutils.h:89
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:139
#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, memcpy(), 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 1607 of file syslogger.c.

1608{
1610}

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 1461 of file syslogger.c.

1462{
1463 pg_time_t now;
1464 struct pg_tm *tm;
1465 int rotinterval;
1466
1467 /* nothing to do if time-based rotation is disabled */
1468 if (Log_RotationAge <= 0)
1469 return;
1470
1471 /*
1472 * The requirements here are to choose the next time > now that is a
1473 * "multiple" of the log rotation interval. "Multiple" can be interpreted
1474 * fairly loosely. In this version we align to log_timezone rather than
1475 * GMT.
1476 */
1477 rotinterval = Log_RotationAge * SECS_PER_MINUTE; /* convert to seconds */
1478 now = (pg_time_t) time(NULL);
1480 now += tm->tm_gmtoff;
1481 now -= now % rotinterval;
1482 now += rotinterval;
1483 now -= tm->tm_gmtoff;
1485}
Datum now(PG_FUNCTION_ARGS)
Definition timestamp.c:1613
#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:72

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 1614 of file syslogger.c.

1615{
1616 rotation_requested = true;
1618}
struct Latch * MyLatch
Definition globals.c:65
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 612 of file syslogger.c.

613{
615 char *filename;
616#ifdef EXEC_BACKEND
618#endif /* EXEC_BACKEND */
619
621
622 /*
623 * If first time through, create the pipe which will receive stderr
624 * output.
625 *
626 * If the syslogger crashes and needs to be restarted, we continue to use
627 * the same pipe (indeed must do so, since extant backends will be writing
628 * into that pipe).
629 *
630 * This means the postmaster must continue to hold the read end of the
631 * pipe open, so we can pass it down to the reincarnated syslogger. This
632 * is a bit klugy but we have little choice.
633 *
634 * Also note that we don't bother counting the pipe FDs by calling
635 * Reserve/ReleaseExternalFD. There's no real need to account for them
636 * accurately in the postmaster or syslogger process, and both ends of the
637 * pipe will wind up closed in all other postmaster children.
638 */
639#ifndef WIN32
640 if (syslogPipe[0] < 0)
641 {
642 if (pipe(syslogPipe) < 0)
645 errmsg("could not create pipe for syslog: %m")));
646 }
647#else
648 if (!syslogPipe[0])
649 {
651
652 memset(&sa, 0, sizeof(SECURITY_ATTRIBUTES));
653 sa.nLength = sizeof(SECURITY_ATTRIBUTES);
654 sa.bInheritHandle = TRUE;
655
656 if (!CreatePipe(&syslogPipe[0], &syslogPipe[1], &sa, 32768))
659 errmsg("could not create pipe for syslog: %m")));
660 }
661#endif
662
663 /*
664 * Create log directory if not present; ignore errors
665 */
667
668 /*
669 * The initial logfile is created right in the postmaster, to verify that
670 * the Log_directory is writable. We save the reference time so that the
671 * syslogger child process can recompute this file name.
672 *
673 * It might look a bit strange to re-do this during a syslogger restart,
674 * but we must do so since the postmaster closed syslogFile after the
675 * previous fork (and remembering that old file wouldn't be right anyway).
676 * Note we always append here, we won't overwrite any existing file. This
677 * is consistent with the normal rules, because by definition this is not
678 * a time-based rotation.
679 */
681
683
684 syslogFile = logfile_open(filename, "a", false);
685
687
688 /*
689 * Likewise for the initial CSV log file, if that's enabled. (Note that
690 * we open syslogFile even when only CSV output is nominally enabled,
691 * since some code paths will write to syslogFile anyway.)
692 */
694 {
696
697 csvlogFile = logfile_open(filename, "a", false);
698
700 }
701
702 /*
703 * Likewise for the initial JSON log file, if that's enabled. (Note that
704 * we open syslogFile even when only JSON output is nominally enabled,
705 * since some code paths will write to syslogFile anyway.)
706 */
708 {
710
711 jsonlogFile = logfile_open(filename, "a", false);
712
714 }
715
716#ifdef EXEC_BACKEND
721 &startup_data, sizeof(startup_data), NULL);
722#else
724 NULL, 0, NULL);
725#endif /* EXEC_BACKEND */
726
727 if (sysloggerPid == -1)
728 {
729 ereport(LOG,
730 (errmsg("could not fork system logger: %m")));
731 return 0;
732 }
733
734 /* success, in postmaster */
735
736 /* now we redirect stderr, if not done already */
737 if (!redirection_done)
738 {
739#ifdef WIN32
740 int fd;
741#endif
742
743 /*
744 * Leave a breadcrumb trail when redirecting, in case the user forgets
745 * that redirection is active and looks only at the original stderr
746 * target file.
747 */
748 ereport(LOG,
749 (errmsg("redirecting log output to logging collector process"),
750 errhint("Future log output will appear in directory \"%s\".",
751 Log_directory)));
752
753#ifndef WIN32
754 fflush(stdout);
755 if (dup2(syslogPipe[1], STDOUT_FILENO) < 0)
758 errmsg("could not redirect stdout: %m")));
759 fflush(stderr);
760 if (dup2(syslogPipe[1], STDERR_FILENO) < 0)
763 errmsg("could not redirect stderr: %m")));
764 /* Now we are done with the write end of the pipe. */
765 close(syslogPipe[1]);
766 syslogPipe[1] = -1;
767#else
768
769 /*
770 * open the pipe in binary mode and make sure stderr is binary after
771 * it's been dup'ed into, to avoid disturbing the pipe chunking
772 * protocol.
773 */
774 fflush(stderr);
777 if (dup2(fd, STDERR_FILENO) < 0)
780 errmsg("could not redirect stderr: %m")));
781 close(fd);
783
784 /*
785 * Now we are done with the write end of the pipe. CloseHandle() must
786 * not be called because the preceding close() closes the underlying
787 * handle.
788 */
789 syslogPipe[1] = 0;
790#endif
791 redirection_done = true;
792 }
793
794 /* postmaster will never write the file(s); close 'em */
797 if (csvlogFile != NULL)
798 {
801 }
802 if (jsonlogFile != NULL)
803 {
806 }
807 return (int) sysloggerPid;
808}
int errcode_for_socket_access(void)
Definition elog.c:977
int errhint(const char *fmt,...) pg_attribute_printf(1
int MakePGDirectory(const char *directoryName)
Definition fd.c:3963
#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, const ClientSocket *client_sock)
@ B_LOGGER
Definition miscadmin.h:380
bool redirection_done
Definition postmaster.c:377
static int fd(const char *x, int i)
NON_EXEC_STATIC pg_time_t first_syslogger_file_time
Definition syslogger.c:94
int syslogPipe[2]
Definition syslogger.c:121
bool Logging_collector
Definition syslogger.c:71
#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 172 of file syslogger.c.

173{
174#ifndef WIN32
176 int bytes_in_logbuffer = 0;
177#endif
178 char *currentLogDir;
179 char *currentLogFilename;
183
184#ifndef EXEC_BACKEND
185
186 /*
187 * In !EXEC_BACKEND, syslogger is immediately ready to take over: the
188 * output files were already opened by postmaster before forking. For the
189 * other case we must wait until the file descriptors have been restored,
190 * below.
191 */
193#endif
194
195 /*
196 * Re-open the error output files that were opened by SysLogger_Start().
197 *
198 * We expect this will always succeed, which is too optimistic, but if it
199 * fails there's not a lot we can do to report the problem anyway. As
200 * coded, we'll just crash on a null pointer dereference after failure...
201 */
202#ifdef EXEC_BACKEND
203 {
205
206 Assert(startup_data_len == sizeof(*slsdata));
207 syslogFile = syslogger_fdopen(slsdata->syslogFile);
208 csvlogFile = syslogger_fdopen(slsdata->csvlogFile);
209 jsonlogFile = syslogger_fdopen(slsdata->jsonlogFile);
210
212 }
213#else
215#endif
216
217 /*
218 * Now that we're done reading the startup data, release postmaster's
219 * working memory context.
220 */
222 {
225 }
226
228
230
231 /*
232 * If we restarted, our stderr is already redirected into our own input
233 * pipe. This is of course pretty useless, not to mention that it
234 * interferes with detecting pipe EOF. Point stderr to /dev/null. This
235 * assumes that all interesting messages generated in the syslogger will
236 * come through elog.c and will be sent to write_syslogger_file.
237 */
239 {
240 int fd = open(DEVNULL, O_WRONLY, 0);
241
242 /*
243 * The closes might look redundant, but they are not: we want to be
244 * darn sure the pipe gets closed even if the open failed. We can
245 * survive running with stderr pointing nowhere, but we can't afford
246 * to have extra pipe input descriptors hanging around.
247 *
248 * As we're just trying to reset these to go to DEVNULL, there's not
249 * much point in checking for failure from the close/dup2 calls here,
250 * if they fail then presumably the file descriptors are closed and
251 * any writes will go into the bitbucket anyway.
252 */
255 if (fd != -1)
256 {
259 close(fd);
260 }
261 }
262
263 /*
264 * Syslogger's own stderr can't be the syslogPipe, so set it back to text
265 * mode if we didn't just close it. (It was set to binary in
266 * SubPostmasterMain).
267 */
268#ifdef WIN32
269 else
271#endif
272
273 /*
274 * Also close our copy of the write end of the pipe. This is needed to
275 * ensure we can detect pipe EOF correctly. (But note that in the restart
276 * case, the postmaster already did this.)
277 */
278#ifndef WIN32
279 if (syslogPipe[1] >= 0)
280 close(syslogPipe[1]);
281 syslogPipe[1] = -1;
282#else
283 if (syslogPipe[1])
285 syslogPipe[1] = 0;
286#endif
287
288 /*
289 * Properly accept or ignore signals the postmaster might send us
290 *
291 * Note: we ignore all termination signals, and instead exit only when all
292 * upstream processes are gone, to ensure we don't miss any dying gasps of
293 * broken backends...
294 */
295
296 pqsignal(SIGHUP, SignalHandlerForConfigReload); /* set flag to read config
297 * file */
303 pqsignal(SIGUSR1, sigUsr1Handler); /* request log rotation */
305
306 /*
307 * Reset some signals that are accepted by postmaster but not here
308 */
310
312
313#ifdef WIN32
314 /* Fire up separate data transfer thread */
317
319 if (threadHandle == 0)
320 elog(FATAL, "could not create syslogger data transfer thread: %m");
321#endif /* WIN32 */
322
323 /*
324 * Remember active logfiles' name(s). We recompute 'em from the reference
325 * time because passing down just the pg_time_t is a lot cheaper than
326 * passing a whole file path in the EXEC_BACKEND case.
327 */
329 if (csvlogFile != NULL)
331 if (jsonlogFile != NULL)
333
334 /* remember active logfile parameters */
338 /* set next planned rotation time */
341
342 /*
343 * Reset whereToSendOutput, as the postmaster will do (but hasn't yet, at
344 * the point where we forked). This prevents duplicate output of messages
345 * from syslogger itself.
346 */
348
349 /*
350 * Set up a reusable WaitEventSet object we'll use to wait for our latch,
351 * and (except on Windows) our socket.
352 *
353 * Unlike all other postmaster child processes, we'll ignore postmaster
354 * death because we want to collect final log output from all backends and
355 * then exit last. We'll do that by running until we see EOF on the
356 * syslog pipe, which implies that all other backends have exited
357 * (including the postmaster).
358 */
361#ifndef WIN32
363#endif
364
365 /* main worker loop */
366 for (;;)
367 {
368 bool time_based_rotation = false;
369 int size_rotation_for = 0;
370 long cur_timeout;
371 WaitEvent event;
372
373#ifndef WIN32
374 int rc;
375#endif
376
377 /* Clear any already-pending wakeups */
379
380 /*
381 * Process any requests or signals received recently.
382 */
384 {
385 ConfigReloadPending = false;
387
388 /*
389 * Check if the log directory or filename pattern changed in
390 * postgresql.conf. If so, force rotation to make sure we're
391 * writing the logfiles in the right place.
392 */
394 {
397 rotation_requested = true;
398
399 /*
400 * Also, create new directory if not present; ignore errors
401 */
403 }
405 {
408 rotation_requested = true;
409 }
410
411 /*
412 * Force a rotation if CSVLOG output was just turned on or off and
413 * we need to open or close csvlogFile accordingly.
414 */
416 (csvlogFile != NULL))
417 rotation_requested = true;
418
419 /*
420 * Force a rotation if JSONLOG output was just turned on or off
421 * and we need to open or close jsonlogFile accordingly.
422 */
424 (jsonlogFile != NULL))
425 rotation_requested = true;
426
427 /*
428 * If rotation time parameter changed, reset next rotation time,
429 * but don't immediately force a rotation.
430 */
432 {
435 }
436
437 /*
438 * If we had a rotation-disabling failure, re-enable rotation
439 * attempts after SIGHUP, and force one immediately.
440 */
442 {
443 rotation_disabled = false;
444 rotation_requested = true;
445 }
446
447 /*
448 * Force rewriting last log filename when reloading configuration.
449 * Even if rotation_requested is false, log_destination may have
450 * been changed and we don't want to wait the next file rotation.
451 */
453 }
454
456 {
457 /* Do a logfile rotation if it's time */
458 now = (pg_time_t) time(NULL);
459 if (now >= next_rotation_time)
461 }
462
464 {
465 /* Do a rotation if file is too big */
466 if (ftello(syslogFile) >= Log_RotationSize * (pgoff_t) 1024)
467 {
468 rotation_requested = true;
470 }
471 if (csvlogFile != NULL &&
473 {
474 rotation_requested = true;
476 }
477 if (jsonlogFile != NULL &&
479 {
480 rotation_requested = true;
482 }
483 }
484
486 {
487 /*
488 * Force rotation when both values are zero. It means the request
489 * was sent by pg_rotate_logfile() or "pg_ctl logrotate".
490 */
496 }
497
498 /*
499 * Calculate time till next time-based rotation, so that we don't
500 * sleep longer than that. We assume the value of "now" obtained
501 * above is still close enough. Note we can't make this calculation
502 * until after calling logfile_rotate(), since it will advance
503 * next_rotation_time.
504 *
505 * Also note that we need to beware of overflow in calculation of the
506 * timeout: with large settings of Log_RotationAge, next_rotation_time
507 * could be more than INT_MAX msec in the future. In that case we'll
508 * wait no more than INT_MAX msec, and try again.
509 */
511 {
513
515 if (delay > 0)
516 {
517 if (delay > INT_MAX / 1000)
518 delay = INT_MAX / 1000;
519 cur_timeout = delay * 1000L; /* msec */
520 }
521 else
522 cur_timeout = 0;
523 }
524 else
525 cur_timeout = -1L;
526
527 /*
528 * Sleep until there's something to do
529 */
530#ifndef WIN32
531 rc = WaitEventSetWait(wes, cur_timeout, &event, 1,
533
534 if (rc == 1 && event.events == WL_SOCKET_READABLE)
535 {
536 int bytesRead;
537
540 sizeof(logbuffer) - bytes_in_logbuffer);
541 if (bytesRead < 0)
542 {
543 if (errno != EINTR)
544 ereport(LOG,
546 errmsg("could not read from logger pipe: %m")));
547 }
548 else if (bytesRead > 0)
549 {
552 continue;
553 }
554 else
555 {
556 /*
557 * Zero bytes read when select() is saying read-ready means
558 * EOF on the pipe: that is, there are no longer any processes
559 * with the pipe write end open. Therefore, the postmaster
560 * and all backends are shut down, and we are done.
561 */
562 pipe_eof_seen = true;
563
564 /* if there's any data left then force it out now */
566 }
567 }
568#else /* WIN32 */
569
570 /*
571 * On Windows we leave it to a separate thread to transfer data and
572 * detect pipe EOF. The main thread just wakes up to handle SIGHUP
573 * and rotation conditions.
574 *
575 * Server code isn't generally thread-safe, so we ensure that only one
576 * of the threads is active at a time by entering the critical section
577 * whenever we're not sleeping.
578 */
580
581 (void) WaitEventSetWait(wes, cur_timeout, &event, 1,
583
585#endif /* WIN32 */
586
587 if (pipe_eof_seen)
588 {
589 /*
590 * seeing this message on the real stderr is annoying - so we make
591 * it DEBUG1 to suppress in normal use.
592 */
594 (errmsg_internal("logger shutting down")));
595
596 /*
597 * Normal exit from the syslogger is here. Note that we
598 * deliberately do not close syslogFile before exiting; this is to
599 * allow for the possibility of elog messages being generated
600 * inside proc_exit. Regular exit() will take care of flushing
601 * and closing stdio channels.
602 */
603 proc_exit(0);
604 }
605 }
606}
sigset_t UnBlockSig
Definition pqsignal.c:22
@ DestNone
Definition dest.h:87
int int errmsg_internal(const char *fmt,...) pg_attribute_printf(1
#define DEBUG1
Definition elog.h:31
#define elog(elevel,...)
Definition elog.h:228
pg_time_t MyStartTime
Definition globals.c:50
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:1910
MemoryContext PostmasterContext
Definition mcxt.c:169
void MemoryContextDelete(MemoryContext context)
Definition mcxt.c:475
#define pqsignal
Definition port.h:548
#define PG_SIG_IGN
Definition port.h:552
#define DEVNULL
Definition port.h:162
#define PGINVALID_SOCKET
Definition port.h:31
#define PG_SIG_DFL
Definition port.h:551
off_t pgoff_t
Definition port.h:422
CommandDest whereToSendOutput
Definition postgres.c:97
void init_ps_display(const char *fixed_part)
Definition ps_status.c:286
uint32 events
static void logfile_rotate(bool time_based_rotation, int size_rotation_for)
Definition syslogger.c:1382
static bool pipe_eof_seen
Definition syslogger.c:89
#define READ_BUF_SIZE
Definition syslogger.c:61
static void process_pipe_input(char *logbuffer, int *bytes_in_logbuffer)
Definition syslogger.c:898
bool syslogger_setup_done
Definition syslogger.c:83
int Log_RotationSize
Definition syslogger.c:73
static void sigUsr1Handler(SIGNAL_ARGS)
Definition syslogger.c:1614
static void flush_pipe_input(char *logbuffer, int *bytes_in_logbuffer)
Definition syslogger.c:1061
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(), PG_SIG_DFL, PG_SIG_IGN, 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, syslogger_setup_done, 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 1496 of file syslogger.c.

1497{
1498 FILE *fh;
1499 mode_t oumask;
1500
1504 {
1506 ereport(LOG,
1508 errmsg("could not remove file \"%s\": %m",
1510 return;
1511 }
1512
1513 /* use the same permissions as the data directory for the new file */
1516 umask(oumask);
1517
1518 if (fh)
1519 {
1520 setvbuf(fh, NULL, PG_IOLBF, 0);
1521
1522#ifdef WIN32
1523 /* use CRLF line endings on Windows */
1525#endif
1526 }
1527 else
1528 {
1529 ereport(LOG,
1531 errmsg("could not open file \"%s\": %m",
1533 return;
1534 }
1535
1537 {
1538 if (fprintf(fh, "stderr %s\n", last_sys_file_name) < 0)
1539 {
1540 ereport(LOG,
1542 errmsg("could not write file \"%s\": %m",
1544 fclose(fh);
1545 return;
1546 }
1547 }
1548
1550 {
1551 if (fprintf(fh, "csvlog %s\n", last_csv_file_name) < 0)
1552 {
1553 ereport(LOG,
1555 errmsg("could not write file \"%s\": %m",
1557 fclose(fh);
1558 return;
1559 }
1560 }
1561
1563 {
1564 if (fprintf(fh, "jsonlog %s\n", last_json_file_name) < 0)
1565 {
1566 ereport(LOG,
1568 errmsg("could not write file \"%s\": %m",
1570 fclose(fh);
1571 return;
1572 }
1573 }
1574 fclose(fh);
1575
1577 ereport(LOG,
1579 errmsg("could not rename file \"%s\" to \"%s\": %m",
1581}
#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:104
#define LOG_METAINFO_DATAFILE
Definition syslogger.h:103

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 1112 of file syslogger.c.

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

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 117 of file syslogger.c.

Referenced by flush_pipe_input(), and process_pipe_input().

◆ csvlogFile

FILE* csvlogFile = NULL
static

Definition at line 92 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 94 of file syslogger.c.

Referenced by SysLogger_Start(), and SysLoggerMain().

◆ jsonlogFile

FILE* jsonlogFile = NULL
static

Definition at line 93 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 96 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 97 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 95 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 77 of file syslogger.c.

Referenced by logfile_open(), and show_log_file_mode().

◆ Log_filename

char* Log_filename = NULL

Definition at line 75 of file syslogger.c.

Referenced by logfile_getname(), and SysLoggerMain().

◆ Log_RotationAge

int Log_RotationAge = HOURS_PER_DAY * MINS_PER_HOUR

Definition at line 72 of file syslogger.c.

Referenced by set_next_rotation_time(), and SysLoggerMain().

◆ Log_RotationSize

int Log_RotationSize = 10 * 1024

Definition at line 73 of file syslogger.c.

Referenced by SysLoggerMain().

◆ Log_truncate_on_rotation

bool Log_truncate_on_rotation = false

Definition at line 76 of file syslogger.c.

Referenced by logfile_rotate_dest().

◆ Logging_collector

◆ next_rotation_time

pg_time_t next_rotation_time
static

Definition at line 88 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 89 of file syslogger.c.

Referenced by SysLoggerMain().

◆ rotation_disabled

bool rotation_disabled = false
static

Definition at line 90 of file syslogger.c.

Referenced by logfile_rotate_dest(), and SysLoggerMain().

◆ rotation_requested

volatile sig_atomic_t rotation_requested = false
static

Definition at line 134 of file syslogger.c.

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

◆ syslogFile

FILE* syslogFile = NULL
static

Definition at line 91 of file syslogger.c.

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

◆ syslogger_setup_done

bool syslogger_setup_done = false

Definition at line 83 of file syslogger.c.

Referenced by send_message_to_server_log(), SysLoggerMain(), write_csvlog(), and write_jsonlog().

◆ syslogPipe

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

Definition at line 121 of file syslogger.c.

121{-1, -1};

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