Menu

FrontPage

Eclipseプラグイン
Eclipse小技集
リファクタリング講座
テスティングフレームワーク JUnit
MSDEについて



The 20 newest affair
2010-09-092010-09-082010-09-072010-09-062010-09-012010-08-312010-08-272010-08-242010-08-232010-08-172010-08-162010-07-302010-07-212010-07-132010-06-272010-06-182010-06-172010-06-16

PostgreSQLのインストール


PostgreSQLをCygwin上で動かす方法です。
PostgreSQL-7.4.2以降はこの方法でインストールしてください。
なお、このページはWindows XPの場合のものです。Windows 2000の場合は若干違うので注意してください(説明文中に注記してあります)。



Cygwinの導入


http://sources.redhat.com/cygwin/setup.exe をローカルの任意のフォルダにダウンロードし、実行してください。
後はほとんどデフォルト値でウィザードを進めていきますが、パッケージの選択画面でPostgreSQLを選択する必要があります。

[7067696E737430302E706E67.png]

[7067696E737430312E706E67.png]

[7067696E737430322E706E67.png]

[7067696E737430332E706E67.png]

[7067696E737430342E706E67.png]

[7067696E737430352E706E67.png]

「Skip」をクリックしてインストールするバージョンにします。
[7067696E737430362E706E67.png]

[7067696E737430372E706E67.png]

次に環境変数を設定します。システム環境変数「Path」に「C:\cygwin\bin」を追加します。
[7067696E737430382E706E67.png]

システム環境変数「CYGWIN」を新規作成し、値を「server」にします。
[7067696E737430392E706E67.png]

設定が終わったらWindowsを再起動します。

PostgreSQLの導入  Λ


Cygwinを実行します。
するとWindowsのログインユーザでCygwinにログインし、コンソールウィンドウが開きます。以下の手順で、四角の中の「$」はCygwinのプロンプトで、赤文字はキーボードから入力するコマンドです。2行目から後はそのコマンドが表示する内容です。

cygserverサービスの登録


cygserver-configを実行し、cygserverをサービスに登録します。Do you want to install cygserver as service? と聞かれたら yes と答えます。
$ cygserver-config
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) yes

The service has been installed under LocalSystem account.
To start it, call `net start cygserver' or `cygrunsrv -S cygserver'.

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!

cygserverを起動します。
$ cygrunsrv -S cygserver

ユーザ「postgres」の登録


Windowsのスタートメニューの「コントロールパネル->管理ツール->コンピュータの管理」でユーザ「postgres」を新規作成します。

[7067696E737431302E706E67.png]

パスワードは無期限にしておきます。
[7067696E737431312E706E67.png]

ファイル /etc/passwd にユーザ「postgres」を追加します。
$ mkpasswd -l -u postgres >> /etc/passwd

ユーザ「postgres」に、サービスとしてログオンする権限を追加するため、ローカルセキュリティ設定ウィンドウを開きます。
$ cmd /c secpol.msc

[7067696E737431322E706E67.png]

これはWindows XPの画面です。Windows 2000の場合は画面が違いますが、設定することは一緒です。
[7067696E737431332E706E67.png]

[7067696E737431342E706E67.png]

設定が終わったらローカルセキュリティ設定ウィンドウを閉じます。

postmasterサービスの登録


postmasterをサービスに登録します。行末が「\」の行は入力が次の行に継続されます。なので、「--type manual」の行までコピーしてコンソールに一気に貼り付けてOKです。
ユーザ「postgres」のパスワードを聞かれるので入力します。
$ cygrunsrv \
--install postmaster \
--disp 'Cygwin PostgreSQL' \
--path /usr/bin/postmaster \
--args "-D /var/postgresql/data -i" \
--dep cygserver \
--termsig INT \
--user postgres \
--shutdown \
--type manual
Enter password of user `UEDA2\postgres':パスワード(何も表示されない)
Reenter, please:パスワード(何も表示されない)

データベースの初期化


実行ファイル /usr/bin/postgres のアクセス権限を変更します。
$ chmod o+rx /usr/bin/postgres

ユーザ「postgres」でCygwinにログインします。
ユーザ「postgres」のパスワードを聞かれるので入力します。
※注意:Windows 2000の場合、このままだとログインに失敗します。/userで指定するユーザ名を「マシン名\\postgres」としてください。
$ runas /user:postgres "$(cygpath -w /bin/bash)"
postgres のパスワードを入力してください:パスワード(何も表示されない)
C:\cygwin\bin\bash をユーザー "UEDA2\postgres" として開始しています...

Cygwinのコンソールウィンドウがもう一枚開きます。

開いたコンソールで、データベースを初期化します。
$ initdb --no-locale -E EUC_JP -D /var/postgresql/data
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale C.

creating directory /var/postgresql/data... ok
creating directory /var/postgresql/data/base... ok
creating directory /var/postgresql/data/global... ok
creating directory /var/postgresql/data/pg_xlog... ok
creating directory /var/postgresql/data/pg_clog... ok
selecting default max_connections... 40
selecting default shared_buffers... 1000
creating configuration files... ok
creating template1 database in /var/postgresql/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/bin/postmaster -D /var/postgresql/data
or
  /usr/bin/pg_ctl -D /var/postgresql/data -l logfile start

初期化が終わったらこのコンソールはもう使わないので閉じて構いません(このコンソールで以下の作業を行うとファイルのアクセス権限が変わって色々面倒なことになります)。

postmasterの起動と確認


元のコンソールに戻り、postmasterを起動します。
$ cygrunsrv -S postmaster

接続確認のためにpsqlを実行しますが、その前にpsqlの文字エンコーディングの設定を行います。
$ echo "\encoding SJIS" > ~/.psqlrc

psqlを実行します。とりあえずデフォルトのデータベース「template1」に接続します。接続できたら \q で終了します。
$ psql -U postgres template1
Welcome to psql 7.4.5, 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

template1=# \q

これでやっとインストールが終わりました。なお、PostgreSQLのサービス名は「Cygwin PostgreSQL」です。このサービスを停止すればPostgreSQLは止まります。スタートアップの種類は「手動」になっているので、必要に応じてプロパティを変更してください。

[7067696E737431352E706E67.png]

[7067696E737431362E706E67.png]


参考リンク  Λ




Attached File: [Attached File All List] pginst00.png[7KB] pginst01.png[6KB] pginst02.png[6KB] pginst03.png[6KB] pginst04.png[6KB] pginst05.png[7KB] pginst06.png[12KB] pginst07.png[5KB] pginst08.png[4KB] pginst09.png[3KB] pginst10.png[15KB] pginst11.png[7KB] pginst12.png[28KB] pginst13.png[8KB] pginst14.png[7KB] pginst15.png[18KB] pginst16.png[10KB]

Lastmodified: 2004-10-28 (木) 19:45:06 (2141d)