Re: hooks not working in postgresql 9.3 (building from source)

From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Rajmohan C <csrajmohan(at)gmail(dot)com>
Cc: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: hooks not working in postgresql 9.3 (building from source)
Date: 2014-05-01 03:56:41
Message-ID: CAB7nPqTBRXccMtVWce12kfHd9gJ0LXHcEceiuhi9MAkYseoRsA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, May 1, 2014 at 12:33 AM, Rajmohan C <csrajmohan(at)gmail(dot)com> wrote:
> I need to use the hook feature of planner in postgresql 9.3 to perform a
> task. I am building postgresql from source.
This hook is called planner_hook_type and is present in planner.c.

> 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
This is fine.

> Then i added the line
> ClientAuthentication_hook_type client_auth_hook = NULL; at the top of a file
> say planner.c in postgresql code
> and inside a method im checking client_auth_hook value. When i rebuild and
> run the project,
> client_auth_hook value is always zero.
Well, you are trying to create a new hook here, and not to use an
existing one. You do not need to modify the source code of PostgreSQL
when using hooks, that's what make their strength.

> 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
Are you sure that you set up properly shared_preload_libraries =
'my_client_auth' and then restarted the PostgreSQL server. If the hook
library is properly loaded by server, you should see a message similar
to that if of course server is pretty verbose when logging things:
LOG: loaded library "my_client_auth"
You can as well try a hook on an existing session by using LOAD.
--
Michael

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Kapila 2014-05-01 04:55:26 Re: Fix initdb for path with whitespace and at char
Previous Message Robert Haas 2014-05-01 02:56:52 Re: Small doc patch for pg_replication_slots