centos7 安装 postgres12
--创建安装目录
[root@localhost ~]# mkdir /data/pg12/data -p
[root@localhost ~]# chown -R postgres.postgres /data/pg12
下载
wget https://ftp.postgresql.org/pub/source/v12.1/postgresql-12.1.tar.gz
解压
tar -zxf postgresql-12.1.tar.gz
cd postgresql-12.1
vim ~/enpg12.sh
export PGHOME=/data/pg12
export PGPORT=10005
export PGDATA=/data/pg12/data
export LANG=en_US.UTF8
export LD_LIBRARY_PATH=$PGHOME/lib:/lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/lib:$LD_LIBRARY_PATH
export DATE=`date +"%Y%m%d%H%M"`
export PATH=$PGHOME/bin:$CMAKE_ROOT/bin:$PATH:.
export MANPATH=$PGHOME/share/man:$MANPATH
export PGUSER=postgres
export PGHOST='127.0.0.1'
export PGDATABASE='postgres'
alias rm='rm -i'
alias ll='ll -lh'
sudo yum install readline-devel zlib-devel openssl openssl-devel pam pam-devel libxml2 libxml2-devel libxslt libxslt-devel openldap openldap-devel python python-devel libssh2-devel perl-ExtUtils-Embed flex flex.x86_64 bison bison-devel
chmod +x ~/enpg12.sh
编译安装
./configure --prefix=/data/pg12 --with-pgport=10005 --with-perl --with-python --with-openssl --with-pam --with-ldap --with-libxml --with-libxslt
yum install gcc
安装 所有的插件
gmake world -j 32 && gmake install world
初始化
[postgres@cnsz92pl00192 postgresql-12.1]$initdb -D $PGDATA -E UTF8 --locale=C -U postgres -W
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
The database cluster will be initialized with locale "C".
The default text search configuration will be set to "english".
Data page checksums are disabled.
Enter new superuser password:
Enter it again:
fixing permissions on existing directory /data/pg12/data ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... PRC
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok
initdb: warning: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.
Success. You can now start the database server using:
pg_ctl -D /data/pg12/data -l logfile start
更改配置
cd $PGDATA
vim postgresql.conf
监听IPV4的所有IP
listen_addresses='0.0.0.0'
vim pg_hba.conf
host all all 127.0.0.1/32 trust
host all all 0.0.0.0/0 md5
[postgres@localhost data]$ pg_ctl -D $PGDATA -l logfile start
waiting for server to start.... done
server started
[postgres@cnsz92pl00192 data]$psql
psql (12.1)
Type "help" for help.
postgres=# select version();
version
---------------------------------------------------------------------------------------------------------
PostgreSQL 12.1 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-36), 64-bit
(1 row)
pg wal log自动归档和删除指定天数前的文件
vi $PGDATA/arch.sh
test ! -f /arch/$1 && cp --preserve=timestamps $2 /arch/$1 ; find /arch/ -type f -mtime +7 -exec rm -f {} \;
chmod 500 $PGDATA/arch.sh
wal_level = replica
archive_mode = on
archive_command = 'arch.sh %f %p'
报错:configure: error: readline library not found
解决办法:yum -y install readline-devel
报错:configure: error: zlib library not found
解决办法:yum -y install zlib-devel
报错:configure: error: library 'crypto' is required for OpenSSL
解决办法:yum -y install openssl openssl-devel
报错:configure: error: library 'pam' is required for PAM
解决办法:yum -y install pam pam-devel
报错:configure: error: library 'xml2' (version >= 2.6.23) is required for XML support
解决办法:yum -y install libxml2 libxml2-devel
报错:configure: error: library 'xslt' is required for XSLT support
解决办法:yum -y install libxslt libxslt-devel
报错:configure: error: header file is required for LDAP
解决办法:yum -y install openldap openldap-devel
报错:configure: error: header file <Python.h> is required for Python
解决办法:yum -y install python python-devel
报错: libssh2.h: No such file or directory
解决办法: yum -y install libssh2-devel
报错:configure: error: could not determine flags for linking embedded Perl.
解决办法:yum install perl-ExtUtils-Embed
5.1.2 make 阶段常见报错及解决方法
报错:ERROR: `flex' is missing on your system.
解决办法:yum -y install flex flex.x86_64
报错:ERROR: `bison' is missing on your system.
解决办法:yum -y install bison bison-devel