zalando / postgres-operator

Postgres operator creates and manages PostgreSQL clusters running in Kubernetes
https://postgres-operator.readthedocs.io/
MIT License
4.37k stars 980 forks source link

Restore of db from WAL is impossible if public schema does not exists #2742

Closed jovanradin closed 2 months ago

jovanradin commented 2 months ago

Please, answer some short questions which should help us to understand your problem / question better?

When i try to restore db from WAL backup i have following error:

ERROR:  schema "public" does not exist
2024-08-23 13:28:47,420 ERROR: post_init script /scripts/post_init.sh "zalandos" returned non-zero code 3
2024-08-23 13:28:47,421 INFO: removing initialize key after failed attempt to bootstrap the cluster
2024-08-23 13:28:47,459 INFO: renaming data directory to /home/postgres/pgdata/pgroot/data.failed
Traceback (most recent call last):
  File "/usr/local/bin/patroni", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.10/dist-packages/patroni/__main__.py", line 344, in main
    return patroni_main(args.configfile)
  File "/usr/local/lib/python3.10/dist-packages/patroni/__main__.py", line 232, in patroni_main
    abstract_main(Patroni, configfile)
  File "/usr/local/lib/python3.10/dist-packages/patroni/daemon.py", line 174, in abstract_main
    controller.run()
  File "/usr/local/lib/python3.10/dist-packages/patroni/__main__.py", line 192, in run
    super(Patroni, self).run()
  File "/usr/local/lib/python3.10/dist-packages/patroni/daemon.py", line 143, in run
    self._run_cycle()
  File "/usr/local/lib/python3.10/dist-packages/patroni/__main__.py", line 201, in _run_cycle
    logger.info(self.ha.run_cycle())
  File "/usr/local/lib/python3.10/dist-packages/patroni/ha.py", line 1972, in run_cycle
    info = self._run_cycle()
  File "/usr/local/lib/python3.10/dist-packages/patroni/ha.py", line 1786, in _run_cycle
    return self.post_bootstrap()
  File "/usr/local/lib/python3.10/dist-packages/patroni/ha.py", line 1670, in post_bootstrap
    self.cancel_initialization()
  File "/usr/local/lib/python3.10/dist-packages/patroni/ha.py", line 1663, in cancel_initialization
    raise PatroniFatalException('Failed to bootstrap cluster')
patroni.exceptions.PatroniFatalException: Failed to bootstrap cluster

We probably just need:

CREATE SCHEMA IF NOT EXISTS public

In post_init.sh to successfully add extensions etc

Also if anyone knows solution how i can restore db without creating my own docker image, please help :)

jovanradin commented 2 months ago

I just changed create_user_functions.sql, added CREATE SCHEMA IF NOT EXISTS public; and with custom docker image restore now works. Still think that this should be added in official containers.

I also created same issue in zalando/spilo repo, closing this issue.