通过yum安装postgresql相关包sudoyuminstall-ypostgresqlpostgresql-serverpostgresql96-develpostgresql-contribpostgresql-docs初始化数据库sudoservicepostgresqlinitdb//根据安装的版本判断postgresql的版本eg:sudoservicepostgresql96initdb启动数据库sudoservicepostgresqlstartcreateuseranddata//首先登录postgres用户sudosupostprespsql//输入前面的命令输入psql,可以输入sql语句createusertestuserwithpassword'testpwd';//创建数据库创建数据库testdb所有者testuser;//授予用户操作数据库的权限grant数据库testdb的所有权限给testuser;\qexit//修改配置文件,设置数据可以远程访问sudocd/var/lib/pgsql/data//编辑文件sudovimpostgresql.conf修改文件listen_addresses='localhost'为listen_addresses='*'修改文件pg_hba.conf在文件底部添加一行hostallall0.0.0.0/0md5//重启服务注意:检查是否有权限数据文件的of是700,如果不修改为700sudochmod700/var/bin/data/sudoservicerestartpostgresqltestconnectionpsql-h*.*.*.*-dtestdb-Utestuser可能会遇到错误Peer用户“postgres”的身份验证失败解决方法sudovim/var/lib/pgsql/data/pg_h将ba.confhostallallpeer更改为hostallalltr??ust
