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

0

I'm trying to get the plpython3u language working in PostgreSQL 11 (I'm working on a Windows 10 machine).

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.

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

To test the installation I tried creating the following function which I got from the 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

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.

python
postgresql
python-3.6
postgresql-11
plpython
asked on Stack Overflow Jan 17, 2020 by Bilesh Ganguly • edited Jan 17, 2020 by Bilesh Ganguly

2 Answers

2

I had to download python36.dll and save it in 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.

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.

Remove any DLL files from rogue downloads, get a Python 3 installation package and install it in the regular fashion.

answered on Stack Overflow Jan 17, 2020 by Laurenz Albe
0

As suggested by Laurenz Albe in his answer, the error was most probably being caused by the DLL file I downloaded.

Following is what I followed.

  1. Drop the extension using DROP EXTENSION plpython3u
  2. Remove the downloaded python36.dll from C:\Windows\System32
  3. Uninstall all installed Python versions in my machine
  4. Downloaded and installed (for all users) the 64-bit version of Python 3.6 (because that is what plpython3.dll was expecting)
  5. Added Python path to the Path variable of the environment variables (I did this during Python installation)
  6. Install extension again using CREATE EXTENSION plpython3u (it was able to successfully create the extension)

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
answered on Stack Overflow Jan 17, 2020 by Bilesh Ganguly

User contributions licensed under CC BY-SA 3.0