how to change PostgreSQL data directory?

前端 未结 1 1997
后悔当初
后悔当初 2021-02-06 18:01

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

i`m trying to change my data directory:

how can i change data directory on postg

1条回答
  •  臣服心动
    2021-02-06 18:45

    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. Stop Postgres (you can use the control panel to find the correct service name)

      net stop 
      
    2. Make sure Postgres is not running (e.g. using ProcessMonitor)
    3. Remove the Windows service using

      pg_ctl unregister -N 
      
    4. make sure Postgres is not running
    5. move the data directory to the new location (or maybe only copy it, so that you have a backup)
    6. re-create the service using (this assigns postgres as the service name)

      pg_ctl register -N postgres -D c:\new\path\to\datadir
      
    7. start the service

      net start postgres 
      
    8. run psql to verify that Postgres is up and running

      psql -U postgres
      
    9. Verify the running server is using the new data directory

      show data_directory;
      

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

    0 讨论(0)
提交回复
热议问题