Re: How to create database link and synonym in postgresql 9.0

From: tushar nehete <tpnehete(at)gmail(dot)com>
To: Filip Rembiałkowski <plk(dot)zuber(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: How to create database link and synonym in postgresql 9.0
Date: 2011-10-07 08:00:33
Message-ID: CANuBLQVymzp-szmKmTdyqnQ16e09nDRpch+uEC8OCdro2w-ZOA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Thank you very much Filip.
I am also thinking on the same direction but I think I was missing something
in syntax.
I am using Postgres Plus Standard server9.0.
For the database connection I have to give
dblink_exec('dbname=db2','update...');

My next concern is about performance as dblink first
transferred all data from
table to local server in recordtype and query executed as per it. Does it
has performance related issues. If yes how we improve it?

2011/10/5 Filip Rembiałkowski <plk(dot)zuber(at)gmail(dot)com>

>
> There is no CREATE SYNONYM in PostgreSQL and it's not planned for
> implementation.
> There is also no direct support for foreign data wrapper. But it's planned
> for 9.2.
>
> Nearest that you can get with PostgreSQL 9.0 is cautious use of dblink and
> views and rules.
>
> here's a sample script to show what I mean:
>
>
>
> create database db1;
> create database db2;
>
> \c db2;
> create table emp ( id integer primary key, name text);
> insert into emp values (1,'Joe'), (2,'Mary');
>
> \c db1
> \i /usr/share/postgresql/9.0/contrib/dblink.sql
>
> SELECT dblink_connect( 'db2', 'dbname=db2' );
>
> -- remote SELECT;
> CREATE VIEW emp AS SELECT id,name FROM dblink('db2','SELECT id,name FROM
> emp') AS emp(id integer, name text);
>
> SELECT * FROM emp ORDER BY name;
>
> -- remote INSERT:
> CREATE RULE emp_ins AS ON INSERT TO emp DO INSTEAD
> SELECT dblink_exec( 'db2',
> 'INSERT INTO emp(id,name) VALUES(' || quote_nullable(NEW.id) || ',' ||
> quote_nullable(NEW.name) || ')', true );
>
> INSERT INTO emp VALUES(3,'Phil');
>
> -- remote UPDATE:
> CREATE RULE emp_upd AS ON UPDATE TO emp DO INSTEAD
> SELECT dblink_exec( 'db2',
> 'UPDATE emp SET id=' || quote_nullable(NEW.id) || ', name=' ||
> quote_nullable(NEW.name)
> || ' WHERE id=' || quote_nullable(OLD.id), true );
>
> UPDATE emp SET name = 'Philip' WHERE id = 3;
>
>
>
>
>
> 2011/10/5 tushar nehete <tpnehete(at)gmail(dot)com>
>
>> Hi,
>> In one of the migration porject want to access and update some tables
>> from
>> other database on same postgresql server.
>>
>> The question is how to access tables from other database on the same
>> postgres server.
>> If it is by database link like Oracle then what is the syntax.
>> And how to create synonym?
>>
>> Say i have a postgres server on RHEL5 and it has 2 databases db1 and db2.
>> db2 has table emp which i want to access from db1.
>> so i create a dblink in oracle named dblnk_emp and access the table in db1
>> by
>> select * from emp(at)dblnk_emp;
>> so i create synonym for emp(at)dblnk_emp as emp in db1.
>>
>>
>> In postgres I can access table from other database by dblink but cannot
>> update it. Also there is
>> support for synonym.
>>
>> Please help..
>>
>>
>>
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Raymond O'Donnell 2011-10-07 08:56:55 Re: Retrieve Future Timestamp Values
Previous Message Adarsh Sharma 2011-10-07 07:13:54 Retrieve Future Timestamp Values