Centos 7 更改 PostgreSQL 14 默认存储路径

前言:

默认PostgreSQL数据存储路径为:/var/lib/pgsql/14/data

迁移到新的存储路径:/mnt/postgresql/data

1、关闭PostgreSQL服务

复制代码
systemctl stop postgresql-14

2、创建目录

复制代码
# 创建新目录
mkdir -p /mnt/postgresql/data

# 更改目录权限
chown -R postgres:postgres /mnt/postgresql/data
chmod 0700 /mnt/postgresql/data

3、更新系统文件

复制代码
# 编辑 postgresql-14.service 文件
vim /usr/lib/systemd/system/postgresql-14.service

# 修改内容如下:
Environment=PGDATA=/mnt/postgresql/data/

4、更新PostgreSQL配置

复制代码
# 编辑 postgresql.conf 文件
vim /var/lib/pgsql/14/data/postgresql.conf

# 修改内容如下(42行左右):
data_directory = '/mnt/postgresql/data'
hba_file = '/mnt/postgresql/data/pg_hba.conf'
ident_file = '/mnt/postgresql/data/pg_ident.conf'

5、迁移目录

复制代码
cp -rp /var/lib/pgsql/14/data/* /mnt/postgresql/data
或 mv /var/lib/pgsql/14/data/* /mnt/postgresql/data

6、重新加载配置文件

复制代码
systemctl daemon-reload
systemctl restart postgresql-14
systemctl status postgresql-14
相关推荐
IT大白鼠5 小时前
Linux进程与计划任务管理:技术详解与实战指南
linux·运维·服务器
拾贰_C5 小时前
【Ubuntu | 公共工作站 | mysql 】 MySQL残留物残留数据
linux·mysql·ubuntu
Ujimatsu6 小时前
虚拟机安装Ubuntu 26.04.x服务器版(命令行版)(2026.5)
linux·windows·ubuntu
hweiyu006 小时前
Linux命令:arptables
linux·运维
仙柒4157 小时前
管理网络安全
linux·运维·服务器
福尔摩斯·柯南8 小时前
Ubuntu 14.04/16.04/18.04/20.04/22.04/24.04/26.04全系列LTS长期支持版镜像IOS分享
linux·运维·ubuntu
xiaoming00189 小时前
JAVA项目打包部署运维全流程(多服务、批量)
java·linux·运维
浪客灿心9 小时前
Linux五种IO模型与非阻塞IO
linux·网络
洋哥网络科技9 小时前
centos7 升级openssh-10.2
linux·运维·服务器·系统安全
我先去打把游戏先9 小时前
【保姆级图文教程】:VMware虚拟机安装Ubuntu Server 22.04
linux·数据库·ubuntu