--磁盘推荐SSD > 机械磁盘
--cpu关闭numa
--存储阵列级别推荐: raid10 > raid5
--使用逻辑卷LVM
--文件系统选择: xfs > ext4
--多网卡绑定,分别连接到不同的交换机上
根据业务实际修改,此处不做演示
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
useradd postgres
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
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
pg_ctl -D $PGDATA -s -l $PGHOME/logfile -o "-p 1521" start
其中-D为数据目录 -s为详细信息报错 -l为启动日志路径
通过进程查看相应数据库实例已经启动