一、安装
可以参考postgresql官网安装教程:https://www.postgresql.org/download/linux/redhat/

二、创建用户和数据库
# su - postgres -- 首先切换到postgres
-bash-4.1$ psql -- 输入psql
psql (10.5)
Type "help" for help.
postgres=#
创建用户
postgres=# create user username with password '****'; CREATE ROLE postgres=#
需要注意:
1. 要以英文分号结尾
2.密码需要引号包裹
创建数据库
postgres=# create database dbtest owner username; -- 创建数据库指定所属者 CREATE DATABASE postgres=#
将数据库得权限,全部赋给某个用户
postgres=# grant all on database dbtest to username; -- 将dbtest所有权限赋值给username GRANT postgres=#
PostgreSQL安装完成后是不能从本机之外的机器连接的
按以下步骤修改配置
1,安装目录/data/pg_hba.conf
host all all 192.168.0.0/16 md5
加入一行允许内网IP访问
2,安装目录/data/postgresql.conf
listen_addresses = '*'
在这里加入星号允许访问
3,重启postgres服务
4,防火墙打开端口,以CentOS7为例
sudo firewall-cmd --permanent --zone=public --add-port=5432/tcp
sudo firewall-cmd --reload
本文详细介绍PostgreSQL数据库的安装步骤,包括在RedHat系统上的安装教程链接,以及如何创建用户和数据库。此外,还提供了调整配置以允许远程连接的方法,涉及pg_hba.conf和postgresql.conf文件的修改,并说明了如何重启服务及开放防火墙端口。
1474

被折叠的 条评论
为什么被折叠?



