postgresql源码编译安装(linux-postgresql13.8)

postgresql源码编译安装(linux-postgresql13.8)

一、安装包下载

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

二、环境准备

1、修改最大用户进程数

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

2、修改普通用户

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

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

3、修改文件句柄数

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

4、验证

 ulimit -a

5、安装依赖

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

三、安装步骤

解压

tar -zxvf postgresql-13.8.tar.gz

进入安装目录

cd postgresql-13.8

生成编译文件

/home/pgsql/ 为安装路径,可根据需要修改

./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

编译

make -j4 

安装

make -j4 install

创建postgresql用户,

useradd postgres

创建数据存储目录并赋予权限

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

切换用户

su - postgres

设置环境变量

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

环境变量生效

source .bash_profile

初始化数据库

su - postgres

initdb

postgresql.conf 文件配置参数

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 文件远程登录配置参数

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

配置系统服务(使用root用户)

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

配置系统环境变量

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

环境变量生效

source /etc/profile

开机自启动

systemctl status postgresql-13
systemctl enable postgresql-13

查看版本信息

psql --version

登录数据库测试,默认端口 5432

psql -h 127.0.0.1 -U postgres

修改密码

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

完成安装!

猜你喜欢

转载自blog.csdn.net/LSW1737554365/article/details/129789740