在已安装 CentOS 7.6 系统下的 PostgreSQL 9.2 中,安装 PostgreSQL 13.3
在已经安装了PostgreSQL 9.2的情况下,将安装PostgreSQL 13.3。
检查 PostgreSQL 9.2 的状态。
以下是Postgre9.2的默认安装状态。
設定項目設定値(デフォルト)TCP使用ポート5432データディレクトリ/var/lib/pgsql/data
[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 ~]#
安装PostgreSQL 13.3
在互联网连接环境下,同时下载仓库并进行安装。(与以下的“1.安装PostgreSQL”相同)
[root@cent76-d1 ~]# yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
[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 ~]#
在启动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
请注意,仅仅将原始配置文件设置为注释状态可能无法正常工作,所以需要进行配置的覆盖。
# Location of database directory
Environment=PGDATA=/var/lib/pgsql/13/data/
↓変更
# Location of database directory
Environment=PGDATA=/pgdata/13/data/
执行initdb命令,在数据目录中解压初始数据库和配置文件。
[root@cent76-d1 ~]# /usr/pgsql-13/bin/postgresql-13-setup initdb
Initializing database ... OK
[root@cent76-d1 ~]#
在这种状态下,尝试启动 postgreSQL 13.3 时,由于 TCP 端口重复,无法启动。
[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
#port = 5432 # (change requires restart)
↓変更
port = 5330 ### CUSTOM ADD ###
#port = 5432 # (change requires restart)
更改了端口后,启动postgreSQL 13.3时能够正常运行。
[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并存在一起。