From fa8f6478c3cecf4c92253137166f62582e45a892 Mon Sep 17 00:00:00 2001 From: "Andrei V. Lepikhov" Date: Mon, 6 Jul 2026 10:26:21 +0200 Subject: [PATCH] Port snowflake to PostgreSQL 19 PG19 commit a87987cafca ("Move WAL sequence code into its own file") split the sequence WAL definitions out of commands/sequence.h into a new commands/sequence_xlog.h. Include that header on PG19+ so SEQ_MAGIC, sequence_magic, xl_seq_rec and XLOG_SEQ_LOG keep resolving, and guard the module's local SEQ_MAGIC/sequence_magic definitions behind the pre-19 version check to avoid duplicate definitions. Also add an explicit include for clock_gettime()/struct timespec. On PG <=18 was pulled in transitively through the backend header chain, but PG19 header-dependency cleanups (the instr_time.h TSC rework and removal of the clock_gettime configure probe) pruned that path, so without the include PG19 fails with "call to undeclared function 'clock_gettime'". Following the "include what you use" rule, add it directly; it is harmless on all supported branches. Co-Authored-By: Claude Opus 4.8 (1M context) --- snowflake.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/snowflake.c b/snowflake.c index 483aa3c..c90f5b5 100644 --- a/snowflake.c +++ b/snowflake.c @@ -16,6 +16,8 @@ #include "postgres.h" +#include + #include "access/bufmask.h" #include "access/htup_details.h" #include "access/multixact.h" @@ -35,6 +37,9 @@ #include "catalog/storage_xlog.h" #include "commands/defrem.h" #include "commands/sequence.h" +#if PG_VERSION_NUM >= 190000 +#include "commands/sequence_xlog.h" +#endif #include "commands/tablecmds.h" #include "funcapi.h" #include "miscadmin.h" @@ -61,6 +66,7 @@ PG_MODULE_MAGIC; */ #define SEQ_LOG_VALS 32 +#if PG_VERSION_NUM < 190000 /* * The "special area" of a sequence's buffer page looks like this. */ @@ -70,6 +76,7 @@ typedef struct sequence_magic { uint32 magic; } sequence_magic; +#endif /* * We store a SeqTable item for every sequence we have touched in the current @@ -186,7 +193,6 @@ snowflake_nextval(PG_FUNCTION_ARGS) ereport(ERROR, (errcode(ERRCODE_CONFIG_FILE_ERROR), errmsg("value for snowflake.node is not set"))); - /* open and lock sequence */ init_sequence(relid, &elm, &seqrel);