简体   繁体   English

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

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

I'm trying to get the plpython3u language working in PostgreSQL 11 (I'm working on a Windows 10 machine).我正在尝试让plpython3u语言在PostgreSQL 11 中工作(我正在Windows 10机器上工作)。

I was able to successfully install it using the following command.我能够使用以下命令成功安装它。

CREATE EXTENSION plpython3u;

I had to download python36.dll and save it in C:\\Windows\\System32 to successfully execute this because previously I was getting the following error.我必须下载python36.dll并将其保存在C:\\Windows\\System32才能成功执行此操作,因为之前我收到以下错误。

could not load library "C:/Program Files/PostgreSQL/11/lib/plpython3.dll": The specified module could not be found.无法加载库“C:/Program Files/PostgreSQL/11/lib/plpython3.dll”:找不到指定的模块。

To test the installation I tried creating the following function which I got from the PostgreSQL Docs .为了测试安装,我尝试创建从PostgreSQL Docs获得的以下函数。

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

But executing it gives me the following error.但是执行它会给我以下错误。

SQL Error [57P03]: FATAL: the database system is in recovery mode SQL 错误 [57P03]:致命:数据库系统处于恢复模式

Following is what I got from the logs.以下是我从日志中得到的。

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'

Any help will be appreciated.任何帮助将不胜感激。

I had to download python36.dll and save it in C:\\Windows\\System32我必须下载python36.dll并将其保存在C:\\Windows\\System32

Because of the lack of library versioning, the fact that the directory containing the executable is always on the shared library path and the ensuing sloppy habit of keeping random copies of the same shared library in various directories, Windows users got in the habit of downloading executable code from somewhere on the internet and running it.由于缺乏库版本控制、包含可执行文件的目录总是在共享库路径上以及随之而来的在不同目录中保留相同共享库的随机副本的草率习惯,Windows 用户养成了下载可执行文件的习惯从互联网上的某个地方编写代码并运行它。

This is a dangerous and detrimental practice.这是一种危险和有害的做法。 You obviously got the wrong incarnation of the Python shared library, or you are missing some other important files, and as a consequence PostgreSQL crashed when using it.显然,您弄错了 Python 共享库的化身,或者您丢失了一些其他重要文件,结果 PostgreSQL 在使用它时崩溃了。

Remove any DLL files from rogue downloads, get a Python 3 installation package and install it in the regular fashion.从恶意下载中删除任何 DLL 文件,获取 Python 3 安装包并以常规方式安装。

As suggested by Laurenz Albe in his answer, the error was most probably being caused by the DLL file I downloaded.正如Laurenz Albe在他的回答中所建议的那样,该错误很可能是由我下载的 DLL 文件引起的。

Following is what I followed.以下是我所遵循的。

  1. Drop the extension using DROP EXTENSION plpython3u使用DROP EXTENSION plpython3u删除扩展
  2. Remove the downloaded python36.dll from C:\\Windows\\System32C:\\Windows\\System32删除下载的python36.dll
  3. Uninstall all installed Python versions in my machine卸载我机器中所有已安装的 Python 版本
  4. Downloaded and installed (for all users) the 64-bit version of Python 3.6 (because that is what plpython3.dll was expecting)为所有用户下载并安装了 64 位版本的Python 3.6 (因为这是plpython3.dll所期望的)
  5. Added Python path to the Path variable of the environment variables (I did this during Python installation)在环境变量的Path变量中添加了 Python 路径(我在 Python 安装过程中这样做了)
  6. Install extension again using CREATE EXTENSION plpython3u (it was able to successfully create the extension)使用CREATE EXTENSION plpython3u再次安装扩展(它能够成功创建扩展)

I was able to successfully test it out using the following sample function.我能够使用以下示例函数成功对其进行测试。

Sample Code:示例代码:

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

Query询问

SELECT pymax(4,2)

Output输出

4

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM