Replace PostgreSQL data and restart the service

Change the PostgreSQL data folder and restart the PostgreSQL service to adapt to the scenario:

  • The system crashes, and the PostgreSQL data and services need to be restored
  • A PostgreSQL backup/restore method that is usually available

Steps:

  1. Export the data folder under the PostgreSQL installation directory (Installation Directory)
  2. Back up the current PostgreSQL installation directory (Installation Directory) to another directory
  3. Stop the PostgreSQL service (Database Service)
    • You can enter services.msc during operation to close the PostgreSQL service (Database Service) in the startup window
    • Or enter it in CMD ( postgresql-x64-14net stop postgresql-x64-14 here is Database Service, change according to the actual situation)
  4. Check and close the existing process of PostgreSQL in the task manager
  5. Remove the PostgreSQL service, execute directory jump to the bin directory under the PostgreSQL installation directory in CMD, and then enter ( postgresql-x64-14pg_ctl unregister -N postgresql-x64-14 here is also Database Service)
  6. Change the name of the data folder in the PostgreSQL directory to data_back, and then copy the data file in the backup PostgreSQL directory to the current PostgreSQL directory
  7. Re-create the PostgreSQL service, ensure that the execution directory of CMD is under bin, enterpg_ctl register -N postgresql-x64-14 -D "D:\Program Files\PostgreSQL\14\data"
  8. Start the service, CMD inputnet start postgresql-x64-14
  9. Open pgAdmin and click to connect to the server, the host enters the 127.0.0.1 password, enters the previous password, and clicks OK to connect to the previous server

Guess you like

Origin blog.csdn.net/hekaiyou/article/details/126491052