centos7下通过yum安装postgresql12数据库

**假设系统环境初始化安装(zlib-devel bzip2-devel openssl-devel ncurses-devel
sqlite-devel readline-devel tk-devel libffi-devel gcc make python-devel postgresql-devel)均已完成(通过yum逐一安装)**

centos版本:CentOS Linux release 7.6.1810 (Core)

安装步骤:
```
# 安装postgresql服务
1. sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
2. sudo yum install -y postgresql12-server

# 创建数据保存目录并修改权限
1. mkdir /data
2. chown postgres:postgres /data
3. chmod -R 700 /data

# 切换到postgres用户初始化数据库
1. su - postgres # 如果提示无此用户需创建
2. /usr/pgsql-12/bin/initdb -D /data/
```
修改配置文件
```
1. cd /data/
2. vim pg_hba.conf
"""修改start"""
# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     trust
# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
host    all             all             0.0.0.0/0               md5
# IPv6 local connections:
host    all             all             ::1/128                 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     trust
host    replication     all             127.0.0.1/32            trust
host    replication     all             ::1/128                 trust
""""修改end"""
3. vim postgresql.conf
"""修改start"""
listen_addresses = '*'
port = 9000
"""修改end"""
```
启动数据库
```
1. cd # 进入postgres用户主目录
2. /usr/pgsql-12/bin/pg_ctl -D /data/ -l logfile start
```
修改postgres用户密码
```
1. psql -U postgres -p 9000 # 连接数据库,端口和上面配置文件一致
2. ALTER USER postgres WITH PASSWORD '123456';
```
创建数据库
```
1. create database test with encoding='utf-8';
2. \q # 退出
```
切换回root用户并关闭防火墙
```
1. su - root
2. systemctl stop firewalld
```
大功告成!
参考网址:https://www.jianshu.com/p/adbb652a8f22
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值