
官网:https://www.postgresql.org/download/linux/redhat/
下载rpm包
# yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm # yum list | grep postgresql postgresql10-server【postgresql的服务端】 postgresql10-contrib【postgresql的extension,提供较多的拓展功能】 postgresql10【postgresql的数据库工具组件,包含很多管理数据库组件】 postgresql10-libs【postgresql的动态库,依赖安装】 postgresql10-odbc【postgresql的odbc相关组件】 postgresql10-plperl【postgresql的PL/Perl,如果使用Perl开发函数,需要安装】 postgresql10-plpython【postgresql的PL/python,如果使用python开发函数,需要安装】 postgresql10-pltcl【postgresql的PL/tcl,如果使用tcl开发函数,需要安装】 postgresql10-devel【postgresql的开发包,包含.h头文件等】 postgresql10-test【postgresql的回归测试组件】 postgresql10-docs【postgresql的说明文档】
安装
//yum install postgresql11 //客户端 //yum install postgresql11-server //服务 //yum install postgresql11-contrib //服务工具 # yum -y install postgresql11-server postgresql11-contrib //其他不装
初始化数据库
# /usr/pgsql-11/bin/postgresql-11-setup initdb
服务器相关的命令
# systemctl enable postgresql-11 # systemctl start postgresql-11
修改用户密码
# su postgres //切换用户,执行后提示符会变为 '-bash-4.2$' bash-4.2$psql -U postgres //登录数据库,执行后提示符变为 'postgres=#' postgres=#ALTER USER postgres WITH PASSWORD 'xxx' //设置postgres用户密码为postgres ALTER ROLE postgres=#\q //退出数据库 # systemctl restart postgresql-11 //重启服务器
开启远程访问
# vi /var/lib/pgsql/10/data/postgresql.conf //修改#listen_addresses = 'localhost' 为listen_addresses='*' 当然,此处'*'也可以改为任何你想开放的服务器IP
信任远程连接
# vi /var/lib/pgsql/11/data/pg_hba.conf //在文件末尾加上,如果不加上远程连接PostgreSQL会出现no pg_hba.conf…的错误 host all all 0.0.0.0/0 trust
重启
# service postgresql-11 restart