在 9.4b2 中,postgresql_fdw不知道如何在远程表上“下推”聚合查询,例如
> explain verbose select max(col1) from remote_tables.table1;
QUERY PLAN
---------------------------------------------------------------------------------------------
Aggregate (cost=605587.30..605587.31 rows=1 width=4)
Output: max(col1)
-> Foreign Scan on remote_tables.table1 (cost=100.00..565653.20 rows=15973640 width=4)
Output: col1, col2, col3
Remote SQL: SELECT col1 FROM public.table1
Run Code Online (Sandbox Code Playgroud)
显然,发送SELECT max(col1) FROM public.table1到远程服务器并只将一行拉回来会更有效率。
有没有办法手动执行此优化?我会对像(假设地说)这样低级的东西感到满意
EXECUTE 'SELECT max(col1) FROM public.table1' ON remote RETURNING (col1 INTEGER);
Run Code Online (Sandbox Code Playgroud)
虽然当然更喜欢更高级别的构造。
我知道我可以用 做这样的事情dblink,但这将涉及重写大量已经使用外部表的代码,所以我不想这样做。
编辑:这是 Erwin Brandstetter 建议的查询计划:
=> explain verbose select col1 from remote_tables.table1
-> order by col1 desc nulls last limit …Run Code Online (Sandbox Code Playgroud) 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 …
我正在尝试创建一个脚本,该脚本在两个 postgres 9.4 数据库之间创建 postgres-fdw 连接。该脚本(在版本控制下签入)一直依靠 pgpass 来做其他事情。我可以使用任何选项来请求在 pgpass 中查找密码吗?...一般来说,关于哪些选项可用的文档在哪里CREATE USER MAPPING?该参考只是说,选项取决于在服务器上。
在 PostgreSQL 9.5.0 中,我有一个按月收集数据的分区表。尝试使用PostgreSQL新增的外表继承特性,将一个月的数据推送到另一台PostgreSQL服务器,结果得到了外表。当我从主服务器运行查询时,执行查询所需的时间比在我拥有外部表的服务器上长 7 倍。我没有通过网络传递大量数据,我的查询如下所示:
explain analyze
SELECT source, global_action, paid, organic, device, count(*) as count, sum(price) as sum
FROM "toys"
WHERE "toys"."container_id" = 857 AND (toys.created_at >= '2015-12-02 05:00:00.000000') AND
(toys.created_at <= '2015-12-30 04:59:59.999999') AND ("toys"."source" IS NOT NULL)
GROUP BY "toys"."source", "toys"."global_action", "toys"."paid", "toys"."organic", "toys"."device";
HashAggregate (cost=1143634.94..1143649.10 rows=1133 width=15) (actual time=1556.894..1557.017 rows=372 loops=1)
Group Key: toys.source, toys.global_action, toys.paid, toys.organic, toys.device
-> Append (cost=0.00..1143585.38 rows=2832 width=15) (actual time=113.420..1507.373 rows=76593 loops=1)
-> Seq Scan on toys (cost=0.00..0.00 rows=1 width=242) …Run Code Online (Sandbox Code Playgroud) postgresql performance inheritance foreign-data postgresql-9.5 postgresql-performance