【问题标题】:Get databases from old PostgreSQL folder (win 10)从旧 PostgreSQL 文件夹中获取数据库(win 10)
【发布时间】:2023-03-23 13:19:02
【问题描述】:

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

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

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

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

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

【问题讨论】:

  • postgresql 日志中有什么错误?
  • @IS 感谢有关日志的问题!它有助于找到解决方案

标签: postgresql postgresql-12


【解决方案1】:

将文件夹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 服务启动时没有出现错误,并且可以恢复旧数据库。

【讨论】:

  • 经验教训:不要弄乱 DBMS 的数据文件。这些由 DBMS 管理,(格式可能取决于 Postgres 的主要版本号)那里没什么可看的。
猜你喜欢
  • 2019-07-04
  • 2019-08-12
  • 2011-08-14
  • 1970-01-01
  • 2019-09-29
  • 2017-09-28
  • 1970-01-01
  • 2018-02-20
  • 2021-08-27
相关资源
最近更新 更多