Windows2000環境でのCygwin+AN HTTPD+PHP+PostgreSQL

−インストール編−

第2章 PostgreSQLによるテストデータベースの作成

2.1 PostgreSQLの起動

ipc-daemonの起動

(1)PostgreSQLを使用するために、PostgreSQLのバックエンドサーバpostmasterを起動します。ただし、postmasterは共有メモリを使用するので、あらかじめ共有メモリを提供してくれるプロセス間通信サーバipc-daemonを起動しておく必要があります。

(2)ipc-daemonはあらかじめWindowsサービスとして登録されていれば(1.3節参照)、PCの電源ONと同時に自動起動します。

もし、ipc-daemonがあらかじめWindowsサービスとして登録されていない場合は、手動でcygwinのコマンドラインから、次のコマンドで起動します。

$ ipc-daemon -q &

postmasterの起動

(1)postmasterがあらかじめWindowsサービスとして登録されていない場合は、手動でpostmasterを起動します。起動用のシェルpg_ctlが用意されているので、次のように入力します。

$ pg_ctl -o "-i" start

オプション「-o "-i」を指定することにより、インターネット経由でPostgreSQLを使用することができます。

postmasterの手動終了は、次のコマンドを実行します。

$ pg_ctl stop

(2)postmasterの起動状態は、次のコマンドで確認できます。

$ pg_ctl status

たとえば、次のようになります。

postgres@TY0109 ~
$ pg_ctl status
pg_ctl: postmaster or postgres is not running

postgres@TY0109 ~
$ pg_ctl -o "-i" start
postmaster successfully started

postgres@TY0109 ~
$ pg_DEBUG: database system was shut down at 2002-12-11 18:02:43
DEBUG: checkpoint record is at 0/13AC00
DEBUG: redo record is at 0/13AC00; undo record is at 0/0; shutdown TRUE
DEBUG: next transaction id: 140; next oid: 16576
DEBUG: database system is ready
([ctrl]+cで中断)

postgres@TY0109 ~
$ pg_ctl status
pg_ctl: postmaster is running (pid: 2048)
Command line was:
/usr/bin/postmaster '-i'

postgres@TY0109 ~
$

(3)プロセスの状態はpsコマンドで確認できます。

postgres@TY0109 ~
$ ps
  PID PPID PGID WINPID TTY UID STIME COMMAND
  2044   1 2044 2044  con 1011 18:29:40 /usr/bin/bash
S 1532 2044 1532 2008  con 1011 18:43:45 /usr/bin/man
S 1976 1532 1532 1896  con 1011 18:43:46 /usr/bin/sh
S 2020 1976 1532 1628  con 1011 18:43:46 /usr/bin/less
  2048   1 1236 2048  con 1011 18:56:49 /usr/bin/postgres
  1584 2048 1236 1584  con 1011 18:56:53 /usr/bin/postgres
  2156 1584 1236 2156  con 1011 18:56:53 /usr/bin/postgres
  1992 2044 1992 2080  con 1011 19:03:52 /usr/bin/ps

postgres@TY0109 ~
$

(4)共有メモリの割り当て状況は次のipcsコマンドで確認できます。

$ ipcs

たとえば、次のようになります。


postgres@TY0109 ~
$ ipcs

---------- Shared Memory Segments --------
shmid key bytes nattch status
_shm 256 5432001 1441792 1

---------- Semaphore Arrays --------
semid nsems key
_sem 0 17 5432001 currents: 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 537
_sem 1 17 5432002 currents: 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 537
_sem 2 17 5432003 currents: 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 537
_sem 387 17 5432004 currents: 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 537
_sem 388 17 5432005 currents: 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 537
_sem 389 17 5432006 currents: 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 537

---------- Message Queues --------
msqid used-bytes messages


postgres@TY0109 ~
$

(5)postmasterを異常終了した場合は、共有メモリに残骸が残っており、次回postmasterが正常に起動しない場合があります。そのような場合は、ipcsコマンドで共有メモリID(shmid)、セマフォID(semid)、メッセージキューID(msqid)を確認し、ipcrmコマンドで共有メモリの種類ごとに共有メモリを開放します。

【参考サイト】


前へ | 目次へ | 次へ | YCポータルサイト

執筆 山田豊通
更新日:2002年12月12日