環境変数設定
1) .bashrcの編集
cygwinは終了しておきます。Windowsでの作業になります。C:\cygwin\home\Owner\.bashrcの末尾に下の2行を追加します。これで、cygwinを起動すると環境変数、「PGDATA」「CYGWIN」がエクスポート(設定)されるようになります。
(C:\cygwin\home\Owner\.bashrcの「Owner」の部分は各PCの環境によって異なります。)

export PGDATA="/usr/local/pgsql/data"
export CYGWIN="server"

2) 設定内容を確認
Cygwinを起動して「echo $CYGWIN」と入力します。「sever」と表示されれば1)の設定がうまくいったことを意味します。echoに続く「$」は続く文字列(「CYGWIN」)を変数として解釈するという意味です。

$ echo $CYGWIN
server

server
3) cygseverの設定
Cygwinを起動して下を入力して、cygseverの設定をします。C:\cygwin\etc\cygserver.confが作成されます。
これは初めに1回だけ行えばよいです。
$ cygserver-config

Overwrite existing /etc/cygserver.conf file? (yes/no) と聞かれたらyesを
Do you want to install cygserver as service?と聞かれたらnoを入力します。


Owner@FMIL002 ~
$ cygserver-config
Overwrite existing /etc/cygserver.conf file? (yes/no) yes
Generating /etc/cygserver.conf file


Warning: The following function requires administrator privileges!

Do you want to install cygserver as service?
(Say "no" if it's already installed as service) (yes/no) no

Further configuration options are available by editing the configuration
file /etc/cygserver.conf. Please read the inline information in that
file carefully. The best option for the start is to just leave it alone.

Please keep in mind, that a client application which wants to use
the services provided by cygserver *must* have the environment variable
CYGWIN set so that it contains the word "server". So, if you don't
need any other special CYGWIN setting, just set it to "server".

It is advisable to add this setting to the Windows system environment.

Basic Cygserver configuration finished. Have fun!
!

4) cygserverの起動
「/usr/sbin/cygserver &」と入力します。「cygserver: Initialization complete. Waiting for requests.」と表示されるので「Enter」を入力します。「ps」と入力してcygserverが動いていることが確認できます。


Owner@FMIL002 ~
$ /usr/sbin/cygserver &
[1] 1744

Owner@FMIL002 ~
$ cygserver: Initialization complete. Waiting for requests.


Owner@FMIL002 ~
$ ps
PID PPID PGID WINPID TTY UID STIME COMMAND
1436 1 1436 1436 con 1003 17:21:48 /usr/bin/bash
1744 1436 1744 1832 con 1003 17:31:00 /usr/sbin/cygserver
1440 1436 1440 1264 con 1003 17:31:04 /usr/bin/ps

5) データベースの初期化
/usr/sbin/initdb」と入力します。下のように表示されデータベースの初期化が行われます。
1)で設定した環境変数「PGDATA」のフォルダ(C:\cygwin\usr\local\pgsql\data)が作成されたことが確認できます。れは初めに1回だけ行えばよいです。

Owner@FMIL002 ~
$ initdb
The files belonging to this database system will be owned by user "Owner
This user must also own the server process.

The database cluster will be initialized with locale C.

creating 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
selecting default max_connections... 40
selecting default shared_buffers... 1000
creating configuration files... ok
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:

/usr/sbin/postmaster -D /usr/local/pgsql/data
or
/usr/sbin/pg_ctl -D /usr/local/pgsql/data -l logfile start

6) Postmasterの起動
「/usr/sbin/pg_ctl -D /usr/local/pgsql/data -l logfile start」と入力してPostgreSQLを起動します。

Owner@FMIL002 ~
$ /usr/sbin/pg_ctl -D /usr/local/pgsql/data -l logfile start
postmaster successfully started

7) データベースの作成
「createdb mydb」と入力してデータベースを作成します。
以上でPostgreSQLの設定は終了です。

Owner@FMIL002 ~
$ createdb mydb
CREATE DATABASE

8) Postmasterの終了
「/usr/sbin/pg_ctl stop」と入力してPostmasterを終了させます。

Owner@FMIL002 ~
$ /usr/sbin/pg_ctl stop
waiting for postmaster to shut down......done
postmaster successfully shut down

9) cygserverの終了
killコマンドでcygseverのプロセスID(PID)を指定してプログラムを終了させます。「ps」と入力してcygseverのPIDを調べます。
「kill 1744」と入力してcygserverを終了させます。
Owner@FMIL002 ~
$ ps
PID PPID PGID WINPID TTY UID STIME COMMAND
1436 1 1436 1436 con 1003 17:21:48 /usr/bin/bash
1744 1436 1744 1832 con 1003 17:31:00 /usr/sbin/cygserver
2196 1436 2196 2220 con 1003 18:04:32 /usr/bin/ps

Owner@FMIL002 ~
$ kill
1744


上記8)と9)の操作はDBでの作業を終了してからCygwinを閉じるまでに必ず行ってください。



3節  PostgreSQLの設定 1章 インストールと設定
PostgreSQL 8.0.4-1のインストール手順です。バージョンは下のように入力して確認します。

$ cygcheck -cd postgresql
Cygwin Package Information
Package Version
postgresql 8.0.4-1