First PostgreSQL Contributor Gift


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.

pg16 contrib gift front

Problem

It all starts with a problem. So while working on my first PostgreSQL extension, supautils (blog post), I needed to define a custom parameter.

For this, I needed the DefineCustomStringVariable function, which has the following signature:

void DefineCustomStringVariable( const char *name, const char *short_desc, 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, NULL, // problem here &placeholders, NULL, PGC_SIGHUP, 0, placeholders_check_hook, NULL, NULL);

I thought it would be so safe to leave the short_desc (which would obviously mean a "short description") as NULL. But turns out it didn't...

Crash

SHOW ALL relied on the 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));

Solution

The obvious solution 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).

In the end though, after some discussion, the pg hackers were open about fixing the issue. 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).

Getting the Gift

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.

email gift

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!