从旧的PostgreSQL文件夹中获取数据库Win 10

问题描述

我需要从Program Files(win 10)中的旧Postgresql文件夹中获取数据库

我尝试通过注册表更改数据路径(ImagePath 从当前目录到旧Postgresql数据文件夹在HKEY_LOCAL_MACHINE\SYstem\CurrentControlSet\Services\postgresql-x64-12)处“ -D”之后的值。

我还尝试用旧文件(已替换C:\Program Files\Postgresql\12\data\base and C:\Program Files\Postgresql\12\data\global)的数据)替换Postgresql当前文件夹中的文件

在两种情况下,尝试启动postgresql-x64-12服务时均发生错误错误消息:the postgresql-x64-12 service on local computer started and then stopped.如果某些服务未被其他服务或程序使用,则会自动停止。

如何从旧的../Program Files/Postgresql文件夹中获取数据库

解决方法

将文件夹C:\Program Files\PostgreSQL\12\data\baseC:\Program Files\PostgreSQL\12\data\global替换为旧文件夹并尝试启动postgresql-x64-12服务后,出现了一个日志文件,其中包含以下内容:

LOG: database system was shut down at ...
LOG: invalid primary checkpoint record
PANIC: could not locate a valid checkpoint record
LOG: startup process (PID 17452) was terminated by exception 0xC0000409
HINT: See C include file "ntstatus.h" for a description of the hexadecimal value.
LOG: aborting startup due to startup process failure
LOG: database system is shut down

由于出现消息PANIC: could not locate a valid checkpoint record,我使用了pg_resetwal:在PowerShell中,我打开了文件夹C:\Program Files\PostgreSQL\12\bin,然后运行了命令.\pg_resetwal.exe -f -D "C:\Program Files\PostgreSQL\12\data在某些情况下,值得使用不带-f的命令,对于Postgres的其他版本,也可能需要其他命令。详细信息:https://stackoverflow.com/a/8812934/14145682.

此后,该服务也没有启动,并且日志中出现以下错误:

FATAL: could not access status of transaction
DETAIL: Could not read from file "pg_multixact/members/0000" at offset 8192: read too few bytes.

因此,我用旧文件替换了C:\Program Files\PostgreSQL\12\data\pg_multixact文件夹中的文件。

完成这些步骤后,postgresql-x64-12服务已启动且没有错误,并且可以还原旧数据库。