PostgreSQL 11:错误 [57P03]:致命:数据库系统处于恢复模式

PostgreSQL 11: Error [57P03]: FATAL: the database system is in recovery mode

我正在尝试让 plpython3u 语言在 PostgreSQL 11 中工作(我正在开发 Windows 10 机)。

我能够使用以下命令成功安装它。

CREATE EXTENSION plpython3u;

我必须下载 python36.dll 并将其保存在 C:\Windows\System32 中才能成功执行此操作,因为之前我遇到了以下错误。

could not load library "C:/Program Files/PostgreSQL/11/lib/plpython3.dll": The specified module could not be found.

为了测试安装,我尝试创建以下从 PostgreSQL Docs.

获得的函数
CREATE FUNCTION pymax (a integer, b integer)
  RETURNS integer
AS $$
  if a > b:
    return a
  return b
$$ LANGUAGE plpython3u;

但是执行它会出现以下错误。

SQL Error [57P03]: FATAL: the database system is in recovery mode

以下是我从日志中得到的。

Current thread 0x000035b8 (most recent call first):
2020-01-16 20:10:17.136 CST [6980] LOG:  server process (PID 12532) was terminated by exception 0xC0000409
2020-01-16 20:10:17.136 CST [6980] DETAIL:  Failed process was running: CREATE FUNCTION public.pymax (a integer, b integer)

      RETURNS integer

    AS $$

      if a > b:

        return a

      return b

    $$ LANGUAGE plpython3u
2020-01-16 20:10:17.136 CST [6980] HINT:  See C include file "ntstatus.h" for a description of the hexadecimal value.
2020-01-16 20:10:17.136 CST [6980] LOG:  terminating any other active server processes
2020-01-16 20:10:17.229 CST [5636] WARNING:  terminating connection because of crash of another server process
2020-01-16 20:10:17.229 CST [5636] DETAIL:  The postmaster has commanded this server process to roll back the current transaction and exit, because another server process exited abnormally and possibly corrupted shared memory.
2020-01-16 20:10:17.229 CST [5636] HINT:  In a moment you should be able to reconnect to the database and repeat your command.
2020-01-16 20:10:17.246 CST [6980] LOG:  all server processes terminated; reinitializing
2020-01-16 20:10:17.373 CST [4944] LOG:  database system was interrupted; last known up at 2020-01-16 20:09:02 CST
2020-01-16 20:10:17.392 CST [9880] FATAL:  the database system is in recovery mode
2020-01-16 20:10:17.509 CST [11412] FATAL:  the database system is in recovery mode
2020-01-16 20:10:17.623 CST [12472] FATAL:  the database system is in recovery mode
2020-01-16 20:10:17.730 CST [12480] FATAL:  the database system is in recovery mode
2020-01-16 20:10:17.843 CST [12432] FATAL:  the database system is in recovery mode
2020-01-16 20:10:17.951 CST [12492] FATAL:  the database system is in recovery mode
2020-01-16 20:10:18.060 CST [12744] FATAL:  the database system is in recovery mode
2020-01-16 20:10:18.175 CST [12160] FATAL:  the database system is in recovery mode
2020-01-16 20:10:18.298 CST [13084] FATAL:  the database system is in recovery mode
2020-01-16 20:10:18.828 CST [4944] LOG:  database system was not properly shut down; automatic recovery in progress
2020-01-16 20:10:18.835 CST [4944] LOG:  redo starts at 0/17FF400
2020-01-16 20:10:18.835 CST [4944] LOG:  redo done at 0/17FF438
2020-01-16 20:10:19.044 CST [6980] LOG:  database system is ready to accept connections
Fatal Python error: Py_Initialize: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'

任何帮助将不胜感激。

I had to download python36.dll and save it in C:\Windows\System32

由于缺乏库版本控制,包含可执行文件的目录始终在共享库路径上,以及随之而来的在不同目录中随机保存相同共享库副本的草率习惯,Windows 用户养成了从互联网某处下载可执行代码并 运行 它的习惯。

这是一种危险且有害的做法。很明显,您得到了错误的 Python 共享库,或者您丢失了一些其他重要文件,结果 PostgreSQL 在使用它时崩溃了。

从流氓下载中删除所有 DLL 文件,获取 Python 3 安装包并以常规方式安装它。

正如Laurenz Albe在他的回答中所建议的那样,错误很可能是由我下载的DLL文件引起的。

以下是我关注的。

  1. 使用 DROP EXTENSION plpython3u
  2. 删除扩展
  3. C:\Windows\System32
  4. 中删除下载的 python36.dll
  5. 卸载我机器上所有已安装的 Python 版本
  6. 已下载并安装(针对所有用户)Python 3.6 的 64 位版本(因为这是 plpython3.dll 所期望的)
  7. 在环境变量的 Path 变量中添加了 Python 路径(我在 Python 安装期间这样做了)
  8. 使用CREATE EXTENSION plpython3u再次安装扩展(能够成功创建扩展)

我能够使用以下示例函数成功测试它。

示例代码:

CREATE FUNCTION pymax (a integer, b integer)
  RETURNS integer
AS $$
  if a > b:
    return a
  return b
$$ LANGUAGE plpython3u;

查询

SELECT pymax(4,2)

输出

4