0%

PostgreSQL编译安装

安装依赖

1
yum install -y gcc readline-devel openssl-devel zlib-devel

下载解压

1
2
3
wget https://ftp.postgresql.org/pub/source/v13.0/postgresql-13.0.tar.gz
tar -zxf postgresql-13.0.tar.gz
cd postgresql-13.0

安装

1
2
./configure --prefix=/usr/local/pgsql
make && make install

添加用户并授权

1
2
3
4
5
6
useradd postgres
passwd postgres
mkdir -p /data/pgsql/data
mkdir -p /data/pgsql/log
touch /data/pgsql/log/pgsql.log
chown -R postgres:postgres /data/pgsql

添加环境变量

1
2
3
4
5
6
7
8
vi /etc/profile

#postgresql
export PGHOME=/data/pgsql
export PGBASE=/usr/local/pgsql
export PATH=$PATH:$PGBASE/bin

source /etc/profile

初始化数据

1
2
3
切换到postgres执行
su - postgres
initdb -D /data/pgsql/data

image-20201028163913488

修改pg_hba.conf文件

1
vi /data/pgsql/data/pg_hba.conf

image-20201028164015211

0.0.0.0/0,表示信任来自所有id连接的客户端,加密方式改为md5

修改postgresql.conf配置文件

1
vi /data/pgsql/data/postgresql.conf

image-20201028164305794

localhost改为*,表示监听所有的网络连接。其他的参数保持默认即可。

启动

切换root用户

1
vi /usr/lib/systemd/system/postgresql.service
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
[Unit]
Description=PostgreSQL database server
After=network.target

[Service]
Type=forking

User=postgres
Group=postgres

# Port number for server to listen on
#Environment=PGPORT=5432

# Location of database directory
Environment=PGDATA=/data/pgsql/data

# Where to send early-startup messages from the server (before the logging
# options of postgresql.conf take effect)
# This is normally controlled by the global default set by systemd
# StandardOutput=syslog

# Disable OOM kill on the postmaster
OOMScoreAdjust=-1000

#ExecStartPre=/usr/local/pgsql/bin/postgresql-check-db-dir ${PGDATA}
ExecStart=/usr/local/pgsql/bin/pg_ctl start -D ${PGDATA}
ExecStop=/usr/local/pgsql/bin/pg_ctl stop -D ${PGDATA}
ExecReload=/usr/local/pgsql/bin/pg_ctl reload -D ${PGDATA}

# Give a reasonable amount of time for the server to start up/shut down
TimeoutSec=300

[Install]
WantedBy=multi-user.target
1
2
systemctl enable postgresql
systemctl start postgresql

登录数据库并设置密码

image-20201028164323098

-------------    本文结束  感谢您的阅读    -------------
请作者一杯咖啡。