Question

The question is rather simple, but I can't find any documentation on it:

How can I mirror specific tables from a database to another?

The basic idea is having twin databases that share only specific tables between them

Any advice will be appreciated! If PostgreSQL can't do it, is there another RDBMS that can? Thanks in advance!

EDIT : The reason I want to do this is to share "arbitrary" info across two databases using django, without losing proper referential integrity. For example:

Let's say we have a clients, products and sales tables. We want to share our client and product base between two companies, but not our sales. This can be extended to any particular situation (share stocks but not clients, users but not permissions, etc). So I thought the easiest solution was to share specific tables among databases. If there is a better approach to the problem, feel free to share your experiences! Thanks in advance

Was it helpful?

Solution

There are few possibilities:

  • Master/Master replication (Bucardo), Master/Slave replication (Slony)

  • Using foreign data wrappers - you can access a any table from other databases. 9.2 provide comfort FDW read only driver, 9.3 contains read/write FDW driver

CREATE EXTENSION postgres_fdw ;
CREATE SERVER omega FOREIGN DATA WRAPPER postgres_fdw 
   OPTIONS (host 'localhost', dbname 'other_database');
CREATE USER MAPPING FOR pavel SERVER omega;
CREATE FOREIGN TABLE oo (a int) SERVER omega;

postgres=# EXPLAIN ANALYZE VERBOSE SELECT * FROM oo WHERE a BETWEEN 1 AND 100;

FDW is probably most simple solution how to share data.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top