本投稿ではPostgreSQLをWindows Server 2016 へインストールします。
インストールするPostgreSQLは2020年3月時点で最新バージョンである「12.2」です。
また、PgAdmin4への接続、psqlの環境変数設定について紹介します。
インストーラーの取得
-PostgreSQLのダウンロードサイトにアクセスする。
-「Binary packages」のWindowsリンクをクリックする。

–Download the installer をクリックする。

-PostgreSQL Version12.2のWindows x86-64のDownloadリンクをクリックする。

-postgresql-12.2-1-windows-x64.exeがダウンロードされます。

インストールの実施
-postgresql-12.2-1-windows-x64.exeを実行し、[Next >]をクリックする。

-インストールフォルダを指定して[Next >]をクリックする。
デフォルト: C:\Program Files\PostgreSQL\12

-コンポーネントを選択し、[Next >]をクリックする。

-データの保存フォルダを指定して[Next >]をクリックする。
デフォルト:C:\Program Files\PostgreSQL\12\data
指定したフォルダ:D:\Program Files\PostgreSQL\12\data

-postgresユーザのパスワードを設定し[Next >]をクリックする。

-ポートを指定し、[Next >]をクリックする。
デフォルト:5432

-「Locale」に[Japanese, Japan]を指定して[Next >]をクリックする。

-設定内容を確認し[Next >]をクリックする。

-[Next >]をクリックする。

-チェックボックスのチェックを外して[Finish]をクリックする。

postgresql.conf の編集
ローカルホストのみが接続できるようになるので必要に応じて設定する。
-以下のファイルを開く。
D:\Program Files\PostgreSQL\12\data¥postgresql.conf
-以下の通りファイルを編集する。
listen_addresses = ‘*’ ⇒ listen_addresses = ‘localhost’
SQL Shell(psql)の接続確認
-[Windows]キーを押下し、[PostgreSQL 12]>[SQL Shell (psql)]をクリックする。

-以下の通り値を入力していく。
Server [localhost]: localhost
Database [postgres]: postgres
Port [5432]: 5432
Username [postgres]: postgres
Client Encoding [SJIS]: sjis
ユーザ postgres のパスワード: ***********

参考:psqlエラー SSL無効用のエントリがありません
以下のエラーが発生した際はIPv6が無効になっていないかを確認し、無効になっている場合は有効にしてください。
psql: エラー: サーバに接続できませんでした: FATAL: pg_hba.conf にホスト”fe80::2072:3cbc:53ef:f932%5″、ユーザ”postgres” 、データベース”postgres, SSL無効用のエントリがありません
CMDでpsqlコマンドを使えるようにする(環境変数の設定)
psqlコマンドをコマンドプロンプトから実行するには環境変数を設定する必要があります。
-[コントロールパネル]>[システムとセキュリティ]>[システム]>[システムの詳細設定]>[環境変数]をクリックする。

-変数Pathにて[編集]をクリックする。
[新規]をクリックし以下を入力後、[OK]をクリックする。
C:\Program Files\PostgreSQL\12\bin

-環境変数画面とシステムのプロパティを閉じる。
-CMDを起動し、以下を入力する。
> psql -U postgres
ユーザー postgres のパスワード: *********

PgAdmin4への接続
-[サーバーマネージャー]>[IEセキュリティ強化の構成]を[無効]にする。

-[Windows]キーを押下し、[PostgreSQL 12]>[pgAdmin 4]をクリックする。

-パスワードを入力し、[OK]をクリックする。

-ダッシュボード画面が表示されることを確認する。

参考:PgAdmin4のエラー
PgAdmin4を実行したところ以下エラーで接続できなかった。

Unauthorized
The server could not verify that you are authorized to access the URL requested. You either supplied the wrong credentials (e.g. a bad password), or your browser doesn’t understand how to supply the credentials required.
上記エラーは「IE セキュリティ強化の構成」をオフにすることで対処できます。
思ったより長くなってしまったので今回はここまで。
次回は以下を投稿していきます。
- PostgreSQLへクライアント端末から接続する。
- サンプルデータベース dvdrental の作成。
コメント