PostgreSQL修改数据目录方法记录

查看当前数据库的data目录

进入psql查看当前数据库的data目录

[root@localhost ~]# su - postgres
-bash-4.1$ psql
psql (8.4.18)
Type "help" for help.

postgres=# show data_directory ;
         data_directory          
---------------------------------
 /postgres_5432
(1 row)

关闭数据库

[root@localhost ~]# /bin/su -l postgres -c "/usr/bin/pg_ctl -D /postgres_5432/  stop"
# 如果是yum方式安装的话可以使用service postgresql stop或systemctl stop postgresql

把当前数据库拷贝到新位置

用rsync方式把数据库内容拷贝到新位置

  • -a 保留的权限和其他目录属性, 能避免未来的权限问题
  • -v 提供详细输出,以便能够看到进度
[root@localhost ~]# rsync -av /postgres_5432 /data/pgdata_5432

修改postgresql.conf配置文件

编辑postgresql.conf文件,找到data_directory字段,修改该字段,保存退出
如果配置文件中没有该字段则直接加在文件末尾即可

data_directory = '/data/pgdata_5432/postgres_5432/'

启动数据库

[root@localhost ~]# /bin/su -l postgres -c "/usr/bin/pg_ctl -D /postgres_5432/  start"
# 如果是yum方式安装的话可以使用service postgresql start或systemctl start postgresql

查看数据库data目录

[root@localhost ~]# su - postgres
-bash-4.1$ psql
psql (8.4.18)
Type "help" for help.

postgres=# show data_directory ;
         data_directory          
---------------------------------
 /data/pgdata_5432/postgres_5432
(1 row)

删除备份

因为我这个数据库特殊,数据文件和配置文件都放在同一个目录下了,如果是标准安装的话,上一步数据库启动没问题以后可以将原数据库的数据文件删除了,我这里没有删除

重启

[root@localhost ~]# /bin/su -l postgres -c "/usr/bin/pg_ctl -D /postgres_5432/  stop"
[root@localhost ~]# /bin/su -l postgres -c "/usr/bin/pg_ctl -D /postgres_5432/  start"
# 如果是yum方式安装的话可以使用service postgresql restart或systemctl restart postgresql
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值