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