PostgreSQL Source Code git master
syslogger.h
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * syslogger.h
4 * Exports from postmaster/syslogger.c.
5 *
6 * Copyright (c) 2004-2025, PostgreSQL Global Development Group
7 *
8 * src/include/postmaster/syslogger.h
9 *
10 *-------------------------------------------------------------------------
11 */
12#ifndef _SYSLOGGER_H
13#define _SYSLOGGER_H
14
15#include <limits.h> /* for PIPE_BUF */
16
17
18/*
19 * Primitive protocol structure for writing to syslogger pipe(s). The idea
20 * here is to divide long messages into chunks that are not more than
21 * PIPE_BUF bytes long, which according to POSIX spec must be written into
22 * the pipe atomically. The pipe reader then uses the protocol headers to
23 * reassemble the parts of a message into a single string. The reader can
24 * also cope with non-protocol data coming down the pipe, though we cannot
25 * guarantee long strings won't get split apart.
26 *
27 * We use non-nul bytes in is_last to make the protocol a tiny bit
28 * more robust against finding a false double nul byte prologue. But
29 * we still might find it in the len and/or pid bytes unless we're careful.
30 */
31
32#ifdef PIPE_BUF
33/* Are there any systems with PIPE_BUF > 64K? Unlikely, but ... */
34#if PIPE_BUF > 65536
35#define PIPE_CHUNK_SIZE 65536
36#else
37#define PIPE_CHUNK_SIZE ((int) PIPE_BUF)
38#endif
39#else /* not defined */
40/* POSIX says the value of PIPE_BUF must be at least 512, so use that */
41#define PIPE_CHUNK_SIZE 512
42#endif
43
44typedef struct
45{
46 char nuls[2]; /* always \0\0 */
47 uint16 len; /* size of this chunk (counts data only) */
48 int32 pid; /* writer's pid */
49 bits8 flags; /* bitmask of PIPE_PROTO_* */
50 char data[FLEXIBLE_ARRAY_MEMBER]; /* data payload starts here */
52
53typedef union
54{
56 char filler[PIPE_CHUNK_SIZE];
58
59#define PIPE_HEADER_SIZE offsetof(PipeProtoHeader, data)
60#define PIPE_MAX_PAYLOAD ((int) (PIPE_CHUNK_SIZE - PIPE_HEADER_SIZE))
61
62/* flag bits for PipeProtoHeader->flags */
63#define PIPE_PROTO_IS_LAST 0x01 /* last chunk of message? */
64/* log destinations */
65#define PIPE_PROTO_DEST_STDERR 0x10
66#define PIPE_PROTO_DEST_CSVLOG 0x20
67#define PIPE_PROTO_DEST_JSONLOG 0x40
68
69/* GUC options */
73extern PGDLLIMPORT char *Log_directory;
74extern PGDLLIMPORT char *Log_filename;
76extern PGDLLIMPORT int Log_file_mode;
77
78#ifdef EXEC_BACKEND
80#endif
81
82#ifndef WIN32
83extern PGDLLIMPORT int syslogPipe[2];
84#else
85extern PGDLLIMPORT HANDLE syslogPipe[2];
86#endif
87
88
89extern int SysLogger_Start(int child_slot);
90
91extern void write_syslogger_file(const char *buffer, int count, int destination);
92
93pg_noreturn extern void SysLoggerMain(const void *startup_data, size_t startup_data_len);
94
95extern bool CheckLogrotateSignal(void);
96extern void RemoveLogrotateSignalFiles(void);
97
98/*
99 * Name of files saving meta-data information about the log
100 * files currently in use by the syslogger
101 */
102#define LOG_METAINFO_DATAFILE "current_logfiles"
103#define LOG_METAINFO_DATAFILE_TMP LOG_METAINFO_DATAFILE ".tmp"
104
105#endif /* _SYSLOGGER_H */
#define PGDLLIMPORT
Definition: c.h:1291
#define pg_noreturn
Definition: c.h:165
#define FLEXIBLE_ARRAY_MEMBER
Definition: c.h:434
uint8 bits8
Definition: c.h:509
int32_t int32
Definition: c.h:498
uint16_t uint16
Definition: c.h:501
const void * data
int64 pg_time_t
Definition: pgtime.h:23
NON_EXEC_STATIC pg_time_t first_syslogger_file_time
Definition: syslogger.c:87
PGDLLIMPORT int Log_file_mode
Definition: syslogger.c:76
PGDLLIMPORT bool Logging_collector
Definition: syslogger.c:70
PGDLLIMPORT int Log_RotationAge
Definition: syslogger.c:71
pg_noreturn void SysLoggerMain(const void *startup_data, size_t startup_data_len)
Definition: syslogger.c:165
bool CheckLogrotateSignal(void)
Definition: syslogger.c:1574
PGDLLIMPORT char * Log_filename
Definition: syslogger.c:74
PGDLLIMPORT int Log_RotationSize
Definition: syslogger.c:72
PGDLLIMPORT int syslogPipe[2]
Definition: syslogger.c:114
#define PIPE_CHUNK_SIZE
Definition: syslogger.h:41
void RemoveLogrotateSignalFiles(void)
Definition: syslogger.c:1588
void write_syslogger_file(const char *buffer, int count, int destination)
Definition: syslogger.c:1093
PGDLLIMPORT bool Log_truncate_on_rotation
Definition: syslogger.c:75
PGDLLIMPORT char * Log_directory
Definition: syslogger.c:73
int SysLogger_Start(int child_slot)
Definition: syslogger.c:593
PipeProtoHeader proto
Definition: syslogger.h:55