在Mac上尝试安装Postgres9.3并添加Redis_Fdw
由于一直使用9.2版本的PostgreSQL,我使用brew切换到了9.3.2版本。因此,我决定再次尝试之前因错误而放弃的Redis_fdw。
首先,安装redis_fdw所需的hiredis库。
$ git clone https://github.com/redis/hiredis.git
Cloning into 'hiredis'...
remote: Reusing existing pack: 2172, done.
remote: Total 2172 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (2172/2172), 717.79 KiB | 362.00 KiB/s, done.
Resolving deltas: 100% (1248/1248), done.
Checking connectivity... done
$ cd hiredis/
$ make install
cc -std=c99 -pedantic -c -O3 -fPIC -Wall -W -Wstrict-prototypes -Wwrite-strings -g -ggdb net.c
cc -std=c99 -pedantic -c -O3 -fPIC -Wall -W -Wstrict-prototypes -Wwrite-strings -g -ggdb hiredis.c
cc -std=c99 -pedantic -c -O3 -fPIC -Wall -W -Wstrict-prototypes -Wwrite-strings -g -ggdb sds.c
cc -std=c99 -pedantic -c -O3 -fPIC -Wall -W -Wstrict-prototypes -Wwrite-strings -g -ggdb async.c
cc -shared -Wl,-install_name,libhiredis.0.10.dylib -o libhiredis.dylib net.o hiredis.o sds.o async.o
ar rcs libhiredis.a net.o hiredis.o sds.o async.o
mkdir -p /usr/local/include/hiredis /usr/local/lib
cp -a hiredis.h async.h adapters /usr/local/include/hiredis
cp -a libhiredis.dylib /usr/local/lib/libhiredis.0.10.dylib
cd /usr/local/lib && ln -sf libhiredis.0.10.dylib libhiredis.0.dylib
cd /usr/local/lib && ln -sf libhiredis.0.dylib libhiredis.dylib
cp -a libhiredis.a /usr/local/lib
请在本机上安装生产环境的redis_fdw。
まずはgitから落とす。
$ git clone https://github.com/pg-redis-fdw/redis_fdw.git
Cloning into 'redis_fdw'...
remote: Counting objects: 174, done.
remote: Compressing objects: 100% (75/75), done.
remote: Total 174 (delta 89), reused 174 (delta 89)
Receiving objects: 100% (174/174), 49.01 KiB | 0 bytes/s, done.
Resolving deltas: 100% (89/89), done.
Checking connectivity... done
$ cd redis_fdw/
ここで、PostgreSQL9.3をinstallし直し、どこにインストールされているのか分からなくなり調べる事に...
whichコマンドでpsqlの場所を調べる。
$ which psql
/usr/local/bin/psql
シンボリックリンクが張ってあるので場所を確認
$ cd /usr/local/bin
$ ls -la psql
******************** 35 2 18 13:53 psql -> ../Cellar/postgresql/9.3.2/bin/psql
見つかったのでインストール
$ cd ~/redis_fdw/
$ PATH=/usr/local/Cellar/postgresql/9.3.2/bin/:$PATH make USE_PGXS=1 install
clang -I/usr/local/Cellar/ossp-uuid/1.6.2/include -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -I. -I. -I/usr/local/Cellar/postgresql/9.3.2/include/server -I/usr/local/Cellar/postgresql/9.3.2/include/internal -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/libxml2 -c -o redis_fdw.o redis_fdw.c
clang -I/usr/local/Cellar/ossp-uuid/1.6.2/include -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -bundle -multiply_defined suppress -o redis_fdw.so redis_fdw.o -L/usr/local/Cellar/postgresql/9.3.2/lib -L/usr/local/Cellar/ossp-uuid/1.6.2/lib -Wl,-dead_strip_dylibs -lhiredis -bundle_loader /usr/local/Cellar/postgresql/9.3.2/bin/postgres
/bin/sh /usr/local/Cellar/postgresql/9.3.2/lib/pgxs/src/makefiles/../../config/install-sh -c -d '/usr/local/Cellar/postgresql/9.3.2/lib'
/bin/sh /usr/local/Cellar/postgresql/9.3.2/lib/pgxs/src/makefiles/../../config/install-sh -c -d '/usr/local/Cellar/postgresql/9.3.2/share/postgresql/extension'
/bin/sh /usr/local/Cellar/postgresql/9.3.2/lib/pgxs/src/makefiles/../../config/install-sh -c -d '/usr/local/Cellar/postgresql/9.3.2/share/postgresql/extension'
/usr/bin/install -c -m 755 redis_fdw.so '/usr/local/Cellar/postgresql/9.3.2/lib/redis_fdw.so'
/usr/bin/install -c -m 644 ./redis_fdw.control '/usr/local/Cellar/postgresql/9.3.2/share/postgresql/extension/'
/usr/bin/install -c -m 644 ./redis_fdw--1.0.sql '/usr/local/Cellar/postgresql/9.3.2/share/postgresql/extension/'
以前在這裡出現了錯誤,使我放棄了,但這次順利通過了。
在psql中进入数据库并执行“create extension”。
postgres=# create extension redis_fdw;
CREATE EXTENSION
postgres=# \dx
List of installed extensions
Name | Version | Schema | Description
-----------+---------+------------+--------------------------------------------------
hstore | 1.2 | public | data type for storing sets of (key, value) pairs
plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language
redis_fdw | 1.0 | public | Foreign data wrapper for querying a Redis server
(3 rows)
胜利!
以前我非常着迷,但很顺利地结束了。