Just got my first PostgreSQL Contributor Gift! I was so surprised to be included in the PostgreSQL 15 acknowledgements after such a small contribution.
In this post, I'll share how I got it.
It all starts with a problem. While working on my first PostgreSQL extension, supautils (Supabase blog post), I needed to define a custom parameter.
For this, I used the DefineCustomStringVariable
function, which has the following signature:
void DefineCustomStringVariable(
const char *name,
const char *long_desc,
char **valueAddr,
const char *bootValue,
GucContext context,
int flags,
GucStringCheckHook check_hook,
GucStringAssignHook assign_hook,
GucShowHook show_hook);
And I used it like this:
DefineCustomStringVariable("supautils.placeholders",
NULL,
&placeholders,
NULL,
PGC_SIGHUP, 0,
placeholders_check_hook,
NULL,
NULL);
I thought it would be safe to leave the short_desc
("short description") as NULL. But turns out it didn't...
SHOW ALL relied on non-NULL short descriptions. When trying to use it with supautils
installed, it crashed:
postgres# SHOW ALL
The connection to the server was lost. Attempting reset: 2022-04-14 08:53:08.280 -05 [63034] LOG: server process (PID 63047) was terminated by signal 11: Segmentation fault
2022-04-14 08:53:08.280 -05 [63034] DETAIL: Failed process was running: show all;
2022-04-14 08:53:08.280 -05 [63034] LOG: terminating any other active server processes
2022-04-14 08:53:08.280 -05 [63039] WARNING: terminating connection because of crash of another server process
2022-04-14 08:53:08.280 -05 [63039] DETAIL: The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally an
d possibly corrupted shared memory.
2022-04-14 08:53:08.280 -05 [63039] HINT: In a moment you should be able to reconnect to the database and repeat your command.
2022-04-14 08:53:08.280 -05 [63050] FATAL: the database system is in recovery mode
Failed.
!?> 2022-04-14 08:53:08.280 -05 [63034] LOG: all server processes terminated; reinitializing
2022-04-14 08:53:08.286 -05 [63051] LOG: database system was interrupted; last known up at 2022-04-14 08:53:06 -05
2022-04-14 08:53:08.286 -05 [63051] LOG: database system was not properly shut down; automatic recovery in progress
2022-04-14 08:53:08.287 -05 [63051] LOG: redo starts at 0/16475C0
2022-04-14 08:53:08.287 -05 [63051] LOG: invalid record length at 0/1663818: wanted 24, got 0
2022-04-14 08:53:08.287 -05 [63051] LOG: redo done at 0/16636D0
2022-04-14 08:53:08.289 -05 [63034] LOG: database system is ready to accept connections
Underlyingly, SHOW ALL
used the ShowAllGUCConfig
function, which in turn relied on the non-NULL short_desc
here.
values[2] = PointerGetDatum(cstring_to_text(conf->short_desc));
The obvious fix would have been to add a guard conditional. However, being my first contribution, I thought it wouldn't be that simple to add code to PostgreSQL.
So I thought an assertion would be the simplest patch to accept and I started by sending that (email thread).
This would at least give an error when building postgres with --enable-cassert
.
Although, after some discussion, the pg hackers were open about just adding the fix. Which resulted in me adding this impressive (sarcasm) if/else conditional:
if (conf->short_desc)
{
values[2] = PointerGetDatum(cstring_to_text(conf->short_desc));
snull[2] = false;
}
else
{
values[2] = PointerGetDatum(NULL);
snull[2] = true;
}
Which is now included into the PostgreSQL codebase! (commit).
Later on, I was contacted by the pg team to send me the gift. I was of course pleased to send them my mailing address.
One other thing that was impressive to me. Some time later I read Mark Wong's blog post about Acknowledged Individuals in the PostgreSQL Release Notes. This shows a chart of the contributors gifts by country and now you can see Peru (my country) in it!