美文网首页
CentOs7 安装 PostgreSQL

CentOs7 安装 PostgreSQL

作者: 啊深是阿深啊 | 来源:发表于2021-03-31 22:53 被阅读0次

CentOs7 安装 PostgreSQL 13

#安装存储库RPM:
sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

# 安装PostgreSQL:
sudo yum install -y postgresql13-server

#(可选)初始化数据库
sudo /usr/pgsql-13/bin/postgresql-13-setup initdb

# 设置开机启动项
sudo systemctl enable postgresql-13
sudo systemctl start postgresql-13

创建用户和数据库

# 1、使用postgres用户登录(PostgresSQL安装后会自动创建postgres用户,无密码)
su - postgres
# 2、登录postgresql数据库  
psql
# 3、创建用户和数据库并授权
create user test_user with password '123456';
create database test_db owner test_user;
grant all privileges on database test_db to test_user;
# 4、退出psql(输入 \q 再按回车键即可)
\q

开启远程访问

vim /var/lib/pgsql/13/data/postgresql.conf
# 修改 listen_addresses
listen_addresses = ‘*’
# 修改 IPV4 local connections
vim  /var/lib/pgsql/13/data/pg_hba.conf
host all  all 0.0.0.0/0   md5
# 切换到root用户,重启postgresql服务
su - root
systemctl restart postgresql-13.service

修改默认生成的 postgres 用户密码

此postgres非上面的postgres用户,此为数据库的用户,上面的为操作系统的用户

su - postgres
psql -U postgres
alter user postgres with encrypted password '123456';

相关文章

网友评论

      本文标题:CentOs7 安装 PostgreSQL

      本文链接:https://www.haomeiwen.com/subject/mcczhltx.html