放回原始数据文件夹后如何重新启动 PostgreSQL 服务?

How do i restart PostgreSQL service after putting back the original Data folder?

我正在编写一些批处理脚本,用于在 Windows 服务器上对 PostgreSQL 集群进行增量备份。

我将 Data 文件夹复制到另一个文件夹,运行 我的备份脚本,停止服务,删除 Data 文件夹,并尝试从 WAL 文件等恢复数据库。

这不行,因为我复制了错误的日志文件,我无法重新启动服务,所以我尝试复制回原来的数据文件夹,但我仍然无法启动服务.

我 运行 调用的第一个脚本:

pg_basebackup -Fp -D %BACKUPDIR%\full_%CURRENTDATE%

这是唯一实际最终与数据交互的行,但不是我事先复制的原始数据文件夹。

再次尝试启动服务时,出现以下错误消息:

The postgresql-x64-10 - PostgreSQL Server 10 service on Local Computer started and then stopped. 
Some services stop automatically if they are not in use by other services or programs.

我以前在 conf 文件中输入错误时遇到过这个问题,所以我猜这只是缺少某些内容时的标准错误消息。

发现我必须重做文件夹权限。

这是通过以下方式完成的:

5. Change permissions for the new data directory For the new data-dictionary folder: Right-click on it and click Properties. Under the Security Tab click “Edit...” and then “Add...”. Type “Network Service” and then click “Check Names”, make sure it has Modify and Full Control permissions and then click OK. Equally important PostgreSQL needs to be able to “see” the data-directory (see my ServerFault.StackEx question), i.e. it needs to have read access to the parent directories above it. So Right-click on the pg_db folder and under the Security Permissions add Network Services again, but this time it only needs Read & Execute as well as List folder contents permissions.

完整的 post 是一个很好的核对清单,供其他面临类似问题的人参考: https://radumas.info/blog/tutorial/2016/08/08/Migrating-PostgreSQL-Data-Directory-Windows.html