mkdir -p /data/usr/src
把包postgresql-11.7.tar.gz 和pg_pathman-master.zip 拷到该目录
1、创建数据库管理账户
# useradd maintuser
2、安装依赖包
# yum install gcc gcc-c++ -y
# yum install readline-devel zlib-devel -y
# yum install uuid-devel -y
# yum install libxml2 libxml2-devel -y
3、编译安装
# tar -zxf postgresql-11.7.tar.gz
# cd postgresql-11.7/
# ./configure --prefix=/data/usr/postgresql --with-libxml --with-ossp-uuid
# make && make install
4、添加需要的模块支持
把支持数据库分区的包放入指定目录下
unzip pg_pathman-master.zip
mv pg_pathman-master /data/usr/src/postgresql-11.7/contrib/pg_pathman
# cd contrib/uuid-ossp
# make && make install
# cd ../pg_stat_statements
# make && make install
# cd ../xml2/
# make && make install
# cd ../pg_pathman
make && make install
5、编译环境变量
# vi /etc/profile
export PGHOME=/data/usr/postgresql
export PGDATA=/data/pg_data
export PATH=$PATH:$PGHOME/bin
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
export LC_CTYPE=en_US.UTF-8
# source /etc/profile
6、初始化数据库并启动
# chown -R maintuser:maintuser /data/pg_data
# chown -R maintuser:maintuser /data/usr/postgresql
# su maintuser
$ initdb
$ pg_ctl start
7、修改管理员账户密码并修改配置文件
$ psql -h 127.0.0.1 -d postgres
ALTER USER maintuser WITH PASSWORD 'Admindata!';
$ vi /data/pg_data/pg_hba.conf
# "local" is for Unix domain socket connections only
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 md5
host all all 192.168.125.0/24 md5
host all all 192.168.99.0/24 md5
# replication privilege.
vi /data/pg_data/postgresql.conf
listen_addresses = '*'
wal_level = archive
max_connections = 512
unix_socket_directories = '/data/pg_data/socket'
# 配置支持 pg_stat_statements 和 pg_pathman
shared_preload_libraries = 'pg_stat_statements,pg_pathman'
track_io_timing = on
track_activity_query_size = 2048
pg_stat_statements.max = 10000
pg_stat_statements.track = all
pg_stat_statements.track_utility = off
pg_stat_statements.save = on
$ mkdir /data/pg_data/socket
$ pg_ctl restart
8、对库进行操作,增加模块功能支持
postgres=# create extension "uuid-ossp";
CREATE EXTENSION
postgres=# create extension pg_stat_statements;
CREATE EXTENSION
postgres=# create extension "pg_pathman";
CREATE EXTENSION
postgres=# create database test;
CREATE DATABASE
对新建的库增加模块功能支持,这里需要使用管理员账户登陆数据库
$ psql -h 127.0.0.1 -d test
postgres=# create extension "uuid-ossp";
CREATE EXTENSION
postgres=# create extension pg_stat_statements;
CREATE EXTENSION
postgres=# create extension "pg_pathman";
CREATE EXTENSION