当前位置:网站首页>PostgreSQL 13 installation
PostgreSQL 13 installation
2022-07-05 14:28:00 【What kind of fish are you keeping?】
One 、 summary
This document describes Linux platform PostgreSQL Two installation methods of ,rmp Installation and source installation .
Two 、rpm install
rpm The installation package is compiled in advance , So the installation process is fast , But its path is also fixed , inflexible .
2.1 Operating system environment
RHEL/CentOS 7-x86_64
2.2 Installation package
PG13.6 rpm Installation package download address
1.postgresql13-13.6-1PGDG.rhel7.x86_64.rpm
2.postgresql13-contrib-13.6-1PGDG.rhel7.x86_64.rpm
3.postgresql13-libs-13.6-1PGDG.rhel7.x86_64.rpm
4.postgresql13-server-13.6-1PGDG.rhel7.x86_64.rpm
Installation package description :
- 1.PostgreSQL Client package . If you want to be local or remote PostgreSQL Operation on the server PostgreSQL database , You need this bag . If you want to install postgresql13-server package , You also need to install this package .
- 2.PostgreSQL Expansion pack, . Contains PostgreSQL Various extension modules included in the distribution .
- 3. share lib Library package . The client program or interface connects to the database , Or use other PostgreSQL lib library , This package needs to be installed .
- 4.PostgreSQL Server installation package . The package includes creating and running PostgreSQL Programs required by the server , This will allow you to create and maintain PostgreSQL database .
2.3 Installation steps
1) close SELinux
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
setenforce 0
cat /etc/selinux/config | grep SELINUX=disabled
getenforce
2) Firewall configuration
-- Turn off firewall
systemctl status firewalld.service
systemctl stop firewalld.service
systemctl disable firewalld.service
-- Add the database port number ( When the firewall cannot be closed )
firewall-cmd --add-port=5432/tcp
firewall-cmd --permanent --add-port=5432/tcp
firewall-cmd --reload
firewall-cmd --list-ports | grep 5432
3) Parameter limit configuration
vi /etc/security/limits.conf
#for pg13
postgres soft core unlimited
postgres hard nproc unlimited
postgres soft nproc unlimited
postgres hard memlock unlimited
postgres hard nofile 1024000
postgres soft memlock unlimited
postgres soft nofile 1024000
postgres hard stack 65536
postgres soft stack 65536
4) Time zone check configuration
-- Check time zone
timedatectl
-- Change the time zone to Shanghai
timedatectl set-timezone Asia/Shanghai
-- Change the time zone to Hong Kong
timedatectl set-timezone Asia/Hong_Kong
5) Create system user
groupdel postgres
userdel postgres
groupadd postgres
useradd -g postgres postgres
passwd postgres
6) Create a data directory
mkdir /data/pg13/{
dbbak,archive} -p
chown postgres:postgres /data -R
7) Install the software
rpm -ivh postgresql13-*
8) Add environment variables
su - postgres
vi /home/postgres/.bash_profile
export PGHOME=/usr/pgsql-13
export PGDATA=/data/pg13/data
export PATH=$PGHOME/bin:$PATH:$HOME/bin
export LD_LIBRARY_PATH=$PGHOME/lib:$LD_LIBRARY_PATH
export PATH=/usr/pgsql-13/bin:$PATH
source /home/postgres/.bash_profile
9) Initialize database
initdb -A scram-sha-256 -W
ll /data/pg13/data
10) Start database
pg_ctl start
pg_ctl status
11) Parameter configuration after installation
psql Connect to the database configuration
alter system set listen_addresses = '*';
alter system set max_connections = 2000;
alter system set superuser_reserved_connections = 10;
alter system set shared_buffers = '16GB'; # Physical memory is recommended 1/4
alter system set effective_cache_size = '32GB'; # Physical memory is recommended 1/2
alter system set maintenance_work_mem = '2GB';
alter system set autovacuum_work_mem = '1GB';
alter system set effective_io_concurrency = 0;
alter system set checkpoint_completion_target = 0.8;
alter system set checkpoint_timeout = '30min';
alter system set log_destination = 'csvlog';
alter system set logging_collector = on;
alter system set log_directory = 'logs';
alter system set log_filename = 'postgresql-%a.log';
alter system set log_rotation_age = '1d';
alter system set log_rotation_size = 0;
alter system set log_truncate_on_rotation = on;
alter system set log_statement = 'ddl';
alter system set log_connections = on;
alter system set log_disconnections = on;
alter system set log_min_duration_statement = '5s';
alter system set log_checkpoints = on;
alter system set log_error_verbosity = verbose;
alter system set log_line_prefix = '%m [%p] %q %u %d %a %r %e ';
alter system set min_wal_size ='8GB'; # recommend max_wal_size Of 1/4
alter system set max_wal_size ='32GB'; # recommend shared_buffers Of 2 times
alter system set archive_mode = on;
alter system set archive_command = 'cp %p /data/pg13/archive/%f;find /data/pg13/archive/ -type f -mtime +7 -exec rm -f {} \'; alter system set archive_timeout = '30min';
12) modify pg_hba.conf
vi $PGDATA/pg_hba.conf
host all all 0.0.0.0/0 scram-sha-256
pg_ctl restart
13) Set power on self start
root User configuration
Mode one : Script
vi /etc/rc.d/rc.local
su - postgres -c '/usr/pgsql-13/bin/pg_ctl start -D /data/pg13/data/'
chmod +x /etc/rc.d/rc.local
Mode two : service
vi /usr/lib/systemd/system/postgresql-13.service
Environment=PGDATA=/data/pg13/data/
systemctl enable postgresql-13.service
systemctl is-enabled postgresql-13.service
14) Installation and configuration instructions
After installation , You can use pg_config Command to view the default path , Default compilation parameters and other information .
[[email protected] ~]$ pg_config
BINDIR = /usr/pgsql-13/bin
DOCDIR = /usr/pgsql-13/doc
HTMLDIR = /usr/pgsql-13/doc/html
INCLUDEDIR = /usr/pgsql-13/include
PKGINCLUDEDIR = /usr/pgsql-13/include
INCLUDEDIR-SERVER = /usr/pgsql-13/include/server
LIBDIR = /usr/pgsql-13/lib
PKGLIBDIR = /usr/pgsql-13/lib
LOCALEDIR = /usr/pgsql-13/share/locale
MANDIR = /usr/pgsql-13/share/man
SHAREDIR = /usr/pgsql-13/share
SYSCONFDIR = /etc/sysconfig/pgsql
PGXS = /usr/pgsql-13/lib/pgxs/src/makefiles/pgxs.mk
CONFIGURE = '--enable-rpath' '--prefix=/usr/pgsql-13' '--includedir=/usr/pgsql-13/include' '--mandir=/usr/pgsql-13/share/man' '--datadir=/usr/pgsql-13/share' '--libdir=/usr/pgsql-13/lib' '--with-icu' '--with-llvm' '--with-perl' '--with-python' '--with-tcl' '--with-tclconfig=/usr/lib64' '--with-openssl' '--with-pam' '--with-gssapi' '--with-includes=/usr/include' '--with-libraries=/usr/lib64' '--enable-nls' '--enable-dtrace' '--with-uuid=e2fs' '--with-libxml' '--with-libxslt' '--with-ldap' '--with-selinux' '--with-systemd' '--with-system-tzdata=/usr/share/zoneinfo' '--sysconfdir=/etc/sysconfig/pgsql' '--docdir=/usr/pgsql-13/doc' '--htmldir=/usr/pgsql-13/doc/html' 'CFLAGS=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic' 'LLVM_CONFIG=/usr/lib64/llvm5.0/bin/llvm-config' 'CLANG=/opt/rh/llvm-toolset-7/root/usr/bin/clang' 'PKG_CONFIG_PATH=:/usr/lib64/pkgconfig:/usr/share/pkgconfig' 'PYTHON=/usr/bin/python3'
CC = gcc -std=gnu99
CPPFLAGS = -D_GNU_SOURCE -I/usr/include/libxml2 -I/usr/include
CFLAGS = -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic
CFLAGS_SL = -fPIC
LDFLAGS = -L/usr/lib64/llvm5.0/lib -L/usr/lib64 -Wl,--as-needed -Wl,-rpath,'/usr/pgsql-13/lib',--enable-new-dtags
LDFLAGS_EX =
LDFLAGS_SL =
LIBS = -lpgcommon -lpgport -lpthread -lselinux -lxslt -lxml2 -lpam -lssl -lcrypto -lgssapi_krb5 -lz -lreadline -lrt -ldl -lm
VERSION = PostgreSQL 13.6
BINDIR: Executable location .
DOCDIR: Document file location .
HTMLDIR:HTML Document file location .
INCLUDEDIR: Client interface C Location of header file .
PKGINCLUDEDIR: Other C Location of header file .
INCLUDEDIR-SERVER: Server programmed C Location of header file .
LIBDIR: Location of object code base .
PKGLIBDIR: Location of dynamically loadable modules , Or the server may search their location ( Other architecture independent data files may also be installed in this directory ).
LOCALEDIR: Location of area support files ( If in PostgreSQL There is no configuration region support when it is compiled , This will be an empty string ).
MANDIR: The location of the man page .
SHAREDIR: Location of architecture independent support files .
SYSCONFDIR: Location of system wide configuration files .
PGXS: Expand makefile The location of .
CONFIGURE: When PostgreSQL Configured to be given at compile time configure Script options . This can be used to get the same configuration again , Or find out which option compiles a binary package ( Note, however, that binary packages usually contain vendor specific patches ).
CC: Used to compile PostgreSQL Of CC A variable's value . This shows the used C compiler .
CPPFLAGS: Used to compile PostgreSQL Of CPPFLAGS A variable's value . This shows what is needed in preprocessing C Compiler switches ( Typically -I switch ).
CFLAGS: Used to compile PostgreSQL Of CFLAGS A variable's value . This shows the used C Compiler switches .
CFLAGS_SL: Used to compile PostgreSQL Of CFLAGS_SL A variable's value . This shows the additional C Compiler switches .
LDFLAGS: Used to compile PostgreSQL Of LDFLAGS A variable's value . This shows the linker switch .
LDFLAGS_EX: Used to compile PostgreSQL Of LDFLAGS_EX A variable's value . This only shows the linker switches used to compile executable programs .
LDFLAGS_SL: Used to compile PostgreSQL Of LDFLAGS_SL A variable's value . This only shows the linker switch used to compile the shared library .
LIBS: Used to compile PostgreSQL Of LIBS A variable's value . This usually includes links to PostgreSQL Of the external library in -l switch .
VERSION:PostgreSQL Version of .
15) uninstall
root User configuration
-- Stop storage
systemctl stop postgresql-13.service
ps -ef|grep post
-- Back up the original data ( Be sure not to delete )
mv /data/ /data20220616
-- uninstall
rpm -e --nodeps `rpm -qa | grep postgresql`
userdel -r postgres
rpm -qa |grep -ie "postgre|pg"
find / -name post
3、 ... and 、 Source code installation
3.1 Operating system environment
RHEL/CentOS 7-x86_64
3.2 Installation package
PG13.6 Source installation package download address
postgresql-13.6.tar.bz2
postgresql-13.6.tar.bz2.md5
postgresql-13.6.tar.bz2.sha256
postgresql-13.6.tar.gz
postgresql-13.6.tar.gz.md5
postgresql-13.6.tar.gz.sha256
Installation package description :
- The above is the source installation package and its verification code of the two packaging methods , This selection postgresql-13.6.tar.gz Installation package .
3.3 Installation steps
1) close SELinux
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
setenforce 0
cat /etc/selinux/config | grep SELINUX=disabled
getenforce
2) Firewall configuration
-- Turn off firewall
systemctl status firewalld.service
systemctl stop firewalld.service
systemctl disable firewalld.service
-- Add the database port number ( When the firewall cannot be closed )
firewall-cmd --add-port=5432/tcp
firewall-cmd --permanent --add-port=5432/tcp
firewall-cmd --reload
firewall-cmd --list-ports | grep 5432
3) Parameter limit configuration
vi /etc/security/limits.conf
#for pg13
postgres soft core unlimited
postgres hard nproc unlimited
postgres soft nproc unlimited
postgres hard memlock unlimited
postgres hard nofile 1024000
postgres soft memlock unlimited
postgres soft nofile 1024000
postgres hard stack 65536
postgres soft stack 65536
4) Time zone check configuration
-- Check time zone
timedatectl
-- Change the time zone to Shanghai
timedatectl set-timezone Asia/Shanghai
-- Change the time zone to Hong Kong
timedatectl set-timezone Asia/Hong_Kong
5) Create system user
groupdel postgres
userdel postgres
groupadd postgres
useradd -g postgres postgres
passwd postgres
6) Create a data directory
mkdir /app/pg13 -p
mkdir /data/pg13/{
dbbak,archive} -p
chown postgres:postgres /app/pg13 -R
chown postgres:postgres /data -R
7) Install dependency packages
yum install -y make gcc gcc-c++ readline-devel zlib-devel gzip bzip2 perl-ExtUtils-Embed libperl-dev python-devel tcl-devel libxml2-devel libxslt-devel pam-devel openldap-devel libuuid-devel uuid uuid-devel openssl openssl-devel
make gcc gcc-c++: Compiling and installing requires
gzip bzip2: Decompression requires
readline-devel: Support arrow keys to retrieve and edit previous commands
zlib-devel: Support pg_dump and pg_restore Use in zlib Compressed archive
perl-ExtUtils-Embed libperl-dev: Support PL/Perl Server programming language
python-devel: Support PL/Python Server programming language
tcl-devel: Support PL/Tcl Process language
libxml2-devel: Support handling XML
libxslt-devel: Support use XSLT take XML Programs that convert to other formats
pam-devel openldap-devel: Support use Kerberos、OpenLDAP and / or PAM Certification of services
libuuid-devel uuid uuid-devel: Support generation UUID
openssl openssl-devel: Support encrypted client connection
llvm llvm-devel:llvm library , Support based on LLVM Of JIT compile
8) Compilation and installation
Upload the source installation package , Decompress, compile, install
tar -xzvf postgresql-13.6.tar.gz
cd postgresql-13.6
./configure --prefix=/app/pg13 --with-perl --with-python --with-tcl --with-openssl --with-pam --with-gssapi --enable-nls --with-uuid=e2fs --with-libxml --with-libxslt --with-ldap
make&&make install
–prefix
Put all the files in the directory PREFIX Not /usr/local/pgsql in , The actual files are installed in several subdirectories .
–with-perl
Make PL/Perl Server programming language .
–with-python
Make PL/Python Server programming language .
–with-tcl
Make PL/Tcl Server programming language .
–with-openssl
compile SSL( encryption ) Connection support .
–with-pam
Use PAM( Pluggable authentication module ) Support building .
–with-gssapi
Build support GSSAPI Authentication .
–enable-nls
Turn on local language support (NLS), That is, the ability to display program messages in non English .
–with-uuid
Use specified UUID Library compilation uuid-ossp modular ( Provide build UUID Function of ).
–with-libxml
Use libxml2 structure , Enable SQL/XML Support .
–with-libxslt
Use libxslt structure , send xml2 The module can execute XML Of XSL transformation . --with-libxml Must also specify .
–with-ldap
Compile for authentication and connection parameter lookup LDAP Support .
8) Add environment variables
su - postgres
vi /home/postgres/.bash_profile
export PGHOME=/app/pg13
export PGDATA=/data/pg13/data
export PATH=$PGHOME/bin:$PATH:$HOME/bin
export LD_LIBRARY_PATH=$PGHOME/lib:$LD_LIBRARY_PATH
export PATH=/app/pg13/bin:$PATH
source /home/postgres/.bash_profile
9) Initialize database
initdb -A scram-sha-256 -W
ll /data/pg13/data
10) Start database
pg_ctl start
pg_ctl status
11) Parameter configuration after installation
psql Connect to the database configuration
alter system set listen_addresses = '*';
alter system set max_connections = 2000;
alter system set superuser_reserved_connections = 10;
alter system set shared_buffers = '16GB'; # Physical memory is recommended 1/4
alter system set effective_cache_size = '32GB'; # Physical memory is recommended 1/2
alter system set maintenance_work_mem = '2GB';
alter system set autovacuum_work_mem = '1GB';
alter system set effective_io_concurrency = 0;
alter system set checkpoint_completion_target = 0.8;
alter system set checkpoint_timeout = '30min';
alter system set log_destination = 'csvlog';
alter system set logging_collector = on;
alter system set log_directory = 'logs';
alter system set log_filename = 'postgresql-%a.log';
alter system set log_rotation_age = '1d';
alter system set log_rotation_size = 0;
alter system set log_truncate_on_rotation = on;
alter system set log_statement = 'ddl';
alter system set log_connections = on;
alter system set log_disconnections = on;
alter system set log_min_duration_statement = '5s';
alter system set log_checkpoints = on;
alter system set log_error_verbosity = verbose;
alter system set log_line_prefix = '%m [%p] %q %u %d %a %r %e ';
alter system set min_wal_size ='8GB'; # recommend max_wal_size Of 1/4
alter system set max_wal_size ='32GB'; # recommend shared_buffers Of 2 times
alter system set archive_mode = on;
alter system set archive_command = 'cp %p /data/pg13/archive/%f;find /data/pg13/archive/ -type f -mtime +7 -exec rm -f {} \'; alter system set archive_timeout = '30min';
12) modify pg_hba.conf
vi $PGDATA/pg_hba.conf
host all all 0.0.0.0/0 scram-sha-256
pg_ctl restart
13) Set power on self start
root User configuration
vi /etc/rc.d/rc.local
su - postgres -c '/app/pg13/bin/pg_ctl start -D /data/pg13/data/'
chmod +x /etc/rc.d/rc.local
14) uninstall
root User configuration
-- Stop storage
pg_ctl stop
ps -ef|grep post
-- Back up the original data ( Be sure not to delete )
mv /data/pg13/data/ /data/pg13/data20220616
-- Clean up users and directories
userdel -r postgres
find / -name post*
rm -rf /app/
rm -rf /data/
边栏推荐
- C语言中限定符的作用
- 关于memset赋值的探讨
- Show strength. In this way, the mobile phone will not be difficult to move forward
- Thymeleaf th:with use of local variables
- PHP - fatal error: allowed memory size of 314572800 bytes exhausted
- R语言ggplot2可视化条形图:通过双色渐变配色颜色主题可视化条形图、为每个条形添加标签文本(geom_text函数)
- The forked VM terminated without saying properly goodbye
- 区间 - 左闭右开
- SaaS multi tenant solution for FMCG industry to build digital marketing competitiveness of the whole industry chain
- Oneconnect listed in Hong Kong: with a market value of HK $6.3 billion, ye Wangchun said that he was honest and trustworthy, and long-term success
猜你喜欢
微帧科技荣获全球云计算大会“云鼎奖”!
LeetCode_ 2 (add two numbers)
为什么我认识的机械工程师都抱怨工资低?
网上电子元器件采购商城:打破采购环节信息不对称难题,赋能企业高效协同管理
Kunlun Taike rushes to the scientific innovation board: the annual revenue is 130million, and it plans to raise 500million. CETC Taiji holds 40% of the shares
Loop invariant
区间 - 左闭右开
Topology可视化绘图引擎
【学习笔记】阶段测试1
Security analysis of Web Architecture
随机推荐
矩阵链乘 - 动态规划实例
Niuke: intercepting missiles
leetcode:881. 救生艇
Security analysis of Web Architecture
How to choose the appropriate certificate brand when applying for code signing certificate?
R language ggplot2 visualization: visual line graph, using legend in theme function The position parameter defines the position of the legend
如何深入理解“有限状态机”的设计思想?
Total amount analysis accounting method and potential method - allocation analysis
What about SSL certificate errors? Solutions to common SSL certificate errors in browsers
网上电子元器件采购商城:打破采购环节信息不对称难题,赋能企业高效协同管理
LeetCode_ 3 (longest substring without repeated characters)
Judge whether the variable is an array
How to introduce devsecops into enterprises?
ASP.NET大型外卖订餐系统源码 (PC版+手机版+商户版)
注意!软件供应链安全挑战持续升级
R语言ggplot2可视化密度图:按照分组可视化密度图、自定义配置geom_density函数中的alpha参数设置图像透明度(防止多条密度曲线互相遮挡)
申请代码签名证书时如何选择合适的证书品牌?
Mingfeng medical sprint technology innovation board: annual revenue of 350million yuan, proposed to raise 624million yuan
LeetCode_ 69 (square root of x)
How does redis implement multiple zones?