I'm writing a postgres FDW extension for my custom data storage.
I have a class that provides the API for the storage. initialization of the class is rather costly, and I also need to have access to it outside of the FdwRoutine functions, so I wanted to initialize it once (per foreign table) in the VALIDATOR function, then access it in the FdwRoutine functions and UDFs.
I found that each query is executed in a separate threads, and even the ForeignServer isn't shared between them. I couldn't find any documentation on memory sharing in FDW.
What would be the best approach way to initialize some object when CREATE FOREIGN TABLE is called, and access it in FdwRoutine functions and UDFs?