1、查看系统版本
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
2、进入postgresql官网https://www.postgresql.org/download/linux/redhat/
3、选择安装的版本、平台(这里选择RedHat Enterprise)、架构(这里选择64位)
![d01fb5860aace3cd4f40ee02d6d40f6a.png](https://img-blog.csdnimg.cn/img_convert/d01fb5860aace3cd4f40ee02d6d40f6a.png)
4、安装rpm包
[root@localhost ~]# yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-6-x86_64/pgdg-redhat-repo-latest.noarch.rpm
Loaded plugins: fastestmirror, langpacks
pgdg-redhat-repo-latest.noarch.rpm | 5.5 kB 00:00:00
Examining /var/tmp/yum-root-hIJ7mi/pgdg-redhat-repo-latest.noarch.rpm: pgdg-redhat-repo-42.0-4.noarch
Marking /var/tmp/yum-root-hIJ7mi/pgdg-redhat-repo-latest.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package pgdg-redhat-repo.noarch 0:42.0-4 will be installed
--> Finished Dependency Resolution
base/7/x86_64 | 3.6 kB 00:00:00
extras/7/x86_64 | 3.4 kB 00:00:00
updates/7/x86_64 | 3.4 kB 00:00:00
updates/7/x86_64/primary_db | 6.5 MB 00:00:01
Dependencies Resolved
====================================================================================================================================================
Package Arch Version Repository Size
====================================================================================================================================================
Installing:
pgdg-redhat-repo noarch 42.0-4 /pgdg-redhat-repo-latest.noarch 6.8 k
Transaction Summary
====================================================================================================================================================
Install 1 Package
Total size: 6.8 k
Installed size: 6.8 k
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : pgdg-redhat-repo-42.0-4.noarch 1/1
Verifying : pgdg-redhat-repo-42.0-4.noarch 1/1
Installed:
pgdg-redhat-repo.noarch 0:42.0-4
Complete!
5、安装客户端
[root@localhost ~]# yum install postgresql11Loaded plugins: fastestmirror, langpacksLoading mirror speeds from cached hostfile * base: mirror.bit.edu.cn * extras: mirrors.aliyun.com * updates: mirrors.huaweicloud.compgdg10 | 3.6 kB 00:00:00 pgdg11 | 3.6 kB 00:00:00 pgdg94 | 3.6 kB 00:00:00 pgdg95 | 3.6 kB 00:00:00 pgdg96 | 3.6 kB 00:00:00 (1/10): pgdg11/7/x86_64/group_gz | 245 B 00:00:01 (2/10): pgdg94/7/x86_64/group_gz | 247 B 00:00:01 (3/10): pgdg95/7/x86_64/group_gz | 249 B 00:00:00 (4/10): pgdg10/7/x86_64/group_gz | 245 B 00:00:02 (5/10): pgdg96/7/x86_64/group_gz | 249 B 00:00:00 (6/10): pgdg94/7/x86_64/primary_db | 301 kB 00:00:02 (7/10): pgdg11/7/x86_64/primary_db | 227 kB 00:00:06 (8/10): pgdg95/7/x86_64/primary_db | 295 kB 00:00:04 (9/10): pgdg10/7/x86_64/primary_db | 280 kB 00:00:07 (10/10): pgdg96/7/x86_64/primary_db | 298 kB 00:00:08 Resolving Dependencies--> Running transaction check---> Package postgresql11.x86_64 0:11.4-1PGDG.rhel7 will be installed--> Processing Dependency: postgresql11-libs(x86-64) = 11.4-1PGDG.rhel7 for package: postgresql11-11.4-1PGDG.rhel7.x86_64--> Processing Dependency: libpq.so.5()(64bit) for package: postgresql11-11.4-1PGDG.rhel7.x86_64--> Running transaction check---> Package postgresql11-libs.x86_64 0:11.4-1PGDG.rhel7 will be installed--> Finished Dependency ResolutionDependencies Resolved==================================================================================================================================================== Package Arch Version Repository Size====================================================================================================================================================Installing: postgresql11 x86_64 11.4-1PGDG.rhel7 pgdg11 1.6 MInstalling for dependencies: postgresql11-libs x86_64 11.4-1PGDG.rhel7 pgdg11 361 kTransaction Summary====================================================================================================================================================Install 1 Package (+1 Dependent package)Total download size: 2.0 MInstalled size: 10 MIs this ok [y/d/N]: yDownloading packages:warning: /var/cache/yum/x86_64/7/pgdg11/packages/postgresql11-libs-11.4-1PGDG.rhel7.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 442df0f8: NOKEYPublic key for postgresql11-libs-11.4-1PGDG.rhel7.x86_64.rpm is not installed(1/2): postgresql11-libs-11.4-1PGDG.rhel7.x86_64.rpm | 361 kB 00:00:18 (2/2): postgresql11-11.4-1PGDG.rhel7.x86_64.rpm | 1.6 MB 00:00:57 ----------------------------------------------------------------------------------------------------------------------------------------------------Total 36 kB/s | 2.0 MB 00:00:57 Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-PGDGImporting GPG key 0x442DF0F8: Userid : "PostgreSQL RPM Building Project " Fingerprint: 68c9 e2b9 1a37 d136 fe74 d176 1f16 d2e1 442d f0f8 Package : pgdg-redhat-repo-42.0-4.noarch (installed) From : /etc/pki/rpm-gpg/RPM-GPG-KEY-PGDGIs this ok [y/N]: yRunning transaction checkRunning transaction testTransaction test succeededRunning transaction Installing : postgresql11-libs-11.4-1PGDG.rhel7.x86_64 1/2 Installing : postgresql11-11.4-1PGDG.rhel7.x86_64 2/2 Verifying : postgresql11-11.4-1PGDG.rhel7.x86_64 1/2 Verifying : postgresql11-libs-11.4-1PGDG.rhel7.x86_64 2/2 Installed: postgresql11.x86_64 0:11.4-1PGDG.rhel7 Dependency Installed: postgresql11-libs.x86_64 0:11.4-1PGDG.rhel7 Complete!
6、安装server端
[root@localhost ~]# yum install postgresql11-server
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirror.bit.edu.cn
* extras: mirrors.aliyun.com
* updates: mirrors.huaweicloud.com
Resolving Dependencies
--> Running transaction check
---> Package postgresql11-server.x86_64 0:11.4-1PGDG.rhel7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
====================================================================================================================================================
Package Arch Version Repository Size
====================================================================================================================================================
Installing:
postgresql11-server x86_64 11.4-1PGDG.rhel7 pgdg11 4.7 M
Transaction Summary
====================================================================================================================================================
Install 1 Package
Total download size: 4.7 M
Installed size: 19 M
Is this ok [y/d/N]: y
Downloading packages:
postgresql11-server-11.4-1PGDG.rhel7.x86_64.rpm | 4.7 MB 00:03:22
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : postgresql11-server-11.4-1PGDG.rhel7.x86_64 1/1
Verifying : postgresql11-server-11.4-1PGDG.rhel7.x86_64 1/1
Installed:
postgresql11-server.x86_64 0:11.4-1PGDG.rhel7
Complete!
7、初始化数据库
[root@localhost ~]# /usr/pgsql-11/bin/postgresql-11-setup initdb
Initializing database ... OK
8、修改配置文件
[root@localhost data]# pwd
/var/lib/pgsql/11/data
[root@localhost data]# vim pg_hba.conf
![4de29d15353a13d0698ae4f5d1296223.png](https://img-blog.csdnimg.cn/img_convert/4de29d15353a13d0698ae4f5d1296223.png)
红框处第一行注释,添加第二行
9、启动数据库
[root@localhost ~]# systemctl enable postgresql-11
Created symlink from /etc/systemd/system/multi-user.target.wants/postgresql-11.service to /usr/lib/systemd/system/postgresql-11.service.
[root@localhost ~]# systemctl start postgresql-11
10、设置postgres用户密码
![def7d62daeb76589d8add6d8818185f0.png](https://img-blog.csdnimg.cn/img_convert/def7d62daeb76589d8add6d8818185f0.png)
11、连接
![a26a368dbce2431718578190f900c5ee.png](https://img-blog.csdnimg.cn/img_convert/a26a368dbce2431718578190f900c5ee.png)
OK,现在可以正常使用了