dblink questions
dblink questions
От:
"Brian Maguire" <bmaguire@vantage.com>
Дата:
What's the best way to create a connection with dblink with persisted
connections for web applications?
For example:
I want to have a view that links to a table in another pg database so I
can mask the connection and make it easier to query.
so I would do this ...
create view myremote_pg_proc as
select *
from dblink('myconnection','select proname, prosrc from pg_proc')
as t1(proname name, prosrc text);
so I can do this ...
select * from myremote_pg_proc where proname like 'bytea%';
I understand that a connection can be made by dblink_connect(text
connstr) and
dblink_connect(text connname, text connstr), but how do you suggest
making the first connection from a web application?
select dblink('myconnection','127.0.0.1 port=5432 dbname=template1
user=postgres password=mypasswd')
Do you suggestion not using the persistent connection? and do this?
create view myremote_pg_proc as
select *
from dblink('myconnection','127.0.0.1 port=5432 dbname=template1
user=postgres password=mypasswd','select proname, prosrc from pg_proc')
as t1(proname name, prosrc text);
Thanks a Bunch,
Brian
Re: dblink questions
От:
Joe Conway <mail@joeconway.com>
Дата:
Brian Maguire wrote: > What's the best way to create a connection with dblink with persisted > connections for web applications? > It all depends on how you intend to use the dblink connections. If your web page connects to Postgres, issues a single query using dblink (via a view or whatever), and then completes, you don't need a persistent dblink connection -- just use the explicit connection syntax. If, on the other hand, your web page connects to Postgres, issues several queries using dblink (via a view or whatever), and then completes, it would make sense to use a persistent dblink connection. In that case, execute dblink_connect() before you execute your queries. Use named persistent connections if you need more than one, anonymous otherwise. HTH, Joe