Thread: pg_settings.unit and DefineCustomXXXVariable
Hi all, I need to define a few GUCs, and for that purpose I'm using DefineCustomXXXVariable functions that provide hooks for assignment, show and check. However it is not clear to me if it is possible to populate the unit column in pg_settings for the custom defined variables, and if so, how. Any suggestion is appreciated. Thanks, Luca
On Wed, 8 Jan 2025 at 11:13, Luca Ferrari <fluca1978@gmail.com> wrote: > > Hi all, > I need to define a few GUCs, and for that purpose I'm using > DefineCustomXXXVariable functions that provide hooks for assignment, > show and check. However it is not clear to me if it is possible to > populate the unit column in pg_settings for the custom defined > variables, and if so, how. DefineCustomXXXVariable has a 'flags' argument, into which GUC_UNIT_* can be or-ed. AFAIK, the options provided in guc.h are the only kinds of units supported and available, and I think only integer variables actually support the unit conversion implied by the unit options. Kind regards, Matthias van de Meent
Matthias van de Meent <boekewurm+postgres@gmail.com> writes: > On Wed, 8 Jan 2025 at 11:13, Luca Ferrari <fluca1978@gmail.com> wrote: >> I need to define a few GUCs, and for that purpose I'm using >> DefineCustomXXXVariable functions that provide hooks for assignment, >> show and check. However it is not clear to me if it is possible to >> populate the unit column in pg_settings for the custom defined >> variables, and if so, how. > DefineCustomXXXVariable has a 'flags' argument, into which GUC_UNIT_* > can be or-ed. Correct. contrib/auto_explain has some examples. > AFAIK, the options provided in guc.h are the only kinds of units > supported and available, and I think only integer variables actually > support the unit conversion implied by the unit options. Nowadays we allow units for float GUCs as well. (Originally it was indeed just for integers. But at some point we decided an existing integer value with units needed to become float, and then we had to back-fill the implementation for compatibility's sake.) regards, tom lane
On Wed, Jan 8, 2025 at 4:18 PM Tom Lane <tgl@sss.pgh.pa.us> wrote: > > Matthias van de Meent <boekewurm+postgres@gmail.com> writes: > > DefineCustomXXXVariable has a 'flags' argument, into which GUC_UNIT_* > > can be or-ed. Thanks Matthias and Tom for the explaination. Since I'm needing to define "seconds", GUC_UNIT_S is what I was looking for. Luca