1.安装前准备
1.1创建用户
useradd postgres
passwd postgres
1.2创建数据目录和日志目录
mkdir -p /data/db/pg/data
mkdir -p /data/db/pg/logs
chown -R postgres:postgres /data/db/pg
2.安装
2.1 下载二进制包
wget https://get.enterprisedb.com/postgresql/postgresql-10.23-1-linux-x64-binaries.tar.gz
tar -xvf postgresql-10.23-1-linux-x64-binaries.tar.gz -C /data/base/pgsql
2.2 初始化
./initdb -E utf8 -D /data/db/pg/data
Success. You can now start the database server using:
./bin/pg_ctl -D /data/db/pg/data -l logfile start
2.3 启动server
./pg_ctl -D /data/db/pg/data -l /data/db/pg/logs/pgsql.log start
2.4 关闭server
./pg_ctl -D /data/db/pg/data stop
2.5 客户端登录
#本机登录
./psql
#指定目标主机登录
./psql -h 10.16.60.62 -d postgres -U postgres -p 5432
2.6 创建用户并授权
create user root with password 'root';
create database mydb owner root;
grant all privileges on database mydb to root;
2.7 退出登录
\q
2.8 配置远程访问
vim /data/db/pg/data/postgresql.conf
#第60行左右,将listen_addresses取消注释,并将止改为'*'
listen_addresses = '*'
vim /data/db/pg/data/pg_hba.conf.conf
#第86行左右,将"IPv4 local connections"改为:
# IPv4 local connections:
host all all 0.0.0.0/0 trust