当前位置:网站首页>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/
边栏推荐
- Guofu hydrogen energy rushes to the scientific and Technological Innovation Board: it plans to raise 2billion yuan, and 360million yuan of accounts receivable exceed the revenue
- mysql8.0JSON_ Instructions for using contains
- Sharing the 12 most commonly used regular expressions can solve most of your problems
- Niuke: intercepting missiles
- 强联通分量
- 世界环境日 | 周大福用心服务推动减碳环保
- Tidb DM alarm DM_ sync_ process_ exists_ with_ Error troubleshooting
- Solution of commercial supply chain collaboration platform in household appliance industry: lean supply chain system management, boosting enterprise intelligent manufacturing upgrading
- PMP考试20天能通过吗?
- 乌卡时代下,企业供应链管理体系的应对策略
猜你喜欢

Principle and performance analysis of lepton lossless compression

Scenario based technology architecture process based on tidb - Theory
![Which Internet companies are worth going to in Shenzhen for software testers [Special Edition for software testers]](/img/c2/a5f5fe17a6bd1f6f9df828ddd224d6.png)
Which Internet companies are worth going to in Shenzhen for software testers [Special Edition for software testers]

Thymeleaf th:with局部变量的使用

Security analysis of Web Architecture

How to protect user privacy without password authentication?

How to introduce devsecops into enterprises?

SaaS multi tenant solution for FMCG industry to build digital marketing competitiveness of the whole industry chain

Countermeasures of enterprise supply chain management system in UCA Era

World Environment Day | Chow Tai Fook serves wholeheartedly to promote carbon reduction and environmental protection
随机推荐
Mysql database installation tutorial under Linux
家用电器行业商业供应链协同平台解决方案:供应链系统管理精益化,助推企业智造升级
How to introduce devsecops into enterprises?
R language ggplot2 visualization: visual line graph, using legend in theme function The position parameter defines the position of the legend
Postgresql 13 安装
ASP. Net large takeout ordering system source code (PC version + mobile version + merchant version)
Countermeasures of enterprise supply chain management system in UCA Era
关于memset赋值的探讨
Thymeleaf th:with局部变量的使用
The IPO of Ruineng industry was terminated: the annual revenue was 447million and it was planned to raise 376million
CYCA少儿形体礼仪 宁波市培训成果考核圆满落幕
Tdengine biweekly selection of community issues | phase III
mysql8.0JSON_CONTAINS的使用说明
LeetCode_ 67 (binary sum)
Thymeleaf th:classappend属性追加 th:styleappend样式追加 th:data-自定义属性
Zhizhen new energy rushes to the scientific innovation board: the annual revenue is 220million, and SAIC venture capital is the shareholder
PHP - fatal error: allowed memory size of 314572800 bytes exhausted
R语言使用nnet包的multinom函数构建无序多分类logistic回归模型、使用coef函数获取模型中每个变量(自变量改变一个单位)对应的对数优势比(log odds ratio)
MySQL user-defined function ID number to age (supports 15 / 18 digit ID card)
Tidb DM alarm DM_ sync_ process_ exists_ with_ Error troubleshooting