Postgresql source code compilation and installation (linux-postgresql13.8)

Postgresql source code compilation and installation (linux-postgresql13.8)

1. Download the installation package

postgresql官方下载地址:https://www.postgresql.org/ftp/source/

2. Environmental preparation

1. Modify the maximum number of user processes

cat >> /etc/security/limits.conf << 'EOF'
* soft     nproc          65535
* hard     nproc          65535
* soft     nofile         65535
* hard     nofile         65535
EOF

2. Modify ordinary users

cat >> /etc/security/limits.d/90-nproc.conf << 'EOF'

*          soft     nproc          65535
*          hard     nproc          65535
*          soft     nofile         65535
*          hard     nofile         65535
EOF

3. Modify the number of file handles

cat >> /etc/sysctl.conf << 'EOF'
fs.file-max = 65536
EOF

4. Verification

 ulimit -a

5. Installation dependencies

yum install -y perl-ExtUtils-Embed readline-devel zlib-devel pam-devel libxml2-devel libxslt-devel openldap-devel  python-devel gcc-c++ openssl-devel cmake perl python36 tcl openssl-devel ncurses-devel openldap pam

3. Installation steps

decompress

tar -zxvf postgresql-13.8.tar.gz

Enter the installation directory

cd postgresql-13.8

Generate compiled files

/home/pgsql/ is the installation path, which can be modified as needed

./configure \
--prefix=/home/pgsql \
--bindir=/home/pgsql/bin \
--with-pgport=5432 \
--with-wal-blocksize=16 \
--with-segsize=1 \
--with-blocksize=8 \
--with-libedit-preferred \
--with-perl \
--with-openssl \
--with-libxml \
--with-libxslt \
--enable-thread-safety

compile

make -j4 

Install

make -j4 install

create postgresql user,

useradd postgres

Create a data storage directory and grant permissions

mkdir /home/pgsql/data
chown postgres.postgres -R /home/pgsql

switch user

su - postgres

set environment variables

cat >>.bash_profile EOF
export PGDATA=/home/pgsql/data
export PGHOME=/home/pgsql/
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PGHOME/lib
export PATH=$PATH:$PGHOME/bin/
EOF

Environment variables take effect

source .bash_profile

Initialize the database

su - postgres

initdb

postgresql.conf file configuration parameters

cat >> /home/pgsql/data/postgresql.conf <<'EOF'
listen_addresses = '*'
port=5432
unix_socket_directories='/home/pgsql/data'
wal_level = logical
logging_collector = on
log_directory = 'pg_log'
log_filename = 'postgresql-%a.log'
log_truncate_on_rotation = on
log_timezone = 'Asia/Shanghai'
timezone = 'Asia/Shanghai'
max_wal_size = 1GB
min_wal_size = 80MB
dynamic_shared_memory_type = posix      # the default is the first option
shared_buffers = 128MB                  # min 128kB
max_connections = 1000                   # (change requires restart)
datestyle = 'iso, ymd'
lc_messages = 'zh_CN.UTF-8'                     # locale for system error message  # strings
lc_monetary = 'zh_CN.UTF-8'                     # locale for monetary formatting
lc_numeric = 'zh_CN.UTF-8'                      # locale for number formatting
lc_time = 'zh_CN.UTF-8'                         # locale for time formatting
default_text_search_config = 'pg_catalog.simple'
EOF

pg_hba.conf file remote login configuration parameters

cat   > /home/pgsql/data/pg_hba.conf << EOF
# TYPE  DATABASE    USER    ADDRESS       METHOD
local     all       all                    trust
local   replication     all                                     trust
host      all       all   127.0.0.1/32     trust
host      all       all    0.0.0.0/0        md5
host    replication     all    127.0.0.1/32    trust
host   replication  all    0.0.0.0/0        md5
EOF

Configure system services (using root user)

cat > /etc/systemd/system/postgresql-13.service <<'EOF'
[Unit]
Description=PostgreSQL database server
Documentation=man:postgres(1)
After=network.target
[Service]
Type=forking
User=postgres
Group=postgres
Environment=PGPORT=5432
Environment=PGDATA=/home/pgsql/data
OOMScoreAdjust=-1000
ExecStart=/home/pgsql/bin/pg_ctl start -D ${
    
    PGDATA} -s -o '-p ${
    
    PGPORT}' -w -t 300
ExecStop=/home/pgsql/bin/pg_ctl stop -D ${
    
    PGDATA} -s -m fast
ExecReload=/home/pgsql/bin/pg_ctl reload -D ${
    
    PGDATA} -s
KillMode=mixed
KillSignal=SIGINT
TimeoutSec=0
[Install]
WantedBy=multi-user.target
EOF

Configure system environment variables

export PATH=$PATH:/home/pgsql/bin/

Environment variables take effect

source /etc/profile

boot self-start

systemctl status postgresql-13
systemctl enable postgresql-13

View version information

psql --version

Log in to the database test, the default port is 5432

psql -h 127.0.0.1 -U postgres

change Password

\password
或
alter user postgres with password '密码'

finish installation!

Guess you like

Origin blog.csdn.net/LSW1737554365/article/details/129789740