Create Materialized View from foreign table

and*_*har 6 postgresql materialized-view foreign-data postgresql-9.5

I'd like to create a simple materialized view from a table which lies in a different database. The two databases are on the same server.

What do I have to add to make the query access the foreign database and the table there?

CREATE MATERIALIZED VIEW mv_table_1 AS
  SELECT *
  FROM public.mv_table_1 --The schema & table from the different DB
WITH DATA;
Run Code Online (Sandbox Code Playgroud)

I tried using the fully qualified table name (db name before the schema name) but this results in an error:

References to other dbs are not implemented

Nei*_*gan 6

默认情况下,PostgreSQL 数据库无法相互“看到”。这是一件好事。

您可以使用 postgres_fdw 外部数据包装器使一个 pg 数据库看到另一个 pg 数据库:https://www.postgresql.org/docs/current/static/postgres-fdw.html

脚步:

  1. 添加扩展名
  2. 创建外部服务器
  3. 创建用户映射
  4. 创建外部表。如果您有 9.5+,请参阅https://www.postgresql.org/docs/current/static/sql-importforeignschema.html
  5. 创建指向外部表的物化视图