centos7安装postgresql11
版本:PostgreSQL 11.20
安装
yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
rpm -ql pgdg-redhat-repo
yum install postgresql11 postgresql11-server -y
配置用户信息
# 把自动创建的postgres用户删除
userdel -r postgres
groupadd -g 701 postgres
useradd -g 701 -u 701 -s /bin/bash -m postgres
passwd postgres
创建数据目录
su postgres
mkdir /home/postgres/pgdata
cd /home/postgres
vi .bashrc
export PATH=/usr/pgsql-11/bin:$PATH
export LD_LIBRARY_PATH=/usr/pgsql-11/lib:$LD_LIBRARY_PATH
export PGDATA=/home/postgres/pgdata
export PGHOST=/tmp
source .bashrc
初始化
su - postgres
initdb
修改配置文件
vim /home/postgres/pgdata/postgresql.conf
# 修改端口和绑定地址
listen_addresses = '*'
port = 15432
修改pg_hba.conf
vim pg_hba.conf
# 添加一行
host all all 0.0.0.0/0 trust
修改密码
# 进入数据库修改密码
psql -U postgres -p 15432
ALTER USER postgres WITH PASSWORD 'postgres';
启动
# 启动数据库
pg_ctl start
# 停止数据库
pg_ctl stop