Question

I need to use the hook feature of planner in postgresql 9.3 to perform a task. I am building postgresql from source. To start with, I wanted to know how to create a hook and attach that shared libray to postgresql. Hence i tried the examples given in "wiki.postgresql.org/images/e/e3/Hooks_in_postgresql.pdf" and "https://github.com/gleu/Hooks-in-PostgreSQL/tree/master/examples/my_client_auth".

I have copied the "my_client_auth.c" file and Makefile into contrib/client_auth folder. make and make install is working fine. This is the output of make install.

/bin/mkdir -p '/home/rajmohan/projects/lib/postgresql'
/usr/bin/install -c -m 755  my_client_auth.so '/home/rajmohan/projects/lib/postgresql/'

after that i have added shared_preload_libraries = 'my_client_auth' to postgresql.conf.

When i rebuild and run the project and check client_auth_hook in postgresql code client_auth_hook value is always zero. It seems my_client_auth.so file is not linked properly to my postgresql project. Am i missing any step? how to access methods in my_client_auth.so from postgresql. Kindly help

Était-ce utile?

La solution

Then i added the line ClientAuthentication_hook_type client_auth_hook = NULL; at the top of a file say planner.c

Why are you doing that?

If you want to use a hook from an extension, you must define a _PG_init function that sets the hook within the extension when it gets loaded at shared_preload_libraries time.

There is no need to modify the PostgreSQL source code its self. Only your extension. Take a look at the existing examples, like contrib/auth_delay in the PostgreSQL source tree, for how to do this correctly.

Your extension doesn't get "linked ... to the postgresql project" at compile/link time, either. It's a loadable module that PostgreSQL links to at runtime when you ask it to with create extension or by listing it in shared_preload_libraries. At that time it runs whatever code is in _PG_init, which is your opportunity to install hook functions etc.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top