加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

sqlite_fdw 使用

发布时间:2020-12-12 19:26:51 所属栏目:百科 来源:网络整理
导读:Postgresql 提供了外键表的功能,sqlite_fdw唯一的遗憾是只能select,希望github上能够尽快更新吧! 下面我把 sqlite_fdw 如何使用介绍下! 1、下载sqlite_fdw 软件包: git clonehttps://github.com/gleu/sqlite_fdw或者下载 .ZIP压缩文件 make [postgres@m

Postgresql 提供了外键表的功能,sqlite_fdw唯一的遗憾是只能select,希望github上能够尽快更新吧!

下面我把sqlite_fdw 如何使用介绍下!

1、下载sqlite_fdw 软件包:

git clonehttps://github.com/gleu/sqlite_fdw或者下载 .ZIP压缩文件

make


[postgres@mxl sqlite_fdw]$ make

gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -O2 -fpic -I. -I./ -I/usr/local/pgsql/include/server -I/usr/local/pgsql/include/internal -D_GNU_SOURCE -I/usr/include/libxml2 -c -o src/sqlite_fdw.o src/sqlite_fdw.c

gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -O2 -fpic -shared -o sqlite_fdw.so src/sqlite_fdw.o -L/usr/local/pgsql/lib -Wl,--as-needed -Wl,-rpath,'/usr/local/pgsql/lib',--enable-new-dtags -lsqlite3


make install


[root@mxl sqlite_fdw]# make install

/bin/mkdir -p '/usr/local/pgsql/lib'

/bin/mkdir -p '/usr/local/pgsql/share/extension'

/bin/mkdir -p '/usr/local/pgsql/share/extension'

/bin/mkdir -p '/usr/local/pgsql/share/doc/extension'

/usr/bin/install -c -m 755 sqlite_fdw.so '/usr/local/pgsql/lib/sqlite_fdw.so'

/usr/bin/install -c -m 644 sqlite_fdw.control '/usr/local/pgsql/share/extension/'

/usr/bin/install -c -m 644 sql/sqlite_fdw--0.0.1.sql '/usr/local/pgsql/share/extension/'

/usr/bin/install -c -m 644 doc/sqlite_fdw.md '/usr/local/pgsql/share/doc/extension/'


2、在数据库引用sqlite_fdw


postgres=# CREATE EXTENSION sqlite_fdw;

CREATE EXTENSION

postgres=# dx ;

List of installed extensions

Name | Version | Schema | Description

--------------------+---------+------------+-----------------------------------------------------------

pg_stat_statements | 1.2 | public | track execution statistics of all SQL statements executed

plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language

sqlite_fdw | 0.0.1 | public | SQLite Foreign Data Wrapper

uuid-ossp | 1.0 | public | generate universally unique identifiers (UUIDs)

(4 rows)


3、创建一个fdw的server


CREATE SERVER sqlite_server FOREIGN DATA WRAPPER sqlite_fdw OPTIONS (database '/tmp/localdb.sqlite');


4、创建外键表


CREATE FOREIGN TABLE fdwuserrole(userid integer,roleid ingeter) SERVER sqlite_server OPTIONS (table 'userrole');


5、查看外键表server


postgres=# des

List of foreign servers

Name | Owner | Foreign-data wrapper

---------------+----------+----------------------

sqlite_server | postgres | sqlite_fdw

(1 row)


6、删除外键表


drop FOREIGN table fdwuserrole;


问题:1

src/sqlite_fdw.c:37:21: error:sqlite3.h: No such file or directory

make 的时候提示解析不了sqlite头文件

rpm -Uvhhttp://www6.atomicorp.com/channels/atomic/centos/6/x86_64/RPMS/atomic-release-1.0-21.el6.art.noarch.rpm

yum update

yum sqlite-devel install -y


问题:2

安装sqlite_fdw的时候需要使用postgres 的pg_config 所以需要把postgres 的环境变量在root 添加一下

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读