PostgreSQL安装教程(CentOS)

发布时间:2022-07-01 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了PostgreSQL安装教程(CentOS)脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

PostgreSQL安装教程(CentOS)

一、安装教程

1.1 安装脚本

官网安装脚本查询:https://www.postgresql.org/download/linux/redhat/

PostgreSQL安装教程(CentOS)

 # Install the repository RPM: sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm ​ # Install PostgreSQL: sudo yum install -y postgresql10-server ​ # Optionally initialize the database and enable automatic start: sudo /usr/pgsql-10/bin/postgresql-10-setup initdb sudo systemctl enable postgresql-10 sudo systemctl start postgresql-10

二、创建用户和数据库

2.1 切换用户

使用postgres用户登录(PostgresSQL安装后会自动创建postgres用户,无密码)

 [root@localhost software]# su postgres bash-4.2$ 

2.2 登录postgresql数据库

 bash-4.2$ psql psql (10.16) 输入 "help" 来获取帮助信息.

2.3 创建用户和数据库并授权

 create user test_user with password 'abc123';            # 创建用户 create database test_db owner test_user;                 # 创建数据库 grant all privileges on database test_db to test_user;   # 授权

PostgreSQL安装教程(CentOS)

2.4 退出psql(输入 q 再按回车键即可)

 postgres=# q bash-4.2$ 

三、开启远程访问

3.1 修改监听地址

修改/var/lib/pgsql/10/data/postgresql.conf文件,取消 listen_addresses 的注释,将参数值改为“*”

 bash-4.2$ vim /var/lib/pgsql/10/data/postgresql.conf

PostgreSQL安装教程(CentOS)

3.2 添加本地连接地址

修改/var/lib/pgsql/10/data/pg_hba.conf文件,增加下图红框部分内容

 bash-4.2$ vim /var/lib/pgsql/10/data/pg_hba.conf

PostgreSQL安装教程(CentOS)

3.3 切换到root用户,重启postgresql服务

 bash-4.2$ su root 密码: [root@localhost software]# systemctl restart postgresql-10.service

3.4 使用数据库连接工具测试连接

PostgreSQL安装教程(CentOS)

四、其它补充

4.1修改postgres 用户密码

修改默认生成的 postgres 用户密码(此postgres非上面的postgres用户,此为数据库的用户,上面的为操作系统的用户)

su - postgrespsql -U postgresalter user postgres with encrypted password '1';

PostgreSQL安装教程(CentOS)

PostgreSQL安装教程(CentOS)

4.2 服务启动、关闭、重启、查看状态命令

systemctl start postgresql-10.service     # 启动服务systemctl stop postgresql-10.service      # 关闭服务systemctl restart postgresql-10.service   # 重启服务systemctl status postgresql-10.service    # 查看状态

 

脚本宝典总结

以上是脚本宝典为你收集整理的PostgreSQL安装教程(CentOS)全部内容,希望文章能够帮你解决PostgreSQL安装教程(CentOS)所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:数据库