patroni / patroni

A template for PostgreSQL High Availability with Etcd, Consul, ZooKeeper, or Kubernetes
MIT License
6.78k stars 843 forks source link

Not honoring hugepages setting during initdb causes DB crash #2467

Closed howels closed 1 month ago

howels commented 1 year ago

Describe the bug On an OS where hugepages are enabled, if no hugepages resources are assigned in Kubernetes and the postgres instance is set to hugepages = off in the config then one would assume that the DB would not use hugepages. However, because the initdb process uses postgres.conf,sample instead of the actual specified configuration the applied setting is actually hugepages = try during initdb. In these case the initdb phase will attempt to allocate hugepages which are available in the OS, but it will be denied access by Kubernetes and fail.

To Reproduce Run a DB with no hugepages resources assigned on a OS with hugepages and with hugepages = off set in postgres conf.

Expected behavior When hugepages are disabled they should not be used, during initdb or otherwise. The inability to specify hugepages forces all DBs to use hugepages on any system where they are enabled, even if the hugepages are intended for other applications and not available to the DB Pods.

Additional context Issue has persisted for some time and the implementation goes against the spirit of the configuration options provided. Exceedingly awkward workaround such as https://github.com/zalando/patroni/issues/1393#issuecomment-1044380715 are not suitable for ongoing long-term usage.

CyberDem0n commented 1 year ago

This is outside of Patroni scope. The initdb doesn't provide a way to disable huge pages. Editing the sample.conf isn't an option either, Patroni simply doesn't have permissions for that.

waynerv commented 1 month ago

initdb now support a -c option to set server variables for the duration of initdb and all future server starts from pg16.

CyberDem0n commented 1 month ago

initdb now support a -c option to set server variables

Then we don't have to do anything, because users can do it via Patroni config:

bootstrap:
  initdb:
  - set: hugepages=off