Sep 13, 2009
[PostgreSQL] Ludia 1.5.2 を PostgreSQL 8.3 or later にインストールする
Ludia 1.5.2 を PostgreSQL 8.3 以降にインストールする際の注意事項をメモ。
PostgreSQL 8.4.x にインストールする場合
Ludia 1.5.2 は PostgreSQL 8.4.x には対応していない。 make をしようとすると下記の様なエラーが出る。
解決策は Ludia が PostgreSQL 8.4 に対応されるのを待つことくらい?? よろしくお願い致しますm(_ _)m > NTT データの中の方々$ cd ./ludia-1.5.2 $ make make all-am if /bin/sh ./libtool --mode=compile --tag=CC gcc -D_REENTRANT -I. -I. -I. -DPOSTGRES84=1 -I/opt/local/include/postgresql84 -I/opt/local/include/postgresql84/server -I/opt/local/include/senna -Wall -fno-strict-aliasing -g -O2 -MT pgsenna2.lo -MD -MP -MF ".deps/pgsenna2.Tpo" -c -o pgsenna2.lo pgsenna2.c; \ then mv -f ".deps/pgsenna2.Tpo" ".deps/pgsenna2.Plo"; else rm -f ".deps/pgsenna2.Tpo"; exit 1; fi mkdir .libs gcc -D_REENTRANT -I. -I. -I. -DPOSTGRES84=1 -I/opt/local/include/postgresql84 -I/opt/local/include/postgresql84/server -I/opt/local/include/senna -Wall -fno-strict-aliasing -g -O2 -MT pgsenna2.lo -MD -MP -MF .deps/pgsenna2.Tpo -c pgsenna2.c -fno-common -DPIC -o .libs/pgsenna2.o pgsenna2.c: In function 'index_info_open': pgsenna2.c:366: error: dereferencing pointer to incomplete type pgsenna2.c:367: error: dereferencing pointer to incomplete type pgsenna2.c:368: error: dereferencing pointer to incomplete type pgsenna2.c:378: error: too few arguments to function 'relpath' pgsenna2.c:400: warning: implicit declaration of function 'smgrGetPendingDeletes' pgsenna2.c: In function 'scan_stat_close_all': pgsenna2.c:502: error: dereferencing pointer to incomplete type pgsenna2.c:503: error: dereferencing pointer to incomplete type pgsenna2.c:504: error: dereferencing pointer to incomplete type pgsenna2.c: In function 'pgs2build0': pgsenna2.c:613: warning: passing argument 4 of 'IndexBuildHeapScan' makes integer from pointer without a cast pgsenna2.c:613: error: too few arguments to function 'IndexBuildHeapScan' pgsenna2.c:621: warning: implicit declaration of function 'IndexCloseAndUpdateStats' pgsenna2.c: In function 'pgs2bulkdelete0': pgsenna2.c:809: error: 'SnapshotAny' undeclared (first use in this function) pgsenna2.c:809: error: (Each undeclared identifier is reported only once pgsenna2.c:809: error: for each function it appears in.) pgsenna2.c: In function 'pgs2gettuple': pgsenna2.c:940: error: dereferencing pointer to incomplete type pgsenna2.c:951: error: dereferencing pointer to incomplete type pgsenna2.c:951: error: dereferencing pointer to incomplete type pgsenna2.c:965: error: dereferencing pointer to incomplete type pgsenna2.c:967: error: dereferencing pointer to incomplete type pgsenna2.c:973: error: dereferencing pointer to incomplete type pgsenna2.c:975: error: dereferencing pointer to incomplete type pgsenna2.c:975: error: dereferencing pointer to incomplete type pgsenna2.c:975: error: dereferencing pointer to incomplete type pgsenna2.c:975: error: dereferencing pointer to incomplete type pgsenna2.c:975: error: dereferencing pointer to incomplete type pgsenna2.c:975: error: dereferencing pointer to incomplete type pgsenna2.c: In function 'pgs2getmulti': pgsenna2.c:994: error: dereferencing pointer to incomplete type pgsenna2.c:1004: error: dereferencing pointer to incomplete type pgsenna2.c:1004: error: dereferencing pointer to incomplete type pgsenna2.c:1020: error: dereferencing pointer to incomplete type pgsenna2.c:1020: error: dereferencing pointer to incomplete type pgsenna2.c:1020: error: dereferencing pointer to incomplete type pgsenna2.c:1020: error: dereferencing pointer to incomplete type pgsenna2.c: In function 'pgs2rescan': pgsenna2.c:1048: error: dereferencing pointer to incomplete type pgsenna2.c:1048: error: dereferencing pointer to incomplete type pgsenna2.c:1048: warning: left-hand operand of comma expression has no effect pgsenna2.c:1048: error: dereferencing pointer to incomplete type pgsenna2.c:1048: warning: left-hand operand of comma expression has no effect pgsenna2.c:1049: error: dereferencing pointer to incomplete type pgsenna2.c:1049: error: dereferencing pointer to incomplete type pgsenna2.c:1049: warning: left-hand operand of comma expression has no effect pgsenna2.c:1049: error: dereferencing pointer to incomplete type pgsenna2.c:1049: warning: left-hand operand of comma expression has no effect pgsenna2.c:1051: error: dereferencing pointer to incomplete type pgsenna2.c:1052: error: dereferencing pointer to incomplete type pgsenna2.c:1053: error: dereferencing pointer to incomplete type pgsenna2.c:1053: error: dereferencing pointer to incomplete type pgsenna2.c:1054: error: dereferencing pointer to incomplete type pgsenna2.c:1055: error: dereferencing pointer to incomplete type pgsenna2.c:1055: error: dereferencing pointer to incomplete type pgsenna2.c:1055: error: dereferencing pointer to incomplete type pgsenna2.c:1055: error: dereferencing pointer to incomplete type pgsenna2.c:1055: error: dereferencing pointer to incomplete type pgsenna2.c:1055: error: dereferencing pointer to incomplete type pgsenna2.c:1064: error: dereferencing pointer to incomplete type pgsenna2.c:1067: error: dereferencing pointer to incomplete type pgsenna2.c:1068: error: dereferencing pointer to incomplete type pgsenna2.c:1069: error: dereferencing pointer to incomplete type pgsenna2.c:1070: error: dereferencing pointer to incomplete type pgsenna2.c:1071: error: dereferencing pointer to incomplete type pgsenna2.c:1072: error: dereferencing pointer to incomplete type pgsenna2.c:1074: error: dereferencing pointer to incomplete type pgsenna2.c:1076: error: dereferencing pointer to incomplete type pgsenna2.c:1083: error: dereferencing pointer to incomplete type pgsenna2.c:1086: error: dereferencing pointer to incomplete type pgsenna2.c:1117: error: dereferencing pointer to incomplete type pgsenna2.c: In function 'pgs2endscan': pgsenna2.c:1130: error: dereferencing pointer to incomplete type pgsenna2.c: In function 'pgs2costestimate': pgsenna2.c:1241: error: 'indrel' undeclared (first use in this function) pgsenna2.c:1275: error: 'indexSelectivity' undeclared (first use in this function) pgsenna2.c:1277: error: too few arguments to function 'clauselist_selectivity' pgsenna2.c:1283: error: 'indexTotalCost' undeclared (first use in this function) pgsenna2.c:1287: error: too few arguments to function 'cost_qual_eval' pgsenna2.c:1292: error: 'indexStartupCost' undeclared (first use in this function) pgsenna2.c:1302: error: 'indexCorrelation' undeclared (first use in this function) pgsenna2.c: In function 'pgs2getscore': pgsenna2.c:1475: error: dereferencing pointer to incomplete type make[1]: *** [pgsenna2.lo] Error 1 make: *** [all] Error 2 $
PostgreSQL 8.3.5 以降にインストールする場合
configure は通るが、make で落ちる。
PostgreSQL 8.3.5 以降に対応した Ludia が出るのが一番なのだけれど、 matsuou1の日記さんの「PostgreSQL8.3.7にLudia1.5.2をインストールする」に対応方法が記載されている。多謝!!$ make make all-am if /bin/sh ./libtool --mode=compile --tag=CC gcc -D_REENTRANT -I. -I. -I. -DPOSTGRES83=1 -I/opt/local/include/postgresql83 -I/opt/local/include/postgresql83/server -I/opt/local/include/senna -Wall -fno-strict-aliasing -g -O2 -MT pgsenna2.lo -MD -MP -MF ".deps/pgsenna2.Tpo" -c -o pgsenna2.lo pgsenna2.c; \ then mv -f ".deps/pgsenna2.Tpo" ".deps/pgsenna2.Plo"; else rm -f ".deps/pgsenna2.Tpo"; exit 1; fi mkdir .libs gcc -D_REENTRANT -I. -I. -I. -DPOSTGRES83=1 -I/opt/local/include/postgresql83 -I/opt/local/include/postgresql83/server -I/opt/local/include/senna -Wall -fno-strict-aliasing -g -O2 -MT pgsenna2.lo -MD -MP -MF .deps/pgsenna2.Tpo -c pgsenna2.c -fno-common -DPIC -o .libs/pgsenna2.o pgsenna2.c: In function 'pgs2build0': pgsenna2.c:613: warning: passing argument 4 of 'IndexBuildHeapScan' makes integer from pointer without a cast pgsenna2.c:613: error: too few arguments to function 'IndexBuildHeapScan' make[1]: *** [pgsenna2.lo] Error 1 make: *** [all] Error 2 $
PostgreSQL 8.3.4 以前にインストールする場合
普通に Ludia 1.5.2 をインストールできる。
Feb 26, 2009
[PostgreSQL] Ludia にチャレンジ
Ludia とは
Ludiaは高速かつ高精度な全文検索インデックス機能をオープンソースのデータベース管理システムであるPostgreSQLに提供します。Ludia は株式会社NTTデータにより開発され、2006年10月11日にLGPLライセンスのオープンソースソフトウェアとして公開されました。ということで、PostgreSQLに全文検索機能付加するソフトウェア。 Senna, MeCab との連携機能を PostgreSQL に追加してくれる。 全文検索エンジン(Lucene とか Hyper Estraier とか)を管理する手間が省けるので、中小規模の全文検索が必要な場合にはとても便利そうだ。
- Ludia
- http://sourceforge.jp/projects/ludia/
- Senna
- http://qwik.jp/senna/FrontPageJ.html
- MeCab
- http://mecab.sourceforge.net/
Ludia のインストール
Ludia 1.5.1 を Mac OS X (Leopard) + PostgreSQL 8.3 にインストールしてみた。
Senna のインストール
まずは Ludia の動作に必要な Senna をインストール。 今回は MeCab は使用しない (Ludia で わかち書き に対応しない) ので、いきなり Senna をインストールする。 MeCab を使用する場合は先に MeCab をインストールする。
$ wget http://osdn.dl.sourceforge.jp/senna/33763/senna-1.1.4.tar.gz --2009-02-26 00:00:48-- http://osdn.dl.sourceforge.jp/senna/33763/senna-1.1.4.tar.gz (SNIP) 2009-02-26 00:00:48 (2.59 MB/s) - `senna-1.1.4.tar.gz.1' へ保存完了 [1121030/1121030] $ tar zxvf ./senna-1.1.4.tar.gz senna-1.1.4/ senna-1.1.4/lib/ senna-1.1.4/lib/nfkc.h (SNIP) $ cd ./senna-1.1.4 $ ./configure --without-mecab checking for a BSD-compatible install... /usr/bin/install -c checking whether build environment is sane... yes checking for a thread-safe mkdir -p... ./install-sh -c -d checking for gawk... no (SNIP) Install path prefix: /usr/local Now type 'make' to build senna 1.1.4! $ make make all-recursive Making all in lib (SNIP) creating hatenapo make[2]: Nothing to be done for `all-am'. $ sudo make install | tee ./install.log Password: Making install in lib test -z "/usr/local/lib" || .././install-sh -c -d "/usr/local/lib" /bin/sh ../libtool --mode=install /usr/bin/install -c 'libsenna.la' '/usr/local/lib/libsenna.la' (SNIP) /usr/bin/install -c -m 644 'senna.pc' '/usr/local/lib/pkgconfig/senna.pc' test -z "/usr/local/include/senna" || ./install-sh -c -d "/usr/local/include/senna" /usr/bin/install -c -m 644 'senna.h' '/usr/local/include/senna/senna.h' $
Ludia のインストール
Senna がインストール出来たら、次に Ludia をインストール。 MacPorts を使用して PostgreSQL をインストールしている場合は、PostgreSQL のパスを指定する必要がある。
$ wget http://globalbase.dl.sourceforge.jp/ludia/32461/ludia-1.5.1.tar.gz
--2009-02-26 00:21:24-- http://globalbase.dl.sourceforge.jp/ludia/32461/ludia-1.5.1.tar.gz
(SNIP)
2009-02-26 00:21:25 (1.37 MB/s) - `ludia-1.5.1.tar.gz' へ保存完了 [421128/421128]
$ tar zxvf ./ludia-1.5.1.tar.gz
ludia-1.5.1/
ludia-1.5.1/ltmain.sh
ludia-1.5.1/README.advanced
(SNIP)
ludia-1.5.1/README
ludia-1.5.1/Makefile.in
$ ./configure --with-pg-config=/opt/local/lib/postgresql83/bin/pg_config --with-senna-cfg=/usr/local/bin/senna-cfg
checking build system type... i686-apple-darwin9.6.0
checking host system type... i686-apple-darwin9.6.0
checking for gcc... gcc
checking for C compiler default output file name... a.out
(SNIP)
config.status: creating pgsenna2.h
config.status: creating config.h
config.status: executing depfiles commands
$ make
make all-am
if /bin/sh ./libtool --mode=compile --tag=CC gcc -D_REENTRANT -I. -I. -I. -DPOSTGRES83=1
-I/opt/local/include/postgresql83 -I/opt/local/include/postgresql83/server -I/usr/local/
include/senna -Wall -fno-strict-aliasing -g -O2 -MT pgsenna2.lo -MD -MP -MF ".deps/
pgsenna2.Tpo" -c -o pgsenna2.lo pgsenna2.c;
(SNIP)
elif [ `expr -- "-DPOSTGRES83=1 -I/opt/local/include/postgresql83 -I/opt/local/include/
postgresql83/server -I/usr/local/include/senna " : .*POSTGRES81.*` -gt 0 ]; then
cp -f ./uninstall_pgsenna2_81.sql.in ./uninstall_pgsenna2.sql;
fi
$ sudo make install | tee ./install.log
Password:
test -z "/opt/local/lib/postgresql83" || /Users/me/Desktop/ludiawork/ludia-1.5.1/install-sh
-d "/opt/local/lib/postgresql83"
/bin/sh ./libtool --mode=install /usr/bin/install -c 'pgsenna2.la' '/opt/local/lib/
postgresql83/pgsenna2.la'
/usr/bin/install -c .libs/pgsenna2.0.0.0.so /opt/local/lib/postgresql83/pgsenna2.0.0.0.so
(cd /opt/local/lib/postgresql83 && rm -f pgsenna2.0.so && ln -s pgsenna2.0.0.0.so pgsenna2.0.so)
(cd /opt/local/lib/postgresql83 && rm -f pgsenna2.so && ln -s pgsenna2.0.0.0.so pgsenna2.so)
/usr/bin/install -c .libs/pgsenna2.lai /opt/local/lib/postgresql83/pgsenna2.la
/usr/bin/install -c .libs/pgsenna2.a /opt/local/lib/postgresql83/pgsenna2.a
ranlib /opt/local/lib/postgresql83/pgsenna2.a
ranlib: file: /opt/local/lib/postgresql83/pgsenna2.a(pgs2_tp.o) has no symbols
ranlib: file: /opt/local/lib/postgresql83/pgsenna2.a(pgs2_recovery.o) has no symbols
chmod 644 /opt/local/lib/postgresql83/pgsenna2.a
----------------------------------------------------------------------
Libraries have been installed in:
/opt/local/lib/postgresql83
If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
- add LIBDIR to the `DYLD_LIBRARY_PATH' environment variable
during execution
See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
test -z "/opt/local/share/postgresql83" || /Users/me/Desktop/ludiawork/ludia-1.5.1/install-sh -d "/opt/local/share/postgresql83"
/usr/bin/install -c -m 644 'pgsenna2.sql' '/opt/local/share/postgresql83/pgsenna2.sql'
/usr/bin/install -c -m 644 'uninstall_pgsenna2.sql' '/opt/local/share/postgresql83/uninstall_pgsenna2.sql'
$ /opt/local/lib/postgresql83/bin/psql -U me -f ./pgsenna2.sql mydb
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
(SNIP)
CREATE OPERATOR CLASS
CREATE OPERATOR CLASS
CREATE OPERATOR CLASS
$
これで Ludia のインストールは全て完了。次は設定。
Ludia の設定
Ludia の初期設定を行う。 Ludia の設定は postgresql.conf に記述する。
$ sudo cp /opt/local/var/db/postgresql83/mydb/postgresql.conf /opt/local/var/db/postgresql83/mydb/postgresql.conf.original $ sudo vi /opt/local/var/db/postgresql83/mydb/postgresql.confPassword: $ sudo diff /opt/local/var/db/postgresql83/mydb/postgresql.conf.original /opt/local/var/db/postgresql83/mydb/postgresql.conf 493a494,508 > > #------------------------------------------------------------------------------ > # LUDIA OPTIONS > #------------------------------------------------------------------------------ > > custom_variable_classes = 'ludia' > ludia.max_n_sort_result = 10000 > ludia.enable_seqscan = on > ludia.seqscan_flags = 1 > ludia.sen_index_flags = 3 > ludia.max_n_index_cache = 16 > ludia.initial_n_segments = 512 $
postgresql.conf の編集が完了したら、PostgreSQL を再起動する。
$ sudo -u postgres /opt/local/lib/postgresql83/bin/pg_ctl -D /opt/local/var/db/postgresql83/mydb restart waiting for server to shut down.... done server stopped server starting $
Ludia の動作確認
PostgreSQL に組み込まれた Ludia と Senna のバージョンを確認する。
$ /opt/local/lib/postgresql83/bin/psql -U me mydb Welcome to psql 8.3.0, the PostgreSQL interactive terminal. (SNIP) mydb=# SELECT pgs2version(); pgs2version ------------- ludia 1.5.1 (1 row) mydb=# SELECT version, configure_option FROM pgs2seninfo(); version | configure_option ---------+-------------------- 1.1.4 | '--without-mecab' (1 row) mydb=#
テストに使用するテーブルと Ludia 用のインデックスを作成する。
インデックス作成で指定している "using fulltext(VALUE)" は、"カラム VALUE を形態素解析でインデクシングする"という意味。 形態素解析以外にも、N-gram や空白区切りも使用可能。mydb=# create table LUDIA_TEST (ID bigint primary key, VALUE text); CREATE TABLE mydb=# create index LUDIA_TEST on DATA using fulltext(VALUE); CREATE INDEX
Ludia を使って全文検索を行ってみる。 PostgreSQL 8.2 以前を使用している場合はクエリの記法が異なるので注意(下のクエリでは '%%' を '@@' に置き換える)。
mydb=# insert into LUDIA_TEST (ID, VALUE) values (1, 'トタンがセンベイ食べて 春の日の夕暮は穏かです アンダースローされた灰が蒼ざめて 春の日の夕暮は静かです'); mydb=# select * from LUDIA_TEST where VALUE %% '夕暮'; id | value ----+---------------------------------------------------------------------------------------- 1 | トタンがセンベイ食べて 春の日の夕暮は穏かです アンダースローされた灰が蒼ざめて 春の日の夕暮は静かです (1 row) mydb=#
Oct 25, 2008
[PostgreSQL] PostgreSQL の varchar, char は文字数か? バイト数か?
という論争が起きたので(笑)、公式のドキュメントで裏を取ってみた。
- PostgreSQL : Documentation : Manuals : PostgreSQL 8.2 : Character Types
- http://www.postgresql.org/docs/8.2/interactive/datatype-character.html
SQL defines two primary character types: character varying(n) and character(n), where n is a positive integer. Both of these types can store strings up to n characters in length.ということで、varchar も char も文字数ということの様だ。 ・・・「バイト数でした」ということになっていたら大変なことになるところだった(^^;



