PostgreSQLのインストール
PostgreSQLのインストールにつまづいたので、ポイントを書いておきます。
- 環境
- Windows7
- PostgreSQL 9.2.4
ポイント1: .exeでインストールしてもPATHが通らない
.exeの標準設定でインストールして、ログインしようとすると、以下のようなエラーが出た。
C:\>psql -U postgres psql: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
バージョンを確認してみると、8.2.11??
C:\>psql --version psql (PostgreSQL) 8.2.11 contains support for command-line editing
何かのアプリケーションをインストールしたときにPostgreSQLもインストールされていて、それにアクセスしようとしていたようだ。
しかも.exeを実行してもPATHが設定されていなかった。
というわけで、スタート>コンピュータ>システムのプロパティ>システムの詳細設定>詳細設定>環境設定>システム環境設定>変数PATHの値にインストールしたパス(デフォルトでは"C:\Program Files\PostgreSQL\9.2\bin";)を先頭に加える。
ポイント2: ポート番号を合わせる
再びアクセスしようとすると下記のエラー。
C:\>psql -U postgres psql: could not connect to server: Connection refused (0x0000274D/10061) Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432? could not connect to server: Connection refused (0x0000274D/10061) Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5432?
dataの中にあるpostgresql.confからポートを確認すると、ポート番号が一致していない。
port = 5433 # (change requires restart)
以前インストールしたPostgreSQLが5432を使ってしまっていた。
以前のPostgreSQLには port = 5431 としてもらい、最新版を port = 5432 に変更して、保存して、再起動(pgAdminIIIからサービスの停止→サービスの再開)。
ポイント3: psqlとserverのバージョンを合わせる
やっと接続できた。が、psqlとserverのバージョンが異なるというWARNINGが出ている。
C:\>psql -U postgres psql (9.2.4, server 9.1.9) WARNING: psql version 9.2, server version 9.1. Some psql features might not work. Type "help" for help.
pgAdminIIIからPostgreSQL 9.1のサービスを停止し、PostgreSQL 9.2に接続でWARNINGが出なくなった。
C:\>psql -U postgres psql (9.2.4) Type "help" for help. postgres=# \q