PostgreSQL 修改数据目录

注意本文环境是基于CentOS 7 以及Postgre 12

1、查看基础信息

[root@YZX-RD-37 app]# su - postgres
[postgres@YZX-RD-37 data]$ psql 
psql (12.6)
Type "help" for help.

postgres=# SHOW data_directory;
     data_directory     
------------------------
 /var/lib/pgsql/12/data
(1 row)

2、停止PG

[root@YZX-RD-37 app]# systemctl stop postgresql-12
[root@YZX-RD-37 app]# ps aux | grep pg
root       4441  0.0  0.0 112812   976 pts/0    S+   18:46   0:00 grep --color=auto pg

3、创建基础环境

[root@YZX-RD-37 app]# mkdir /app/postgresql
[root@YZX-RD-37 app]# chown -R postgres.postgres /app/postgresql/

4、安装rsync

[root@YZX-RD-37 app]# yum install -y rsync

5、拷贝现在的数据目录到新的数据目录

[root@YZX-RD-37 app]# rsync -av /var/lib/pgsql/12/data /app/postgresql/
# 使用-a标志保留的权限和其他目录属性, 能避免未来的升级权限问题.
# 而-v提供详细输出,以便能够按照进度。

6、修改系统服务配置

[root@YZX-RD-37 app]# vim /usr/lib/systemd/system/postgresql-12.service
#Environment=PGDATA=/var/lib/pgsql/12/data/
Environment=PGDATA=/app/postgresql/data

#重新加载一次服务
[root@YZX-RD-37 app]# systemctl daemon-reload

7、查看新的目录信息

[postgres@YZX-RD-37 12]$ ll /var/lib/pgsql/12/
total 8
drwx------  2 postgres postgres    6 Feb 11 09:16 backups
drwx------ 20 postgres postgres 4096 Apr 21 18:46 data.bak
-rw-------  1 postgres postgres  911 Apr 21 17:39 initdb.log

[root@YZX-RD-37 app]# ll /app/postgresql/
total 4
drwx------ 20 postgres postgres 4096 Apr 21 18:46 data

8、最后启动PG

[root@YZX-RD-37 app]# systemctl start postgresql-12
[root@YZX-RD-37 app]# ps aux | grep pg
postgres   4583  1.0  0.2 393236 17192 ?        Ss   18:53   0:00 /usr/pgsql-12/bin/postmaster -D /app/postgresql/data
root       4594  0.0  0.0 112816   976 pts/0    S+   18:53   0:00 grep --color=auto pg
[root@YZX-RD-37 app]# netstat -anlp | grep 4583
tcp        0      0 0.0.0.0:5432            0.0.0.0:*               LISTEN      4583/postmaster  

9、查看PG新的系统信息

[postgres@YZX-RD-37 ~]$ psql 
psql (12.6)
Type "help" for help.

postgres=# SHOW data_directory;
    data_directory    
----------------------
 /app/postgresql/data
(1 row)

 

 

 

 

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值