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:
- Export the data folder under the PostgreSQL installation directory (Installation Directory)
- Back up the current PostgreSQL installation directory (Installation Directory) to another directory
- 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-14
net stop postgresql-x64-14
here is Database Service, change according to the actual situation)
- Check and close the existing process of PostgreSQL in the task manager
- Remove the PostgreSQL service, execute directory jump to the bin directory under the PostgreSQL installation directory in CMD, and then enter ( postgresql-x64-14
pg_ctl unregister -N postgresql-x64-14
here is also Database Service) - 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
- Re-create the PostgreSQL service, ensure that the execution directory of CMD is under bin, enter
pg_ctl register -N postgresql-x64-14 -D "D:\Program Files\PostgreSQL\14\data"
- Start the service, CMD input
net start postgresql-x64-14
- 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