postgresql14 Linux installation steps

Create Postgre user group
[root@MiWiFi-R4AC-srv local]# useradd postgres
add Postgre user
useradd -g postgres postuser1
update
sudo yum update
# install repository 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
 #Install PostgreSQL14
[root@MiWiFi-R4AC-srv local]# sudo yum install -y postgresql14-server
#Initialize PostgreSQL14
[root@MiWiFi-R4AC-srv local]# sudo /usr/pgsql-14/bin/postgresql-14-setup initdb #Add startup
[
root@MiWiFi-R4AC-srv local] ]# sudo systemctl enable postgresql-14
#Start postgresql
[root@MiWiFi-R4AC-srv local]# sudo systemctl start postgresql-14
#Firewall open port
Open the firewall 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
modify configuration file postgresql.conf 
[root@localhost 14]# vi /var/lib/pgsql/14/data/postgresql.conf 
#modify 
listen_addresses = '*'
#modify file pg_hba.conf 
[root@localhost 14 ]# vi /var/lib/pgsql/14/data/pg_hba.conf 
#Add a line 
#host all all 0.0.0.0/0 password
host all all 0.0.0.0/0 scram-sha-256
 restart PostgreSQL
 [root@localhost 14 ]# sudo systemctl restart postgresql-14
Check the running status
[root@localhost 14]# systemctl status postgresql-14
use user group
[root@localhost 14]# su - postgres
 enter and execute SQL command
[postgres@localhost ~]$ psql
modify password
alter user postgres with password 'mykey';

Exit
postgres=# \q # Exit or: exit;

Create user and password
postgres=# create user postuser with password 'mykey';
 create database
postgres=# create database merchantdb owner postuser;
 #authorize
postgres=# grant all on database merchantdb to postuser;
 

Guess you like

Origin blog.csdn.net/qq_38387996/article/details/129879445