2017-03-20 27 views
1

我想使用FDW從不同的數據源(CSV,SQL Server,Web服務器)訪問數據。我想知道外部表是否支持緩存機制,以便在連接丟失時數據仍然可用?外部數據包裝緩存機制支持

謝謝。

+2

https://www.postgresql.org/docs/current/static/sql-creatematerializedview.html將成爲該 –

+0

我可以創建一個從外部表物化視圖或本僅適用於本地表嗎? – User193452

+0

當然。與本地表相同 - 只需定義qry –

回答

1

例如使用MATERIALIZED VIEW

t=# create foreign table ft1 (pid int,state text) server past options (schema_name 'pg_catalog',table_name 'pg_stat_activity'); 
CREATE FOREIGN TABLE 
Time: 1.771 ms 
t=# create materialized view mv1 as select * FROM ft1 where state = 'active'; 
SELECT 8 
Time: 275.935 ms 
t=# select * from mv1; 
    pid | state 
-------+-------- 
15103 | active 
17699 | active 
    795 | active 
17211 | active 
    3434 | active 
20671 | active 
20888 | active 
27827 | active 
(8 rows) 

Time: 0.289 ms 
t=# refresh materialized view mv1; 
REFRESH MATERIALIZED VIEW 
Time: 329.095 ms 
t=# select * from mv1; 
    pid | state 
-------+-------- 
15103 | active 
17699 | active 
    795 | active 
17211 | active 
    3434 | active 
27396 | active 
27780 | active 
27803 | active 
(8 rows) 

Time: 0.401 ms