ubuntu下安装postgresql扩展redis_fdw

fdw 地址:https://github.com/pg-redis-fdw/redis_fdw/tree/REL9_3_STABLE.zip   这里注意选择分支,不同的版本对应不同的分支

首先安装postgresql

apt-get install postgresql postgresql-contrib postgresql-server-dev-all 

先安装redis_fdw的hiredis

wget https://github.com/redis/hiredis/archive/v0.13.1.tar.gz
unar xxx.tar.gz 
make  & make install

接下来安装 redis_fdw

wget https://github.com/pg-redis-fdw/redis_fdw/archive/REL9_3_STABLE.zip 
unar xxx.zip
make & make install

如果安装成功 会有一个文件产生

/usr/lib/postgresql/9.3/lib/redis_fdw.so

解决lib文件路径

ln -s /usr/local/lib/libhiredis.so.0.13 /usr/lib/

接下来进入postgresql的shell

psql -U postgres -d exampledb
exampledb=> \dx  #查看扩展列表

exampledb=# \dx
                 List of installed extensions
  Name   | Version |   Schema   |         Description          
---------+---------+------------+------------------------------
 plpgsql | 1.0     | pg_catalog | PL/pgSQL procedural language
(1 row)

exampledb=# create extension redis_fdw;
CREATE EXTENSION
exampledb=# CREATE SERVER redis_server
exampledb-# FOREIGN DATA WRAPPER redis_fdw
exampledb-# OPTIONS (address '127.0.0.1', port '6379');
CREATE SERVER
exampledb=# CREATE FOREIGN TABLE redis_db0 (key text, value text) 
exampledb-# SERVER redis_server
exampledb-# OPTIONS (database '0');
CREATE FOREIGN TABLE
exampledb=# CREATE USER MAPPING FOR PUBLIC
exampledb-# SERVER redis_server;
CREATE USER MAPPING
exampledb=# select * from redis_db0 ;
 key | value 
-----+-------
(0 rows)

接下在redis-cli 中 往0队列中插入内容

redis 127.0.0.1:6379> MSET one 1 two 2 three 3 four 4
OK

exampledb=# select * from redis_db0 ;
  key  | value 
-------+-------
 four  | 4
 three | 3
 two   | 2
 one   | 1
(4 rows)

实现同步,

接下来可直接操作数据库的表, 再查看redis中的队列有没有变化。余下的留给自己实验了

发表评论

电子邮件地址不会被公开。 必填项已用*标注