Mirror specific tables in postgreSQL

匆匆过客 提交于 2019-12-08 08:17:25

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/21138302/mirror-specific-tables-in-postgresql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!