PostgreSQL 16.2版本(当前最新版本)安装和根本配置
一.前言PostgreSQL数据库的利用出现出增长的趋势,吸引了越来越多的用户和组织选择采用PostgreSQL作为其首选的关系型数据库管理体系。尤其是在大数据、云计算和人工智能等领域。此外,国内也有一些公司提供了基于 PostgreSQL 的增值服务息争决方案,为用户提供更好的支持。
https://i-blog.csdnimg.cn/blog_migrate/3906cf78e66208119df44403e0d3a6f9.png
PostgreSQL数据库版本更新较快,目前最新版本为16.2。本文记载了16.2版本的详细安装过程。
官方下载链接:https://www.postgresql.org/ftp/source/v16.2/
https://i-blog.csdnimg.cn/blog_migrate/8ae02c514c2efa395bb5814b0b791f70.png
二.安装前准备
-- 安装依赖
yum install -y gcc*
yum install -y readline-devel zlib-devel
yum install -y libicu-devel
-- 创建用户
groupadd postgres
useradd -g postgres postgres
passwd postgres
-- 创建软件目录和数据目录
mkdir -p /u01/pg16/data
chown postgres /u01/pg16/data
三.开始安装
-- 解压后进行编译安装
tar -zxvf postgresql-16.2.tar.gz
cd postgresql-16.2
./configure --prefix=/u01/pg16
make world
make install-world
-- 修改postgres用户环境变量
su - postgres
vim ~/.bash_profile
PATH=$PATH:$HOME/.local/bin:$HOME/bin:/u01/pg16/bin
export PATH
PGDATA=/u01/pg16/data
export PGDATA
export LANG=en_US.UTF-8
source ~/.bash_profile
-- 初始化数据库
/u01/pg16/bin/initdb -D /u01/pg16/data
-- 启动数据库
/u01/pg16/bin/pg_ctl -D /u01/pg16/data -l logfile start
四.修改数据库配置
-- 修改管理员密码
psql
alter user postgres password 'postgres';
-- 修改pg_hba.conf文件,针对IPV4地址的客户端机器,允许其通过任意IP地址连接
vim /u01/pg16/data/pg_hba.conf
#IPv4 local connections: 添加一行
host all all 0.0.0.0/0 trust
-- 修改数据库配置文件(参数根据实际情况进行修改)
vim /u01/pg16/data/postgresql.conf
# 上一步编写了pg_hba.conf文件,需要在配置文件中添加listen_addresses = '*'才可生效
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'
-- 重启数据库生效
pg_ctl restart -m fast
五.配置服务和开机自启动
vim /usr/lib/systemd/system/postgresql.service
Description=postgreSQL Server
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
WantedBy=multi-user.target
-- 加载配置和启动
systemctl daemon-reload && systemctl enable postgresql
-- 关掉服务的自启动
systemctl disable postgresql
-- 关闭服务
systemctl stop postgresql
-- 启动服务
systemctl start postgresql
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页:
[1]