Mac OS X環境にPipelineDBをインストールする

PipelineDB

www.pipelinedb.com

今回試したバージョン

  • Mac OS X 10.9.5 (Mavericks)
  • PipelineDB 0.8.5

インストール手順

まず、公式サイトからMac OS X用のインストーラーをダウンロードして、実行します。

インストールが完了したら、データベースの初期化を試してみます。 適当なディレクトリーへ移動して、pipeline-init <dir>を実行します。

$ pipeline-init pp
The files belonging to this database system will be owned by user "ohtomi".
This user must also own the server process.

The database cluster will be initialized with locale "ja_JP.UTF-8".
The default database encoding has accordingly been set to "UTF8".
pipeline-init: could not find suitable text search configuration for locale "ja_JP.UTF-8"
The default text search configuration will be set to "simple".

Data page checksums are disabled.

fixing permissions on existing directory pp ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
creating template1 database in pp/base/1 ... ok
initializing pg_authid ... ok
initializing dependencies ... ok
creating system views ... ok
loading system objects' descriptions ... ok
creating collations ... ok
creating conversions ... ok
creating dictionaries ... ok
setting privileges on built-in objects ... ok
creating information schema ... ok
loading PL/pgSQL server-side language ... ok
loading PipelineDB extensions ... ok
vacuuming database template1 ... ok
copying template1 to template0 ... ok
copying template1 to pipeline ... ok
syncing data to disk ... ok

WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run pipeline-init.

Success. You can now start the database server using:

    pipeline-server -D pp
or
    pipeline-ctl -D pp -l logfile start

初期化が失敗したときは

Mac OS Xのバージョンによっては、初期化するときに必要なライブラリーが足りない旨のエラーメッセージが出力され、正常に完了しないことがあります(今回試したバージョンではエラーが発生しました)。

公式サイトの手順にしたがって、brew install json-c freexl gdal libgeotiffを実行して、不足しているライブラリーをインストールします。

※libgeotiffをインストールする過程で、libtiffのインストールが一部失敗しました。 /usr/local/share/docは一般ユーザー権限では書き込めないので、sudo brew link libtiffを実行して、インストールを完了させます。

...snip..
==> Downloading https://homebrew.bintray.com/bottles/libtiff-4.0.4.mavericks.bottle.tar.gz
######################################################################## 100.0%
==> Pouring libtiff-4.0.4.mavericks.bottle.tar.gz
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink share/doc/tiff-4.0.4
/usr/local/share/doc is not writable.

You can try again using:
  brew link libtiff
==> Summary
🍺  /usr/local/Cellar/libtiff/4.0.4: 257 files, 3.9M
..snip..

起動手順

初期化が完了したら、データベースを起動します。 pipeline-ctl start -D <dir>を実行します。

$ pipeline-ctl start -D pp
server starting
    ____  _            ___            ____  ____
   / __ \(_)___  ___  / (_)___  ___  / __ \/ __ )
  / /_/ / / __ \/ _ \/ / / __ \/ _ \/ / / / __  |
 / ____/ / /_/ /  __/ / / / / /  __/ /_/ / /_/ /
/_/   /_/ .___/\___/_/_/_/ /_/\___/_____/_____/
       /_/

LOG:  database system was shut down at 2016-01-14 00:57:25 JST
LOG:  MultiXact member wraparound protections are now enabled
LOG:  database system is ready to accept connections
LOG:  autovacuum launcher started
LOG:  continuous query scheduler started

データベースを起動できたら、Continuous Viewを作って、データが増える様子をwatchコマンドで待ち構えておきます。

$ psql -p 5432 -h localhost pipeline
psql (9.4.4)
Type "help" for help.

pipeline=# CREATE STREAM command_history_stream
pipeline-# (
pipeline-#   cmd text
pipeline-# );
CREATE STREAM
pipeline=# 
pipeline=# CREATE CONTINUOUS VIEW command_history_view AS
pipeline-# SELECT cmd::text,
pipeline-#        count(*) AS cmd_count
pipeline-# FROM command_history_stream
pipeline-# WHERE (arrival_timestamp > clock_timestamp() - interval '1 minute')
pipeline-# GROUP BY cmd;
CREATE CONTINUOUS VIEW
pipeline=# 
pipeline=# ACTIVATE;
ACTIVATE
pipeline=# 
pipeline=# \q

$ watch -n 3 "psql -p 5432 -h localhost pipeline \"SELECT * FROM command_history_view;\""

そして、もうひとつターミナルを開いて、適当なデータを投入します。

$ history | awk '{print $2}' | while read msg; do sleep 1; psql -h localhost -p 5432 -d pipeline -c "INSERT INTO command_history_stream (cmd) VALUES ('$msg')"; done
INSERT 0 1
INSERT 0 1
INSERT 0 1
...

すると、watchで待ち構えていたほうのターミナルにContinuous Viewのクエリー結果が表示され始めます。 Continuous Viewは1分間のウィンドウで区切っているので、データを投入し始めてから1分が経過した時点で投入を止めると、徐々に件数が減っていくのが見て取れるはずです。

Every 3.0s: psql -h localhost -p 5432 -d pipeline -c "SELECT * FROM command Thu Jan 14 22:56:19 2016

    cmd     | cmd_count
------------+-----------
 rm         |         2
 ls         |         1
 ll         |         8
 mv         |         2
 cd         |         2
 vi         |         7
 ./setup.sh |         9
 ln         |         1
 git        |        22
 less       |         1
 mkdir      |         1
(11 rows)

参考情報