Re: Global flag - Mailing list pgsql-hackers

From Jeff Janes
Subject Re: Global flag
Date
Msg-id CAMkU=1zSUpDVtJ-L55sDfO-1SMydLSRQM1R-weBCC+gt0+67dQ@mail.gmail.com
Whole thread Raw
In response to Global flag  (Swapnil Bhoite <swapnil.temp28@gmail.com>)
List pgsql-hackers
On Mon, Mar 24, 2014 at 2:53 AM, Swapnil Bhoite <swapnil.temp28@gmail.com> wrote:
Hi,

I want to set a global flag with which I can decide whether to use my code or not
in modified source code.
How I can do that?

edit src/backend/utils/misc/guc.c to add an external variable declaration near "XXX these should appear in other modules' header file", and then add a block for the variable down where it belongs based on the type of the variable, by copying and modifying a related block.  Avoid copying a block with a special validation hook, unless of course you need those.

Then where you want to use it, just add a declaration near the top of the file, and use it where it needs to be used.

Now you can set it the same way you can set other configuration variables.  If the block you copied and changed had "PGC_USERSET", you will be able to change the setting inside each connection dynamically.

It is very easy and powerful once you get used to it.  I find the hardest part is remembering which directory guc.c lives in.

Cheers,

Jeff

pgsql-hackers by date:

Previous
From: Tanmay Deshpande
Date:
Subject: About adding an attribute to pg_attibute
Next
From: Jim Nasby
Date:
Subject: Re: psql blows up on BOM character sequence