LoginSignup
0
0

More than 1 year has passed since last update.

cent os 7.6 に postgreSQL 9.2 が入っている状態で postgreSQL 13.3 をインストールする

Posted at

postgreSQL9.2 が入っている状態で postgre13.3をインストールします。

1.postgreSQL 9.2 の状態確認

postgre9.2はデフォルトインストール状態として以下のようになっています。

設定項目 設定値(デフォルト)
TCP使用ポート 5432
データディレクトリ /var/lib/pgsql/data
postgre9.2_dir&port
[root@cent76-d1 ~]# cat /usr/lib/systemd/system/postgresql.service

《中略》

# Port number for server to listen on
Environment=PGPORT=5432

# Location of database directory
Environment=PGDATA=/var/lib/pgsql/data

《中略》

[root@cent76-d1 ~]#

2.postgreSQL 13.3 のインストール

インターネット接続環境下で、リポジトリをダウンロードしたりしながらインストールをします。
(以下の「1.postgreSQLのインストール」に同じ)

repo_install
[root@cent76-d1 ~]# yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
yum_install
[root@cent76-d1 ~]# yum install -y postgresql13-server

《中略》

================================================================================================================
 Package                                アーキテクチャー      バージョン               リポジトリー        容量
================================================================================================================
インストール中:
 postgresql13-server                    x86_64                13.3-1PGDG.rhel7         pgdg13             5.4 M
依存性関連でのインストールをします:
 postgresql13                           x86_64                13.3-1PGDG.rhel7         pgdg13             1.4 M
 postgresql13-libs                      x86_64                13.3-1PGDG.rhel7         pgdg13             380 k

トランザクションの要約
================================================================================================================
インストール  1 パッケージ (+2 個の依存関係のパッケージ)

総ダウンロード容量: 7.2 M
インストール容量: 30 M

《中略》

インストール:
  postgresql13-server.x86_64 0:13.3-1PGDG.rhel7                                                                                                                                    

依存性関連をインストールしました:
  postgresql13.x86_64 0:13.3-1PGDG.rhel7                                                postgresql13-libs.x86_64 0:13.3-1PGDG.rhel7                                               

完了しました!
[root@cent76-d1 ~]# 

3.postgreSQL 13.3 起動前config変更と起動

postgreSQL 13.3 をプレーンなまま起動すると以下の表のとおりになります。
ただ、TCP使用ポートがpostgreSQL 9.2 と重複する場合は、13.3が起動しないので変更します。
(データディレクトリはpostgreSQL 9.2 と被らないため問題ありません)

設定項目 設定値(デフォルト)
TCP使用ポート 5432
データディレクトリ /var/lib/pgsql/13/data/

 ↓変更

設定項目 設定値
TCP使用ポート 5330
データディレクトリ /pgdata/13/data

※ポート番号5330は 5 + 13.30
※変更先データディレクトリについてはpostgreユーザかつ権限700で事前に作成。

まずはサービス設定ファイルを変更します。
/usr/lib/systemd/system/postgresql-13.service
※なお、元設定をコメントアウトするだけだとうまく動かないので、設定は上書きします。

change_postgresql-13.service
# Location of database directory
Environment=PGDATA=/var/lib/pgsql/13/data/

 ↓変更

# Location of database directory
Environment=PGDATA=/pgdata/13/data/

initdbを行い、データディレクトリに初期DBおよび設定ファイル群を展開します。

initdb
[root@cent76-d1 ~]# /usr/pgsql-13/bin/postgresql-13-setup initdb
Initializing database ... OK

[root@cent76-d1 ~]# 

この状態でpostgreSQL 13.3 を起動しようとすると、TCPポート重複により起動しません。

postgresql13.3_start_error
[root@cent76-d1 ~]# systemctl start postgresql-13
Job for postgresql-13.service failed because the control process exited with error code. See "systemctl status postgresql-13.service" and "journalctl -xe" for details.
[root@cent76-d1 ~]# 

続いてはpostgresql.confを変更します。
なお、当該の設定ファイルは変更先のデータディレクトリに作成されているので注意。
/pgdata/13/data/postgresql.conf

change_postgresql.conf
#port = 5432                            # (change requires restart)

 ↓変更

port = 5330                             ### CUSTOM ADD ###
#port = 5432                            # (change requires restart)

ポート変更後、postgreSQL 13.3 を起動すると正常に実行されます。

postgresql13.3_start_success
[root@cent76-d1 ~]# systemctl start postgresql-13
[root@cent76-d1 ~]# 

[root@cent76-d1 ~]# systemctl status postgresql-13
● postgresql-13.service - PostgreSQL 13 database server
   Loaded: loaded (/usr/lib/systemd/system/postgresql-13.service; enabled; vendor preset: disabled)
   Active: active (running) since 土 2021-06-12 13:24:50 JST; 20s ago
     Docs: https://www.postgresql.org/docs/13/static/
  Process: 28689 ExecStartPre=/usr/pgsql-13/bin/postgresql-13-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)
 Main PID: 28694 (postmaster)
   CGroup: /system.slice/postgresql-13.service
           tq28694 /usr/pgsql-13/bin/postmaster -D /pgdata/13/data
           tq28696 postgres: logger 
           tq28698 postgres: checkpointer 
           tq28699 postgres: background writer 
           tq28700 postgres: walwriter 
           tq28701 postgres: autovacuum launcher 
           tq28702 postgres: stats collector 
           mq28703 postgres: logical replication launcher 

 6月 12 13:24:50 cent76-d1 systemd[1]: Starting PostgreSQL 13 database server...
 6月 12 13:24:50 cent76-d1 postmaster[28694]: 2021-06-12 13:24:50.644 JST [28694] LOG:  ログ出力をログ収集プロセスにリダイレクトしています
 6月 12 13:24:50 cent76-d1 postmaster[28694]: 2021-06-12 13:24:50.644 JST [28694] ヒント:  ここからのログ出力はディレクトリ"log"に現れます。
 6月 12 13:24:50 cent76-d1 systemd[1]: Started PostgreSQL 13 database server.
[root@cent76-d1 ~]# 

異なるバージョンのpostgreSQLを併存させることに成功しました。

0
0
0

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
0
0