PostgreSQL 12.2源码编译安装

PostgreSQL 12.2源码编译安装

  • 选择硬件、存储及文件系统
--磁盘推荐SSD > 机械磁盘
--cpu关闭numa
--存储阵列级别推荐: raid10 > raid5
--使用逻辑卷LVM
--文件系统选择: xfs > ext4
--多网卡绑定,分别连接到不同的交换机上
  • 修改系统内核参数
根据业务实际修改,此处不做演示
  • 禁用SELINUX及防火墙
vim /etc/selinux/config

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted
OS防火墙(建议按业务场景设置,不需要就先删除所有策略,并关闭服务)


iptables -P INPUT ACCEPT  #设置默认接受所有请求
iptables -F 	清除防火墙规则

systemctl disable firewalld
systemctl stop firewalld
  • 创建Postgres用户
useradd postgres
  • 创建安装目录(此处用/op/pg12/data作为安装、数据目录)

mkdir /opt/pg12/data -p
chown -R postgres:postgres /opt/pg12

  • 下载源码包并解压
--使用wget下载
1、wget https://ftp.postgresql.org/pub/source/v12.2/postgresql-12.2.tar.gz

--手动从PostgreSQL官网下载

  • 解压源码包,注意文件夹属主
解压源码包
postgresql-12.2/aclocal.m4
postgresql-12.2/configure.in
postgresql-12.2/INSTALL
[postgres@PostgreSQL pg12]$ ls -l
total 26048
drwxr-xr-x 2 postgres postgres        6 Jul  9 10:55 data
drwxr-xr-x 6 postgres postgres      273 Feb 11 06:29 postgresql-12.2
  • 安装编译所需依赖包
yum install -y openssl openssl-devel pam pam-devel libxml2 libxml2-devel install libxslt libxslt-devel perl perl-devel install perl-ExtUtils-Embed readline readline-devel  zlib zlib-devel gettext gettext-devel bison flex  gcc gcc-c++
  • 编译安装
./configure --prefix=/opt/pg12 --with-pgport=1521 --with-openssl --with-perl --with-python --with-blocksize=16 
make world && make install-world

Linux中./configure、make、make install 命令

  • 设置环境变量(根据实际情况修改)
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/.local/bin:$HOME/bin

export PGDATA=/opt/pg12/data
export PGHOME=/opt/pg12
export PATH=$PGHOME/bin:$PATH

umask 022

PostgreSQL 12.2源码编译安装_第1张图片

  • 初始化数据库实例
initdb -D /opt/pg12/data -E UTF8 --locale=zh_CN.utf8

关于initdb 初始化参数的说明

postgres@PostgreSQL /opt/pg12/data $$Glogin initdb --help
initdb initializes a PostgreSQL database cluster.

Usage:
  initdb [OPTION]... [DATADIR]

Options:
  -A, --auth=METHOD         default authentication method for local connections
      --auth-host=METHOD    default authentication method for local TCP/IP connections
      --auth-local=METHOD   default authentication method for local-socket connections
 [-D, --pgdata=]DATADIR     location for this database cluster
  -E, --encoding=ENCODING   set default encoding for new databases
  -g, --allow-group-access  allow group read/execute on data directory
      --locale=LOCALE       set default locale for new databases
      --lc-collate=, --lc-ctype=, --lc-messages=LOCALE
      --lc-monetary=, --lc-numeric=, --lc-time=LOCALE
                            set default locale in the respective category for
                            new databases (default taken from environment)
      --no-locale           equivalent to --locale=C
      --pwfile=FILE         read password for the new superuser from file
  -T, --text-search-config=CFG
                            default text search configuration
  -U, --username=NAME       database superuser name
  -W, --pwprompt            prompt for a password for the new superuser
  -X, --waldir=WALDIR       location for the write-ahead log directory
      --wal-segsize=SIZE    size of WAL segments, in megabytes

Less commonly used options:
  -d, --debug               generate lots of debugging output
  -k, --data-checksums      use data page checksums
  -L DIRECTORY              where to find the input files
  -n, --no-clean            do not clean up after errors
  -N, --no-sync             do not wait for changes to be written safely to disk
  -s, --show                show internal settings
  -S, --sync-only           only sync data directory

Other options:
  -V, --version             output version information, then exit
  -?, --help                show this help, then exit

If the data directory is not specified, the environment variable PGDATA
is used.

Report bugs to <pgsql-[email protected]>.
postgres@PostgreSQL /opt/pg12/data $$Glogin 

PostgreSQL 12.2源码编译安装_第2张图片

  • 启动数据库实例
pg_ctl -D $PGDATA -s -l $PGHOME/logfile -o "-p 1521" start

其中-D为数据目录 -s为详细信息报错 -l为启动日志路径
通过进程查看相应数据库实例已经启动

PostgreSQL 12.2源码编译安装_第3张图片

  • 通过psql工具链接数据库

PostgreSQL 12.2源码编译安装_第4张图片

你可能感兴趣的:(PostgreSQL)