Discussion:
Skytools - Londiste 3 triggers on consumer usage
(too old to reply)
Emmanuel VINET
2013-09-16 19:24:02 UTC
Permalink
Hie,
I'm trying to use triggers on a consumer table replicated with londiste 3, but it seem's not working as expected.
I've a master database containing a customer table with several customers (one row per customer). Each customer unique id have a customer_<id> database containing other tables and the replicated customer table.
I'd like to keep in customers database only the line corresponding to the customer. For that i added a trigger before insert and updates on this table on consumer :
-------------------------------------------------------
CREATE OR REPLACE FUNCTION customer_filter()
RETURNS trigger AS
$$
DECLARE
result boolean;
BEGIN
SET SEARCH_PATH TO PUBLIC;
IF new.id = 1001 THEN
RETURN new;
END IF;
RETURN null;
END; $$
LANGUAGE plpgsql VOLATILE SECURITY DEFINER
COST 100;
ALTER FUNCTION customer_filter()
OWNER TO ezakus;

CREATE TRIGGER customer_insert_trigger
BEFORE INSERT ON customer
FOR EACH ROW EXECUTE PROCEDURE customer_filter();

CREATE TRIGGER customer_update_trigger
BEFORE UPDATE ON customer
FOR EACH ROW EXECUTE PROCEDURE customer_filter();
-------------------------------------------------------

Then in my consumer londiste config i've add the --trigger-arg parameter as follow :
/usr/bin/londiste3 /etc/skytools/londiste/ini\/$LIniFile add-table customer --trigger-arg=customer_insert_trigger --trigger-arg=customer_update_trigger;

The replication is working, but it seem's the triggers are not working because if I modify for exemple the customer 1001 in the master database, I should not see any modification in the customer_1002 database and see them in customer_1001 database.

Am I missing somthing, or perhaps should I use a tool like table dispatcher to do this ? In this last case, what about foreign keys on the consumer and master table ? Is the master table still containing all the non partitionned data ?

Thanks a lot.

Emmanuel.
Emmanuel VINET
2013-09-17 09:54:00 UTC
Permalink
After reader the londiste documentation, it seems my configuration is wrong as I did'nt specify the --trigger-flags=BIUL to tell londiste to use the trigger on different actions.

I'll try this new configuration.


Emmanuel
Emmanuel VINET
2013-09-30 15:43:06 UTC
Permalink
It works very simply in fact. Just keep the original configuration and put some triggers on update and insertion on consumer tables. Then alter the table to always run triggers :
ALTER TABLE <table_name> ENABLE ALWAYS TRIGGER customer_update_trigger
ALTER TABLE <table_name> ENABLE ALWAYS TRIGGER customer_insert_trigger

And it works fine.
You can have a big table replicated in several ones just containing filtered values.

E.

Loading...