使用 PostgreSQL pg_prewarm 为外国 table
Use PostgreSQL pg_prewarm for a foreign table
我有很多外国 table 由 IMPORT FOREIGN SCHEMA
进口:
CREATE USER MAPPING FOR myuser
SERVER postgres
OPTIONS ( user 'myuser', password 'mypass');
IMPORT FOREIGN SCHEMA public from server postgres INTO public;
我有很多查询加入了本地 tables 和外国 tables。
Q1: 如果我使用 pg_prewarm
并将整个 table 放在内存中,它不会每次都通过网络来帮助我 table
Q2:如果缓存了外部 table,我担心外部 PostgreSQL 服务器上的数据更改是否会在我的本地服务器上可见。
例子:core_category
是外国的table
SELECT pg_prewarm(
'core_category',
-- "pre warm" pages of the last 1000 pages for 'mytable'
first_block := (
SELECT pg_relation_size('core_category') / current_setting('block_size')::int4 - 1000
)
);
-- or
SELECT * FROM pg_prewarm('core_category', 'buffer');
在外部 table 上使用 pg_prewarm
没有意义:因为 table 没有存储在 PostgreSQL 中,PostgreSQL 无法将其加载到共享缓冲区或文件系统缓存中。
确实,尝试这样做会导致
ERROR: fork "main" does not exist for this relation
要加快涉及外部的查询 table,您必须获取外部数据源以在内存中缓存数据。
我有很多外国 table 由 IMPORT FOREIGN SCHEMA
进口:
CREATE USER MAPPING FOR myuser
SERVER postgres
OPTIONS ( user 'myuser', password 'mypass');
IMPORT FOREIGN SCHEMA public from server postgres INTO public;
我有很多查询加入了本地 tables 和外国 tables。
Q1: 如果我使用 pg_prewarm
并将整个 table 放在内存中,它不会每次都通过网络来帮助我 table
Q2:如果缓存了外部 table,我担心外部 PostgreSQL 服务器上的数据更改是否会在我的本地服务器上可见。
例子:core_category
是外国的table
SELECT pg_prewarm(
'core_category',
-- "pre warm" pages of the last 1000 pages for 'mytable'
first_block := (
SELECT pg_relation_size('core_category') / current_setting('block_size')::int4 - 1000
)
);
-- or
SELECT * FROM pg_prewarm('core_category', 'buffer');
在外部 table 上使用 pg_prewarm
没有意义:因为 table 没有存储在 PostgreSQL 中,PostgreSQL 无法将其加载到共享缓冲区或文件系统缓存中。
确实,尝试这样做会导致
ERROR: fork "main" does not exist for this relation
要加快涉及外部的查询 table,您必须获取外部数据源以在内存中缓存数据。