Centos 7 安装 Postgresql数据库

敲入以下命令

# 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 postgresql14-server

# Optionally initialize the database and enable automatic start:
sudo /usr/pgsql-14/bin/postgresql-14-setup initdb
sudo systemctl enable postgresql-14
sudo systemctl start postgresql-14

其他系统可以根据官网文档进行查阅

# 切换postgres用户
sudo su - postgres
##开启远程访问
#修改配置文件  取消 listen_addresses 的注释,将参数值改为“*”
vi /var/lib/pgsql/14/data/postgresql.conf
#修改配置文件  增加一行 host   all   all   0.0.0.0/0   md5
vi /var/lib/pgsql/14/data/pg_hba.conf

#打开客户端,创建用户、数据库及用户授权
psql
create user test_zack with password '123456';
create database test_db owner test_zack;
grant all privileges on database test_db to test_zack;

#重启服务
sudo systemctl restart postgresql-14

 

posted @ 2022-08-10 17:36  風飄絮℃  阅读(269)  评论(0编辑  收藏  举报