postgresql14 Linux安装步骤

创建Postgre 用户组
[root@MiWiFi-R4AC-srv local]# useradd postgres
添加Postgre用户
useradd -g postgres postuser1
更新
sudo yum update
#安装存储库RPM
[root@MiWiFi-R4AC-srv local]# sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
 #安装PostgreSQL14
[root@MiWiFi-R4AC-srv local]# sudo yum install -y postgresql14-server
#初始化PostgreSQL14
[root@MiWiFi-R4AC-srv local]# sudo /usr/pgsql-14/bin/postgresql-14-setup initdb
#添加开机启动
[root@MiWiFi-R4AC-srv local]# sudo systemctl enable postgresql-14
#启动postgresql
[root@MiWiFi-R4AC-srv local]# sudo systemctl start postgresql-14
#防火墙打开端口
开启防火墙 systemctl start firewalld ​
[root@MiWiFi-R4AC-srv local]# firewall-cmd --zone=public --add-port=5432/tcp --permanent
[root@MiWiFi-R4AC-srv local]#  firewall-cmd --reload
修改配置文件postgresql.conf 
[root@localhost 14]# vi /var/lib/pgsql/14/data/postgresql.conf 
#修改 
listen_addresses = '*'
#修改文件pg_hba.conf 
[root@localhost 14]# vi /var/lib/pgsql/14/data/pg_hba.conf 
#增加一行 
#host    all             all             0.0.0.0/0               password
host    all             all             0.0.0.0/0               scram-sha-256
 重启PostgreSQL
 [root@localhost 14]# sudo systemctl restart postgresql-14
检查运行状态
[root@localhost 14]# systemctl status postgresql-14
使用用户组
[root@localhost 14]# su - postgres
 进入执行SQL命令
[postgres@localhost ~]$ psql
修改密码
alter user postgres with password 'mykey';

退出
postgres=# \q   # 退出 or: exit;

创建用户和密码
postgres=# create user postuser with password 'mykey';
 创建数据库
postgres=# create database merchantdb owner postuser;
 #授权
postgres=# grant all on database merchantdb to postuser;
 

猜你喜欢

转载自blog.csdn.net/qq_38387996/article/details/129879445
今日推荐