By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 1,725 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

using Trigger update another database's table

P: 24
I have two data base A, & B. If a table updated or inserted or deleted means then that data have to update in table which is in data base B.

I tried with dblink module, it is not workig fully. One table only getting updated... If u know the the solution let me know it...
Apr 9 '10 #1
Share this Question
Share on Google+
4 Replies


Expert 100+
P: 700
So you need data replication. If you need it for more than one tabele you can use some tools like Slony-I.
Apr 9 '10 #2

P: 24
I was not aware of slony. I am working in 'linux' environment. Can u give better explanation?
Apr 9 '10 #3

Expert 100+
P: 700
Slony-I is a tool that allows data replication between databases.
More you can find here http://slony.info.
Apr 10 '10 #4

P: 24
slony is not working in my system.

my trigger procedure code is,


create or replace function insert_data() returns trigger as '
DECLARE
cid integer;
cmpname text;
sdate timestamp;
fdate timestamp;
phone integer;
status text;
query text;
BEGIN
IF(TG_OP = ''INSERT'') THEN
cid:= NEW.id;
cmpname:=NEW.name;
sdate:= NEW.start_date;
fdate:= NEW.from_date;
phone:= NEW.phoneno;
status:= NEW.flag;
query:=''insert into company(id,name,start_date,from_date,phoneno,flag) values(''||cid||'',''||quote_literal(cmpname)||'', ''||quote_literal(sdate)||'',''||quote_literal(fda te)||'',''||phone||'',''||quote_literal(status)||' ')'';
perform dblink_exec(''dbname=savithri port=5432 host=192.168.1.200 user=savithri password=savithri'',query);
RAISE EXCEPTION ''%'' ,query;
END IF;
RETURN NEW;
END;
' LANGUAGE 'plpgsql';

trigger is,
create trigger t1 after insert on company for each row execute procedure insert_data();

I run the dblink.sql file in both data bases. Data is not adding in source data base but data adding in destination database. can u give the solution for this???
Apr 12 '10 #5

Post your reply

Sign in to post your reply or Sign up for a free account.