我可以在 postgresql 中使用另一个数据库的 table,但给人的印象是 table 存在于同一个数据库中吗?
Can I use another database's table in postgresql, yet give an impression the table exists in the same database?
假设我有以下数据库主机
core
(主机:a.b.c.d
,dbaname:core
,用户名:coreUser
)与 tables users
,accounts
和 permissions
app1
(主机:d.e.f.g
,数据库名:appdb1
,用户名:appuser1
)
app2
(主机:h.i.k.l
,数据库名:appdb2
,用户名:appuser2
)
我希望 core.users
、core.accounts
和 core.permissions
在 app1
和 app2
上作为原生 table 可用。我希望能够镜像准确的 table,并且对这些 table 的插入和更新应该更新 core
中的 table。有办法吗?
是的,看看slony replication。
如果您不想复制数据,那么 dblink extension 可能会对您有所帮助。它允许将查询从一个数据库调用到另一个数据库。结合函数或视图可能会有用(尽管对 core
所做的更改不会自动反映在 "child" 数据库中)。
postgres_fdw 可以胜任。
The postgres_fdw module provides the foreign-data wrapper
postgres_fdw, which can be used to access data stored in external
PostgreSQL servers.
The functionality provided by this module overlaps substantially with
the functionality of the older dblink module. But postgres_fdw
provides more transparent and standards-compliant syntax for accessing
remote tables, and can give better performance in many cases.
FDW 如您所知代表外部数据包装器,它用于将外部数据源连接到 postgresql。在这种情况下,外部数据源是另一个 postgrsql 数据库。
假设我有以下数据库主机
core
(主机:a.b.c.d
,dbaname:core
,用户名:coreUser
)与 tablesusers
,accounts
和permissions
app1
(主机:d.e.f.g
,数据库名:appdb1
,用户名:appuser1
)app2
(主机:h.i.k.l
,数据库名:appdb2
,用户名:appuser2
)
我希望 core.users
、core.accounts
和 core.permissions
在 app1
和 app2
上作为原生 table 可用。我希望能够镜像准确的 table,并且对这些 table 的插入和更新应该更新 core
中的 table。有办法吗?
是的,看看slony replication。
如果您不想复制数据,那么 dblink extension 可能会对您有所帮助。它允许将查询从一个数据库调用到另一个数据库。结合函数或视图可能会有用(尽管对 core
所做的更改不会自动反映在 "child" 数据库中)。
postgres_fdw 可以胜任。
The postgres_fdw module provides the foreign-data wrapper postgres_fdw, which can be used to access data stored in external PostgreSQL servers.
The functionality provided by this module overlaps substantially with the functionality of the older dblink module. But postgres_fdw provides more transparent and standards-compliant syntax for accessing remote tables, and can give better performance in many cases.
FDW 如您所知代表外部数据包装器,它用于将外部数据源连接到 postgresql。在这种情况下,外部数据源是另一个 postgrsql 数据库。