**一.**安装存储库RPM
yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
二.使用yumdownloader下载安装包
mkdir pg_yum
cd pg_yum
yumdownloader --resolve postgresql13-server
**三.**上传rpm包到安装的centos服务器上
scp -r pg_yum/ <目标服务器IP>:/home/
**三.**批量安装rpm包
rpm -ivh postgresql13-13.14-1PGDG.rhel7.x86_64.rpm postgresql13-libs-13.14-1PGDG.rhel7.x86_64.rpm postgresql13-server-13.14-1PGDG.rhel7.x86_64.rpm
1.如果报错,缺少依赖libicu
warning: postgresql13-13.4-1PGDG.rhel7.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 442df0f8: NOKEY
error: Failed dependencies:
libicu is needed by postgresql13-13.4-1PGDG.rhel7.x86_64
libicui18n.so.50()(64bit) is needed by postgresql13-server-13.4-1PGDG.rhel7.x86_64
libicuuc.so.50()(64bit) is needed by postgresql13-server-13.4-1PGDG.rhel7.x86_64
**3.**使用yumdownloader下载libicu
mkdir libicu
cd libicu
yumdownloader --resolve libicu
删除libicu-50.2-4.el7_7.i686.rpm。
**4.**上传到需要安装的服务器,执行安装命令
scp -r pg_yum/ <目标服务器IP>:/home/
cd libicu
rpm -ivh libicu-50.2-4.el7_7.x86_64.rpm
然后再安装pgsql
cd ../pg_yum/
rpm -ivh postgresql13-13.14-1PGDG.rhel7.x86_64.rpm postgresql13-libs-13.14-1PGDG.rhel7.x86_64.rpm postgresql13-server-13.14-1PGDG.rhel7.x86_64.rpm
**四.**安装成功后初始化数据库
/usr/pgsql-13/bin/postgresql-13-setup initdb
**五.**启动postgresql数据库
systemctl enable postgresql-13
systemctl start postgresql-13
六.配置postgres用户密码,开放端口
su - postgres
psql
ALTER USER postgres WITH PASSWORD 'new_password';
#退出
\q
#防火墙开放端口
firewall-cmd --add-port=5432/tcp --permanent
firewall-cmd --reload