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.