LoginSignup
1

More than 5 years have passed since last update.

Postgres Package Managerを使ってみる

Last updated at Posted at 2017-09-01

Postgres Package Managerとは?

これまでWindows環境ではPostgreSQLをインストールするには、Interactive installer by EnterpriseDBしか選択肢がなかった気がしますが、Graphical installer by BigSQLもダウンロードページに出ていました。

EnterpriseDBのPostgreSQL 9.6を入れるとpgAdmin4になっていて使いづらかったりしましたが、BigSQLのインストーラーではpgAdmin3を選べて良い感じです。

BigSQLで9.6.4から9.6.5に上げようとインストーラーをダウンロードして起動したらエラーで止められて、何やらpgcを使ってアップデートして欲しいようです。

There has been an error.
An installation already exsists on this machine. It you are attempting to upgrade your installation, please use the PGCLI instead.

Information related to upgrading an exsisting installation via the PGCLI can be found at the following URL:

                https://bigsql.org/upgrade_windows

If you require another version of PostgreSQL on this machine, please install it via the PGCLI

Documentation for the PGCLI can be found at the following URL:

              https://bitbucket.org/openscg/pgcli

Graphical installer by BigSQLでインストールするとpgcというPostgres Package Managerのコマンドが含まれているらしく、PostgreSQLのアップデートやその他の管理をコマンドラインで行うことができるようです。

pgcのインストール

せっかくなので全部アンインストールして pgc のインストールから行ってみます。

公式のSetting startedなページを見るとコマンド一発でpgcをインストールできるように見えます。

注意:インストールスクリプト実行時のカレントディレクトリ

インストールのコマンドは、コマンドプロンプトを管理者権限で起動する必要があります。
Windowsキー+xでさくっと起動してコマンドを実行したくなりますが、カレントディレクトリ\bigsql\pgc にインストールされてしまうので C:\WINDOWS\system32\bigsql\pgcに入れられたりします。他の場所に移し直すだけで良さそうですが。

mkdir C:\pgc && cd C:\pgc
@powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString('https://s3.amazonaws.com/pgcentral/install.ps1'))"

このようにC:\pgcディレクトリを作成、カレントディレクトリにしてインストールスクリプトを実行すると、C:\pgc\bigsql\pgc.batがpgcコマンドになります。

PostgreSQLその他のインストール

※以下、pgcコマンドの使い方はWindows以外(macOS)でも同じです。
pgc listで利用可能なコンポーネントの一覧が出ます。

Category     | Component | Version  | ReleaseDt  | Status    | Updates
PostgreSQL     pg92        9.2.23-1   2017-08-31
PostgreSQL     pg93        9.3.19-1   2017-08-31
PostgreSQL     pg94        9.4.14-1   2017-08-31
PostgreSQL     pg95        9.5.9-1    2017-08-31
PostgreSQL     pg96        9.6.5-1    2017-08-31
Servers        pgdevops    1.6-3      2017-08-10
Applications   backrest    1.20       2017-07-31
Applications   ora2pg      18.1       2017-03-23
Applications   pgadmin3    1.23.0b    2017-06-08
Applications   pgagent     3.4.1-1    2017-02-23
Applications   pgbadger    9.2        2017-07-31
Frameworks     java8       8u121      2017-02-09
Frameworks     perl5       5.20.3.3   2016-03-14
Frameworks     python2     2.7.12-1   2016-10-20   Installed
Frameworks     tcl86       8.6.4-1    2016-03-11

PostgreSQL 9.6.xとpgAdmin3を入れてみます。
pgc install pg96
pgc install pgadmin3

Category     | Component           | Version  | ReleaseDt  | Status         | Updates
PostgreSQL     pg92                  9.2.23-1   2017-08-31
PostgreSQL     pg93                  9.3.19-1   2017-08-31
PostgreSQL     pg94                  9.4.14-1   2017-08-31
PostgreSQL     pg95                  9.5.9-1    2017-08-31
PostgreSQL     pg96                  9.6.5-1    2017-08-31   NotInitialized
Extensions     cassandra_fdw3-pg96   3.0.1-1    2016-11-08
Extensions     hadoop_fdw2-pg96      2.5.0-1    2016-09-01
Extensions     oracle_fdw1-pg96      1.5.0-1    2016-09-01
Extensions     orafce3-pg96          3.4.0-1    2017-07-13
Extensions     pgaudit11-pg96        1.1.0-2    2017-05-18
Extensions     pgpartman2-pg96       2.6.4-1    2017-04-15
Extensions     pldebugger96-pg96     9.6.0-1    2016-12-28
Extensions     plprofiler3-pg96      3.2-1      2017-04-15
Extensions     postgis23-pg96        2.3.3-2    2017-07-31
Extensions     setuser1-pg96         1.4.0-1    2017-08-31
Extensions     tds_fdw1-pg96         1.0.8-1    2016-11-23
Servers        pgdevops              1.6-3      2017-08-10
Applications   backrest              1.20       2017-07-31
Applications   ora2pg                18.1       2017-03-23
Applications   pgadmin3              1.23.0b    2017-06-08   Installed
Applications   pgagent               3.4.1-1    2017-02-23
Applications   pgbadger              9.2        2017-07-31
Frameworks     java8                 8u121      2017-02-09
Frameworks     perl5                 5.20.3.3   2016-03-14
Frameworks     python2               2.7.12-1   2016-10-20   Installed
Frameworks     tcl86                 8.6.4-1    2016-03-11

入りましたがNotInitializedと表示されています。
pgc init pg96でInstalledになりました。ここでSuperuser(postgresユーザ)のパスワード設定も行います。
pgc startでPostgreSQLが起動します。
pgc stopで停止します。
pgc statusで動いているのか止まっているのか確認できます。

サービスとして起動する

インストーラーでインストールした時の様にサービスとして動かすには
pgc config pg96 --autostart=on
を実行するとサービスが作成されます。
作成されるだけなのですぐ使う場合は pgc start pg96 を実行するとサービスが起動します。

バージョンアップ

リビジョンアップデート

pgc update
pgc upgrade

明示的にstopしなくてもupgradeできました。

メジャー、マイナーアップデート

pgcではメジャーバージョンやマイナーバージョンの番号が変わると別パッケージとして扱われているので、新しいパッケージをインストールしてデータを移します。(pgcからのdbdump等は使い方がよくわからないので止めておきます。。。)

動いているのを止める。

pgc stop pg96
pgc config pg96 --autostart=off
pgc disable pg96

disableはパッケージの扱いがdisableになるだけのようで、サーバー動作止める、サービス削除、パッケージ無効と手順を踏んだほうがよさそうです。

pgcコマンドの使い方を探る

ドキュメントはどこにあるの?

pgc config

pgc config pg96 --autostart=onの他に何を設定できるのか。
実装は各パッケージ内のpg96\config-pg96.pyにあるっぽい。
これを見ると使えるオプションは次の通り。

オプション例 内容
--port=5432 ポート番号を5432に設定する。
--autostart=on PostgreSQLサービス作成。(=offでサービス削除)
--datadir=
--logdir=
--svcname=

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1