[Bucardo-general] understanding customcode and conditional trigger execution

Greg Sabino Mullane greg at endpoint.com
Sun Apr 29 03:09:33 UTC 2012

On Mon, Apr 23, 2012 at 08:52:34PM +0500, Ali Asad Lotia wrote:
> Greetings All,
> I'm a complete Bucardo noob and have just installed Bucardo 4.99.x/5 in
> order to do Postgres to MongoDB replication. In my scenario, I need to
> figure out if it is possible to replicate conditionally. 
> The applications writing to the source database set their application_name, 
> I need to check the application_name when a transaction occurs and ignore 
> the transaction if application_name is set to a known set of values. Are 
> there docs beyond what is in the wiki at 
> http://bucardo.org/wiki/Bucardo/tables/bucardo.customcode I'm also
> wondering at what the customcode_whenrun value should be for that bit of
> customcode.

A customcode is too late: at that point, the only record we (Bucardo) has 
is the timestamp and the primary key of the change. I think what you want 
is a custom trigger on the table(s) in question. These are made by populating 
the bucardo_custom_trigger table. Specifically, you'll want to make a near 
copy of the existing "delta" function. Then you'd add some logic to the top 
of it, before the 
bit, to have the trigger do nothing if the application_name does not match.

For example:

  DECLARE appname TEXT;
  SELECT INTO appname
    setting FROM pg_settings WHERE name = 'application_name';
  IF appname = 'unimportant_app' THEN

Once you have that in place in the bucardo_custom_trigger table, you should 
be able to do a validate sync and have it add the new function. At that 
point, you can drop the original delta function.

Yes, docs are sorely lacking in these areas!

Greg Sabino Mullane greg at endpoint.com
End Point Corporation
PGP Key: 0x14964AC8
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 163 bytes
Desc: not available
URL: <https://mail.endcrypt.com/pipermail/bucardo-general/attachments/20120428/c4cf458e/attachment.sig>

More information about the Bucardo-general mailing list