1、groupadd postgres ----创建组
useradd -g postgres postgres ----创建用户
id postgres ---查看id
echo 1 | passwd ---stdin postgres ----设置密码
PG 软件包下载:https://ftp.postgresql.org/pub/source/v12.3/
tar xf postgresql-12.3.tar.gz -C /home/postgres/ -----解压到 /home/postgres/ 下面
cd进入 /home/postgres/
chown -R postgres.postgres postgresql-12.3
下载依赖包 yum install gcc make tree -y
创建安装目录和数据目录
mkdir -p /data/pg12 /data/pgdata5432 /data/pgdata5433 /data/pgdata5434 && chown postgres.postgres /data/pg12 /data/pgdata5432 /data/pgdata5433 /data/pgdata5434
tree /data/
切换到普通用户 postgres,进行编译安装
su - postgres
cd postgresql-12.3/ ----进入到目录
./configure --prefix=/data/pg12 --without-readline --without-zlib
同时编译8个
make -j 8 install
查看
ll /data/pg12/
配置用户环境变量
pwd
vim .bash_profile
在最后新增2行内容
PGHOME=/data/pg12
PATH=$PATH:$HOME/.local/bin:$HOME/bin:$PGHOME/bin
source .bash_profile 刷新
initdb /data/pgdata5432
ls /data/pgdata5432/ ---查看
cat logfile
ss -ntl | grep 5432
pg_ctl -D /data/pgdata5432/ -l logfile stop ---停止
pg_ctl -D /data/pgdata5432/ -l logfile restart ----重启
pg_ctl -D /data/pgdata5432/ -l logfile status
psql -U postgres -p 5432 ----密码
ALTER USER postgres WITH PASSWORD 'qwe123'; ----从设数据库密码
CREATE ROLE replica login replication encrypted password 'qwe123';
输入quit退出数据库
vim /data/pgdata5432/pg_hba.conf
修改为md5使用密码进行登录
local all all md5
在最后一行添加
host replication replica 10.0.0.0/24 md5
cat .bash_profile