1.下载二进制安装包
https://www.postgresql.org/ftp/source
2.上传解压安装包
[root@postgresql data]# tar -zxvf postgresql-15.2.tar.gz
3.创建用户
[root@postgresql ~]# useradd postgres
[root@postgresql ~]# passwd postgres
4.创建目录
[root@postgresql ~]# mkdir -p /app/install
[root@postgresql ~]# mkdir -p /data/pgsql
5.安装依赖
[root@postgresql yum.repos.d]# yum -y groupinstall "Development Tools" "Legacy
UNIX Compatibility"
[root@postgresql yum.repos.d]# yum -y install bison flex readline* zlib-devel
gcc* make
6.编译
[root@postgresql postgresql-15.2]#cd /app/install/postgresql-15.2
[root@postgresql postgresql-15.2]#./configure --prefix=/app/postgresql
[root@postgresql postgresql-15.2]#make && make install
7.初始化
[root@postgresql ~]# chown -R postgres:postgres /app/install
[root@postgresql ~]# chown -R postgres:postgres /data/pgsql
[root@postgresql ~]# chown -R postgres:postgres /app/postgres
[root@postgresql ~]# su - postgres
[root@postgresql ~]# cd /app/postgresql/
[postgres@postgresql postgresql]$bin/initdb -D /data/pgsql -E UTF8 --locale=C -U
postgres
8.修改配置文件
[root@postgresql ~]# su - postgres
[postgres@postgresql ~]$cd /app/postgresql
[postgres@postgresql postgresql]$ mkdir conf && cd conf
[postgres@postgresql conf]$ ln -s /data/pgsql/postgresql.conf .
[postgres@postgresql conf]$ ln -s /data/pgsql/pg_hba.conf .
修改 pg_hba.conf,允许某些 IP 通过客户端工具使用某个用户连接 pg 的某个库,配置如下:
# TYPE DATABASE USER ADDRESS METHOD
# IPv4 local connections:
#host all all 127.0.0.1/32 trust
host all all 0.0.0.0/0 trust
修改 postgresql.conf,编辑 IP、端口、socket、数据存放目录等,如下(仅列出修改的内容):
data_directory = '/data/pgsql'
hba_file = '/app/postgresql/conf/pg_hba.conf'
listen_addresses = '192.168.100.201'
port = 18086
max_connections = 10000
unix_socket_directories = '/app/postgresql/'
unix_socket_group = 'postgres'
9.尝试启动
[root@postgresql ~]# su - postgres
[postgres@postgresql ~]$cd /app/postgresql
评论