postgres外部表

在创建外部表的时候遇见:

CREATE EXTENSION file_fdw;
2018-12-21 17:32:23.822 CST [31237] ERROR:  could not open extension control file "/usr/local/pgsql/share/extension/file_fdw.control": 没有那个文件或目录
2018-12-21 17:32:23.822 CST [31237] STATEMENT:  CREATE EXTENSION file_fdw;
ERROR:  could not open extension control file "/usr/local/pgsql/share/extension/file_fdw.control": 没有那个文件或目录

原因是,我们安装postgres时,是没有安装file_fwd扩展的,需要手动安装。

需要进去postgres的安装目录:/root/tmp/postgresql-10.5/contrib/file_fdw

然后:make               make install

安装完成后,则可以顺利通过:

postgres=#   CREATE EXTENSION file_fdw;
CREATE EXTENSION
postgres=# CREATE SERVER file_fdw_server FOREIGN DATA WRAPPER file_fdw;
CREATE SERVER

创建外部表:

create foreign table test_03(id int,name text) server file_fdw_server options
(format 'text',filename '/home/postgres/foreign_tables/test_03.txt',delimiter ',',null '');

在路径下的文件显示:

[postgres@master ~]$ more /home/postgres/foreign_tables/test_03.txt
1,zhang
2,wang
3,dong

外部表查询:

postgres=# select * from test_03;
 id | name  
----+-------
  1 | zhang
  2 | wang
  3 | dong
(3 rows)

猜你喜欢

转载自www.cnblogs.com/hello-wei/p/10157362.html
今日推荐