Postgresql mongo_fdw install
2024-07-21 02:51:36
供稿:网友
mongodb_fdw不是PG自带的插件,所以要下载编译安装一下以下操作都是用root用户操作:安装依赖工具:yum install git automake autoconf libtool gcc环境变量配置. /home/postgres/.bash_PRofile export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH下载mongodb_fdwgit clone https://github.com/EnterpriseDB/mongo_fdw.gitcd mongo_fdw./autogen.sh --with-mastermake && make installpsql -h 127.0.0.1 -U postgrescreate extension mongo_fdw;CREATE SERVER mongo_server FOREIGN DATA WRAPPER mongo_fdw OPTIONS (address '127.0.0.1', port '5888'); CREATE USER MAPPING FOR postgres SERVER mongo_server OPTIONS (username 'test', passWord 'test');CREATE FOREIGN TABLE tb1(name text)SERVER mongo_serverOPTIONS (database 'test', collection 'tb1');在同一台机器安装了mongodbcat /data01/mongo.confdbpath = /data01/shard/configport = 5888logpath = /data01/mongodb_log/mongodb_5888.loglogappend = truefork = truenoauth = truenounixsocket = truedirectoryperdb = truejournal = truejournalCommitInterval = 40profile = 0nohttpinterface = truenssize = 1000oplogSize = 1024storageEngine = wiredTigerwiredTigerJournalCompressor = none启动mongodbnumactl --interleave=all mongod --replSet=hank -f /data01/mongo.conf测试表:mongo 127.0.0.1:5888/testMongoDB shell version: 3.2.8connecting to: 127.0.0.1:5888/test创建访问用户:db.createUser( { user:"test", pwd:"test", roles: [ { role:"dbOwner", db:"test" } ] });hank:PRIMARY> db.tb1.count();82postgresql下直接查询mongodb的表postgres=# select count(*) from tb1; count ------- 82参考:https://github.com/EnterpriseDB/mongo_fdwhttp://raghavt.blogspot.jp/2015/06/compiling-write-able-mongofdw-extension.html