-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpgx_warnings.h
More file actions
63 lines (54 loc) · 2.11 KB
/
Copy pathpgx_warnings.h
File metadata and controls
63 lines (54 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*-------------------------------------------------------------------------
*
* pgx_warnings.h
* Public constants, data structures, and function prototypes for
* the pgx_warnings PostgreSQL extension.
*
* Copyright (c) 2026, Valeh Agayev and pgx_warnings contributors
* Licensed under the PostgreSQL License.
*
*-------------------------------------------------------------------------
*/
#ifndef PGX_WARNINGS_H
#define PGX_WARNINGS_H
#include "postgres.h"
#include "storage/lwlock.h"
#include "utils/timestamp.h"
/* ========================= Constants ========================= */
#define PGX_MAX_MSG_LEN 1024
#define PGX_RING_SIZE 2048
#define PGX_URL_LEN 512
#define PGX_CHATID_LEN 128
#define PGX_HOSTNAME_LEN 128
#define PGX_DB_NAME_LEN 128
#define PGX_TELEGRAM_BUF_LEN (PGX_MAX_MSG_LEN + 512)
/* ========================= Data Structures ========================= */
typedef struct pgxLogEntry
{
TimestampTz ts;
int elevel;
int pid;
char database[PGX_DB_NAME_LEN];
char message[PGX_MAX_MSG_LEN];
bool sent;
} pgxLogEntry;
typedef struct pgxSharedState
{
LWLock *lock;
int head; /* next write slot (wraps via modulo) */
int total_count; /* number of valid entries in buffer */
int unsent_idx; /* ring index of next entry to send */
int64 total_captured; /* lifetime captured count */
int64 total_sent; /* lifetime sent count */
int64 total_failed; /* lifetime send failure count */
pgxLogEntry entries[PGX_RING_SIZE];
} pgxSharedState;
/* ========================= Function Prototypes ========================= */
void _PG_init(void);
PGDLLEXPORT void pgx_warnings_main(Datum main_arg) pg_attribute_noreturn();
/* SQL-callable functions */
extern Datum pgx_warnings_stats(PG_FUNCTION_ARGS);
extern Datum pgx_warnings_list(PG_FUNCTION_ARGS);
extern Datum pgx_warnings_clear(PG_FUNCTION_ARGS);
extern Datum pgx_warnings_test(PG_FUNCTION_ARGS);
#endif /* PGX_WARNINGS_H */