CentOS7安装PostgresSQL14
参考:https://www.postgresql.org/download/linux/redhat/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# Install the repository RPM: shell>yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm # Install PostgreSQL: shell>yum install -y postgresql14-server # Optionally initialize the database and enable automatic start: shell>/usr/pgsql-14/bin/postgresql-14-setup initdb shell>systemctl enable postgresql-14 shell>systemctl start postgresql-14 # 修改超管账户postgres密码 shell>su - postgres $>psql postgres=# ALTER USER postgres WITH PASSWORD '此处替换为新密码'; #新建用户和数据库 postgres=# create user test_user with password 'abc123'; # 创建用户 postgres=# create database test_db owner test_user; # 创建数据库 postgres=# grant all privileges on database test_db to test_user; # 授权 #退出 postgres=# \q #开启远程连接 $>exit shell> vim /var/lib/pgsql/14/data/postgresql.conf listen_addresses = '*' shell> vim /var/lib/pgsql/14/data/pg_hba.conf host all all 127.0.0.1/32 scram-sha-256 改为 host all all 0.0.0.0/0 scram-sha-256 #切换到root用户,重启postgresql服务 shell> systemctl restart postgresql-14.service #其他服务命令 shell> systemctl start postgresql-14.service # 启动服务 shell> systemctl stop postgresql-14.service # 关闭服务 shell> systemctl restart postgresql-14.service # 重启服务 shell> systemctl status postgresql-14.service # 查看状态 |