天天看點

Postgresql - Foreign data wrappers - file wrappers

file_fdw,可以通路伺服器的檔案系統的資料,或者執行程式在伺服器上,并且讀取輸出。 資料檔案或程式輸出必須以可從副本讀取的格式。對資料檔案的通路是隻讀的。 環境: CentOS 7 PG 10.4

準備: 1. 外部表檔案 [[email protected] data]# cat ft_dir/ft_test01.csv 1,aaa,aaa

2. 檔案及檔案夾權限 chown -R postgres:postgres ft_dir

建立外部表: 1. create extension CREATE EXTENSION file_fdw; mytest=# create extension file_fdw ; CREATE EXTENSION

2. create a foreign server: mytest=# CREATE SERVER ft_test01 FOREIGN DATA WRAPPER file_fdw; CREATE SERVER

3. 建立外部表 mytest=# CREATE FOREIGN TABLE ft_test01 ( mytest(# id int, mytest(# col1 text, mytest(# col2 text mytest(# ) SERVER ft_test01 mytest-# OPTIONS ( filename '/data/ft_dir/ft_test01.csv', format 'csv' ); CREATE FOREIGN TABLE

4. 檢視資料 mytest=# select * from ft_test01 ; id | col1 | col2 ----+------+------ 1 | aaa | aaa (1 row)

5. 外部表隻讀,無法插入,更新,删除 mytest=# update ft_test01 set col1 = 'aaa' , col2 = 'bbb' where id =1 ; ERROR: cannot update foreign table "ft_test01" mytest=# insert into ft_test01 values (2,'bbb','ccc'); ERROR: cannot insert into foreign table "ft_test01"

繼續閱讀