如何更改PostgreSQL数据目录? [英] how to change PostgreSQL data directory?

查看:665
本文介绍了如何更改PostgreSQL数据目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows7上的postgresql 9.2上更改数据目录时遇到问题:

I am having a problem changing the data directory on postgresql 9.2 on windows7:

我试图更改我的数据目录:

i`m trying to change my data directory:

如何使用pgAdmin更改postgreSQL上的数据目录?

how can i change data directory on postgreSQL with pgAdmin?

推荐答案

在pgAdmin内部无法实现(或任何其他SQL客户端,因为您需要停止Postgres服务器才能移动数据目录)

This not possible from within pgAdmin (or any other SQL client because you need to stop the Postgres server in order to move the data directory)

要移动目录,请执行以下步骤:

To move the directory, use these steps:


  1. 停止Postgres(可以使用控制面板找到正确的服务名称)

  1. Stop Postgres (you can use the control panel to find the correct service name)

net stop <name_of_the_service>


  • 确保Postgres未运行(例如使用ProcessMonitor)

  • 使用以下命令删除Windows服务

  • Make sure Postgres is not running (e.g. using ProcessMonitor)
  • Remove the Windows service using

    pg_ctl unregister -N <name_of_the_service>
    


  • 确保Postgres未运行

  • 移动数据目录到新位置(或仅复制它,以便进行备份)

  • 使用重新创建服务(这将分配 postgres 作为服务名称)

    pg_ctl register -N postgres -D c:\new\path\to\datadir
    


  • 启动服务

  • start the service

    net start postgres 
    


  • 运行psql验证Postgres是否已启动并正在运行

  • run psql to verify that Postgres is up and running

    psql -U postgres
    


  • 验证运行中的服务器正在使用新的数据目录

  • Verify the running server is using the new data directory

    show data_directory;
    


  • <$ c $使用方法的详细信息c> pg_ctl 可以在手册中找到:

    http://www.postgresql.org/docs/current/static/app-pg-ctl.html

    Details on how to use pg_ctl can be found in the manual:
    http://www.postgresql.org/docs/current/static/app-pg-ctl.html

    这篇关于如何更改PostgreSQL数据目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆