Skip site navigation (1) Skip section navigation (2)

Re: [despammed] Reading across databases

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Andreas Kretschmer <akretschmer(at)despammed(dot)com>
Cc: PostGreSQL <pgsql-novice(at)postgresql(dot)org>
Subject: Re: [despammed] Reading across databases
Date: 2004-12-17 09:07:53
Message-ID: 20041217090753.GA33238@winnie.fuhr.org (view raw or flat)
Thread:
Lists: pgsql-novice
On Fri, Dec 17, 2004 at 08:49:02AM +0100, Andreas Kretschmer wrote:
> am  17.12.2004, um  7:48:12 +0000 mailte Steve Tucknott folgendes:
> > 
> > Is there a way of 'cross accessing' databases?
> 
> IMHO no. Not in a single psql-Session. But you can do this in a
> client-application. There can you open any connections to several
> databases.

With the contrib/dblink module you can query other databases, even
databases on other servers.  You can hide the complexity by creating
a view:

CREATE VIEW othertable AS
SELECT *
FROM dblink(
  'host=otherhost dbname=otherdb user=johndoe password=abc123xyz',
  'SELECT * FROM othertable'
) AS othertable(id INTEGER, name TEXT);

SELECT * FROM othertable;

> > We tend to use three environments for development - a dev_ , test_ and
> > rel_ prefixed database then exists - one for each environment. There are
> 
> You should use for this reason different schemas in one database. Then
> you can cross-access between the different schemas.

Some environments might prefer to have development and production
in different databases or on different servers so problems on one
don't affect the other.  In such cases, dblink can be a handy way
to perform queries that need to access both databases.

-- 
Michael Fuhr
http://www.fuhr.org/~mfuhr/

In response to

Responses

pgsql-novice by date

Next:From: Andreas KretschmerDate: 2004-12-17 09:28:21
Subject: Re: [despammed] Reading across databases
Previous:From: Steve TucknottDate: 2004-12-17 08:20:56
Subject: Re: [despammed] Reading across databases

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group