Emmanuel VINET
2013-09-16 19:24:02 UTC
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.
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.