参考博客:https://blog.csdn.net/qianglei6077/article/details/94379298
如果CentOS上已经自带了postgresql,一般版本比较低,在安装新版本前需要将旧版本pgsql卸载。
[root@CentOS7-3 ~]# rpm -qa|grep postgre postgresql-libs-9.2.23-3.el7_4.x86_64 postgresql-server-9.2.23-3.el7_4.x86_64 postgresql-9.2.23-3.el7_4.x86_64 postgresql-docs-9.2.23-3.el7_4.x86_64 --要安装以下顺序依次卸载,否则会报依赖错误 [root@CentOS7-3 ~]# rpm -e postgresql-server-9.2.23-3.el7_4.x86_64 [root@CentOS7-3 ~]# rpm -e postgresql-docs-9.2.23-3.el7_4.x86_64 [root@CentOS7-3 ~]# rpm -e postgresql-9.2.23-3.el7_4.x86_64 [root@CentOS7-3 ~]# rpm -e postgresql-libs-9.2.23-3.el7_4.x86_64
[root@CentOS7-3 ~]# yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
[root@CentOS7-3 ~]# yum search postgresql13 // 后边一路 y 即可
[root@CentOS7-3 ~]# yum install postgresql13-server
[root@pg ~]# /usr/pgsql-13/bin/postgresql-13-setup initdb Initializing database ... OK
[root@CentOS7-3 ~]# systemctl enable postgresql-13 Created symlink from /etc/systemd/system/multi-user.target.wants/postgresql-13.service to /usr/lib/systemd/system/postgresql-13.service
[root@CentOS7-3 ~]#systemctl start postgresql-13
[root@CentOS7-3 ~]# su - postgres -bash-4.2$ psql psql (13.4) 输入 "help" 来获取帮助信息. # 查询版本 postgres=# select version(); version --------------------------------------------------------------------------------------------- ------------ PostgreSQL 13.4 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5- 44), 64-bit (1 行记录) # 退出 postgres=# \q -bash-4.2$ exit 登出
# 首先进入pgsql客户端,然后创建root用户 postgres=#create user root with password 'password'; CREATE ROLE postgres=# GRANT ALL PRIVILEGES ON DATABASE mydatabase to root; GRANT postgres=# ALTER ROLE root WITH SUPERUSER;