PostgreSQL16.2安装文档

原创作者:数据库工程师 鄢守一

powershell 复制代码
#安装依赖
yum install gcc*
yum -y install readline-devel zlib-devel
yum -y install libicu-devel 
powershell 复制代码
#创建用户
groupadd postgres
useradd -g postgres postgres
passwd postgres
powershell 复制代码
#创建软件目录和数据目录
mkdir -p /u01/pg16/data
chown postgres /u01/pg16/data
powershell 复制代码
#编译安装
tar -zxvf postgresql-16.2.tar.gz
cd postgresql-16.2
./configure --prefix=/u01/pg16
make world
make install-world
powershell 复制代码
#初始化数据库
su - postgres
/u01/pg16/bin/initdb -D /u01/pg16/data 
powershell 复制代码
#启动数据库
/u01/pg16/bin/pg_ctl -D /u01/pg16/data -l logfile start
powershell 复制代码
#修改环境变量
vim ~/.bash_profile
powershell 复制代码
PATH=$PATH:$HOME/.local/bin:$HOME/bin:/u01/pg16/bin
export PATH
PGDATA=/u01/pg16/data
export PGDATA
export LANG=en_US
powershell 复制代码
source ~/.bash_profile
powershell 复制代码
#修改管理员密码
psql
alter user postgres password 'postgres';
powershell 复制代码
#修改/u01/pg16/data/pg_hba.conf文件,针对IPV4地址的客户端机器,允许其通过任意IP地址,通过md5加密认证。
vim /u01/pg16/data/pg_hba.conf
#IPv4 local connections: 添加一行
host all all 0.0.0.0/0 trust
powershell 复制代码
#修改/u01/pg16/data/postgresql.conf文件
vim /u01/pg16/data/postgresql.conf

配置文件

powershell 复制代码
listen_addresses = '*'
max_connections = 500
shared_buffers = 2GB
dynamic_shared_memory_type = posix 
max_wal_size = 2GB
min_wal_size = 256MB
logging_collector = on
log_directory = 'pg_log'
log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log'
log_rotation_age = 1d
log_rotation_size = 100MB
log_timezone = 'Asia/Shanghai'
datestyle = 'iso, mdy'
timezone = 'Asia/Shanghai'
lc_messages = 'en_US.UTF-8'
lc_monetary = 'en_US.UTF-8' 
lc_numeric = 'en_US.UTF-8' 
lc_time = 'en_US.UTF-8'
default_text_search_config = 'pg_catalog.english'
powershell 复制代码
#重启数据库生效
pg_ctl restart -m fast
powershell 复制代码
#配置服务
vim /usr/lib/systemd/system/postgresql.service
powershell 复制代码
[Unit]
Description=postgreSQL Server

[Service]
User=postgres
Group=postgres
Type=forking
TimeoutSec=0
PermissionsStartOnly=true
ExecStart=/u01/pg16/bin/pg_ctl -D /u01/pg16/data start
ExecStop=/u01/pg16/bin/pg_ctl stop -D /u01/pg16/data -s -m fast
LimitNOFILE = 65535
Restart=on-failure
RestartSec=3
RestartPreventExitStatus=1
PrivateTmp=false

[Install]
WantedBy=multi-user.target
powershell 复制代码
# 加载配置和启动
systemctl daemon-reload && systemctl enable postgresql
powershell 复制代码
# 关掉服务的自启动
systemctl disable postgresql 
powershell 复制代码
# 关闭和启动服务
systemctl stop postgresql 
相关推荐
开始了码11 小时前
基于 Qt 实现多客户端 TCP 通信聊天室
开发语言·数据库·php
肥猪猪爸11 小时前
数据库 2PC 极简流程图
java·数据库·分布式·mysql·分布式事务·2pc
dot to one11 小时前
B树系列在数据库中的应用
数据结构·数据库·b树
七月初七7712 小时前
使用Python连接MySQL数据库
数据库·python·mysql
悲伤小伞12 小时前
0-MySQL 在 Centos 7环境详细安装过程
linux·服务器·数据库·mysql·centos
Oscar的参数12 小时前
datagrip连接未预置数据库保姆级教程--以dm数据库为例
大数据·数据库·database
海边的Kurisu12 小时前
范进说八股 | Redis篇
数据库·redis·缓存
難釋懷12 小时前
Redis主从-主从同步优化
数据库·redis·缓存
Rick199312 小时前
一个方法a加了事务注解@Transactional,方法a执行10次循环,插入10条数据,是第10条数据执行完之后才会进行提交操作吗?
数据库·事务·transactional
czlczl2002092512 小时前
可重复读 (RR) 的缺陷与“当前读”方案
数据库·oracle