Re: dealing with extension dependencies that aren't quite 'e' - Mailing list pgsql-hackers

From Abhijit Menon-Sen
Subject Re: dealing with extension dependencies that aren't quite 'e'
Date
Msg-id 20160116144818.GA17401@toroid.org
Whole thread Raw
In response to Re: dealing with extension dependencies that aren't quite 'e'  (Abhijit Menon-Sen <ams@2ndQuadrant.com>)
Responses Re: dealing with extension dependencies that aren't quite 'e'  (Robert Haas <robertmhaas@gmail.com>)
List pgsql-hackers
Right, here's another try.

The extension does trigger-based DML auditing. You install it using
CREATE EXTENSION and then call one of its functions to enable auditing
for a particular table. That function will create a customised trigger
function based on the table's columns and a trigger that uses it:
   CREATE FUNCTION fn_audit_$table_name() RETURNS TRIGGER …   CREATE TRIGGER … ON $table_name … EXECUTE
fn_audit_$table_name;

All that works fine (with pg_dump too). But if you drop the extension,
the triggers stop working because the trigger function calls functions
in the extension that are now gone.

To mitigate this problem, the extension actually does:
   CREATE FUNCTION fn_audit…   ALTER EXTENSION … ADD FUNCTION fn_audit…

Now the trigger depends on the trigger function (as before), and the
trigger function depends on the extension, so you can't inadvertently
break the system by dropping the extension.

But now pg_dump has a problem: it'll dump the trigger definitions, but
not the trigger functions (because of their new 'e' dependency on the
extension). So if you restore, you get the extension and the triggers,
but the trigger functions are gone, and things break.

*This* is the problem I'm trying to solve. Sorry, my earlier explanation
was not clear, because I didn't fully understand the problem and what
the extension was doing.

One possible solution is to make the trigger function depend on the
extension with a dependency type that isn't 'e', and therefore doesn't
prevent pg_dump from including the function in its output. We would need
some way to record the dependency, but no changes to pg_dump would be
needed.

Thoughts?

-- Abhijit



pgsql-hackers by date:

Previous
From: Michael Paquier
Date:
Subject: Re: pg_dump fails on domain constraint comments
Next
From: Robert Haas
Date:
Subject: Re: exposing pg_controldata and pg_config as functions