Centos7.6安装PostgreSQL12.1

上个月双十一买的服务器,一上手就先安装个pg。其实作为个人开发的数据库来说,mysql和pg的差别不大。因为在公司用习惯pg了就它了吧。

1 安装步骤

1.1 安装RPM

yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

1.2 安装客户端

yum install postgresql12

1.3 安装服务端

yum install postgresql12-server

2 配置步骤

2.1 始化数据库并启用自动启动 (可选)

# 初始化数据库
/usr/pgsql-12/bin/postgresql-12-setup initdb

# 设置开机启动pg服务
systemctl enable postgresql-12

# 启动pg服务
systemctl start postgresql-12

2.2 修改PostgreSQL远程连接配置


vim /var/lib/pgsql/12/data/pg_hba.conf

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     peer
# IPv4 local connections:
#host    all             all             127.0.0.1/32            ident
host    all             all             127.0.0.1/32            trust
host    all             all             all                     md5
# IPv6 local connections:
#host    all             all             ::1/128                 ident
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local   replication     all                                     peer
host    replication     all             127.0.0.1/32            trust
host    replication     all             all                     md5

2.3 放开远程连接ip限制


vim /var/lib/pgsql/12/data/postgresql.conf

# - Connection Settings -

listen_addresses = '*'          # what IP address(es) to listen on;

3 修改账号密码

3.1 修改postgres账号密码

  • 使用postgres登入数据库
psql -h 127.0.0.1 -d postgres -U postgres
  • 修改postgres密码
alter user postgres with password 'postgres';

猜你喜欢

转载自blog.csdn.net/laichj/article/details/103756837