====== PostgreSQL ======
===== インストール =====
- [[http://www.postgresql.jp/|NPO法人 日本PostgreSQLユーザ会]]より最新版を[[https://www.postgresql.jp/download|ダウンロード]]してくる。\\ ここでは [[https://get.enterprisedb.com/postgresql/postgresql-11.4-3-windows-x64.exe|postgresql-11.4-3-windows-x64.exe]] をダウンロードする。
- postgresql-x.x.x-windows-x64.exe を実行する。
- [Next >] ボタンをクリックしてインストールを続ける。\\ {{:windows:postgresql_installer_001.png?400|PostgreSQL Installer 001}}{{:windows:postgresql_installer_002.png?400|PostgreSQL Installer 002}}\\ {{:windows:postgresql_installer_003.png?400|PostgreSQL Installer 003}}{{:windows:postgresql_installer_004.png?400|PostgreSQL Installer 004}}
- postgres のパスワードを設定して [Next >] ボタンをクリックしインストールを続ける。\\ {{:windows:postgresql_installer_005.png?400|PostgreSQL Installer 005}}{{:windows:postgresql_installer_006.png?400|PostgreSQL Installer 006}}\\ {{:windows:postgresql_installer_007.png?400|PostgreSQL Installer 007}}{{:windows:postgresql_installer_008.png?400|PostgreSQL Installer 008}}\\ {{:windows:postgresql_installer_009.png?400|PostgreSQL Installer 009}}{{:windows:postgresql_installer_010.png?400|PostgreSQL Installer 010}}
- [Finish] をクリックすると Application Stack Builder が起動する。\\ {{:windows:postgresql_installer_011.png?400|PostgreSQL Installer 011}}
- Application Stack Builder で pgBouncer、Npgsql(.NETから利用時)、psqlODBC(MS-Accessから利用時)、PostGIS(GIS機能を利用時)をインストールする。\\ [次へ >] をクリックし、リストから **PostgreSQL 11
(x64) on port 5432** を選択して [次へ >] でインストールを進める。\\ {{:windows:postgresql_application_stack_builder_001.png?400|Application Stack Builder 001}}{{:windows:postgresql_application_stack_builder_002.png?400|Application Stack Builder 002}}
- インストールしたいアプリケーションを選択する。
[v] pgBouncer
[v] Npgsql
[v] psqlODBC (64bit)
[v] PostGIS
\\ {{:windows:postgresql_application_stack_builder_003.png?400|Application Stack Builder 003}}{{:windows:postgresql_application_stack_builder_004.png?400|Application Stack Builder 004}}
- [次へ >] をクリックすると必要なアプリケーションのダウンロードが開始される。{{:windows:postgresql_application_stack_builder_005.png?400|Application Stack Builder 005}}{{:windows:postgresql_application_stack_builder_006.png?400|Application Stack Builder 006}}
- 全てのダウンロードが完了したら [次へ >] でアプリケーションのインストールを開始する。\\ {{:windows:postgresql_application_stack_builder_007.png?400|Application Stack Builder 007}}
- Npgsql インストーラーの [Next >] をクリックしてインストールを行う。\\ {{:windows:postgresql_npgsql_installer_001.png?400|Npgsql Installer 001}}{{:windows:postgresql_npgsql_installer_002.png?400|Npgsql Installer 002}}\\ {{:windows:postgresql_npgsql_installer_003.png?400|Npgsql Installer 003}}{{:windows:postgresql_npgsql_installer_004.png?400|Npgsql Installer 004}}
- pgBouncer インストーラーの「言語の選択」で **Japanese - 日本語** のまま [OK] をクリックする。\\ {{:windows:postgresql_pgbouncer_installer_001.png?200|pgBouncer Installer 001}}
- [次へ >] をクリックしてインストールを進める。\\ {{:windows:postgresql_pgbouncer_installer_002.png?400|pgBouncer Installer 002}}{{:windows:postgresql_pgbouncer_installer_003.png?400|pgBouncer Installer 003}}
- postgres のパスワードを設定して [次へ >] をクリックしてインストールを進める。\\ {{:windows:postgresql_pgbouncer_installer_004.png?400|pgBouncer Installer 004}} {{:windows:postgresql_pgbouncer_installer_005.png?400|pgBouncer Installer 005}}\\{{:windows:postgresql_pgbouncer_installer_006.png?400|pgBouncer Installer 006}} {{:windows:postgresql_pgbouncer_installer_007.png?400|pgBouncer Installer 007}}
- PostGIS インストーラーの [Next >] をクリックしてインストールを行う。\\ {{:windows:postgresql_postgis_installer_001.png?400|PostGIS Installer 001}}{{:windows:postgresql_postgis_installer_002.png?400|PostGIS Installer 002}}\\ {{:windows:postgresql_postgis_installer_003.png?400|PostGIS Installer 003}}
- 以下の問い合わせに [はい] で答える。\\
ラスター変換が機能するために必要な GDAL_DATA 環境変数を登録してもよろしいですか?
既存の設定がある場合、これは上書きされます。
{{:windows:postgresql_postgis_installer_004.png?400|PostGIS Installer 004}}
- 以下の問い合わせに [はい] で答える。\\
ラスタドライバはデフォルトで無効になっています。
変更するには POSTGIS_GDAL_ENABLED_DRIVERS 環境変数を設定する必要があり、
変更を有効にするには PostgreSQL サービスを再起動する必要があります。
POSTGIS_ENABLED_DRIVERS を共通ドライバ GTiff、PNG、JPEG、XYZ、DTED、USGSDEM、AAIGrid に設定しますか?
{{:windows:postgresql_postgis_installer_005.png?400|PostGIS Installer 005}}
- 以下の問い合わせに [はい] で答える。\\
dbからのラスタはデフォルトで無効になっています。
POSTGIS_ENABLE_OUTDB_RASTERS 環境変数を 1 に設定する必要があります。
データベースラスタを有効にしますか?
{{:windows:postgresql_postgis_installer_006.png?400|PostGIS Installer 006}}
- [Close] で PostGIS インストーラーを終了する。\\ {{:windows:postgresql_postgis_installer_007.png?400|PostGIS Installer 007}}
- 全てのインストールが完了したら Application Stack Builder を終了する。\\ {{:windows:postgresql_application_stack_builder_008.png?400|Application Stack Builder 008}}
- 開発用に利用する場合は、タスクバーの「ここに入力して検索」に services.msc を入力して Enter キーを押す。
- 「サービス」より以下のサービスのスタートアップの種類を手動に設定しておく。
* postgresql-x64-x
* pgbouncer
- pgsql_start.cmd ファイルを作成して手動起動できるようにしておく。
powershell start-process net -argumentlist \"start postgresql-x64-x\" -verb runas
powershell start-process net -argumentlist \"start pgbouncer\" -verb runas
※**x** はインストールバージョンで置き換える。
- pgsql_stop.cmd ファイルを作成して手動停止できるようにしておく。
powershell start-process net -argumentlist \"stop postgresql-x64-x\" -verb runas
powershell start-process net -argumentlist \"stop pgbouncer\" -verb runas
※**x** はインストールバージョンで置き換える。
==== pgBouncer の設定 ====
- pgbouncer_edit.cmd ファイルを作成して、設定を編集できるようにしておく。
powershell start-process notepad -argumentlist \"C:\\Program Files (x86)\\PgBouncer\\share\\pgbouncer.ini\" -verb runas
- pgbouncer.ini の以下の部分を修正する。
[databases]
database_name = host=localhost dbname=database_name user=user_name password=********
; any, trust, plain, crypt, md5
auth_type = any
;auth_file = 8.0/main/global/pg_auth
;auth_file = C:\Program Files (x86)\PgBouncer\etc\userlist.txt
- pgBouncer サービスを再起動して設定を反映させる。
==== アプリの設定 ====
- pgBouncer を利用するには、6432 ポートを利用するように設定する。
- DB に接続できない場合は以下のログを確認する。
C:\Program Files (x86)\PgBouncer\log\pgbouncer.log