PostgreSQLをインストールする
ダウンロード
データベースを勉強するために環境を持ち歩くことはできないかと考え、Zaurus(SL-C3000)用のPostgreSQLをGoogle検索したところ、以下のURLにSL-Cシリーズ用のPostgreSQL 7.4.16を発見した。
FocV Projectさんに感謝する。
ダウンロードしたIPKファイルを事前にPCへ展開し、どのようなディレクトリ構造でインストールされるのか、他に必要なファイルが無いかを確認したところ、OpenSSL 0.9.8が必要であることが判明したので、これも同じサイトからダウンロードした。
インストール
いつも通り、「ソフトウェアの追加/削除」でOpenSSL→PostgreSQLの順番でインストールを実行した。
PostgreSQLが割合に大きいので、インストールの完了までに数分間待つ必要があった。
初期設定
初期設定では以下のURLを参考にした。
http://www.postgresql.jp/document/pg746doc/html/installation.html
データベースは /usr/local/pgsql/data に作成することにした。
また、データベースオーナはzaurusユーザとした。
$ su # mkdir /usr/local/pgsql # chown zaurus:qpe /usr/local/pgsql # exit $ mkdir /usr/local/pgsql/data $ initdb -D /usr/local/pgsql/data The files belonging to this database system will be owned by user "zaurus". This user must also own the server process. The database cluster will be initialized with locale ja. fixing permissions on existing directory /usr/local/pgsql/data... ok creating directory /usr/local/pgsql/data/base... ok creating directory /usr/local/pgsql/data/global... ok creating directory /usr/local/pgsql/data/pg_xlog... ok creating directory /usr/local/pgsql/data/pg_clog... ok cp: unable to create `/usr/local/pgsql/data/postgresql.conf': Operation not permitted initdb: failed
上記の通り、initdbでエラーが発生してしまった。
initdbはシェルスクリプトである。
その内容を見ると、以下の行が見つかった。
560行目 : cp /dev/null "$PGDATA"/postgresql.conf || exit_nicely
このコマンドを別のLinux(CentOS 3.7)マシーンで試したところ上手く行くので、どうやらZaurusで駄目なだけらしい。
そこで、この行を以下の内容に置き換えた。
touch "$PGDATA"/postgresql.conf || exit_nicely
そして再びinitdbを実行した。
$ rm -r /usr/local/pgsql/data/* $ initdb -D /usr/local/pgsql/data : : selecting default max_connections... 100 selecting default shared_buffers... 1000 creating configuration files... ok creating template1 database in /usr/local/pgsql/data/base/1... FATAL: XX000: failed to initialize lc_messages to "" LOCATION: InitializeGUCOptions, guc.c:1881 initdb: failed
今度は何やら意味不明なエラーが発生した。
そこで「failed to initialize lc_messages to ""」でGoogle検索して見たところ、以下のURLに同じ障害にぶつかった人が見つかったので、そこのアドバイスに倣った手順を試して見ることにした。
http://ml.postgresql.jp/pipermail/pgsql-jp/2003-February/012685.html
$ export LANG=C $ rm -r /usr/local/pgsql/data/* $ initdb -D /usr/local/pgsql/data --encoding=EUC_JP The files belonging to this database system will be owned by user "zaurus". This user must also own the server process. The database cluster will be initialized with locale C. : : creating template1 database in /usr/local/pgsql/data/base/1... ok initializing pg_shadow... ok enabling unlimited row size for system tables... ok initializing pg_depend... ok creating system views... ok loading pg_description... ok creating conversions... ok setting privileges on built-in objects... ok creating information schema... ok vacuuming database template1... ok copying template1 to template0... ok Success. You can now start the database server using: /home/QtPalmtop/bin/postmaster -D /usr/local/pgsql/data or /home/QtPalmtop/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start
なるほど、環境設定で "LANG=ja" としていたことが問題だったらしい。
ちなみに、別のLinuxマシーンでは "LANG=ja_JP.eucJP" としていても問題はなかったので、Zaurusの言語環境が原因ではないかと考えられる。
何はともあれ、ようやくデータベースを初期化することができた。
ありがたい。
動作確認
最後に簡単な動作確認を行って見た。
$ createdb CREATE DATABASE $ psql Welcome to psql 7.4.16, the PostgreSQL interactive terminal. Type: \copyright for distribution terms \h for help with SQL commands \? for help on internal slash commands \g or terminate with semicolon to execute query \q to quit zaurus=# \l List of databases Name | Owner | Encoding -----------+--------+---------- template0 | zaurus | EUC_JP template1 | zaurus | EUC_JP zaurus | zaurus | EUC_JP (3 rows) zaurus=# create table test ( zaurus(# id integer, zaurus(# name char(40), zaurus(# age integer zaurus(# ); CREATE TABLE zaurus=# \d List of relations Schema | Name | Type | Owner --------+------+-------+-------- public | test | table | zaurus (1 row) zaurus=# insert into test values (1, 'pochy9n', 20); INSERT 17146 1 zaurus=# select * from test; id | name | age ----+------------------------------------------+----- 1 | pochy9n | 20 (1 row) zaurus=# \q
上記の "zaurus=#" はpsqlコマンドの入力プロンプトである。
これでデータベースを勉強するモバイル環境が手に入った。
改めて先人に感謝する。