charts
charts copied to clipboard
[bitnami/postgresql] Initdb sql scripts do not run due to env var mismatch between chart and container.
Name and Version
bitnami/postgresql 15.5.23
What architecture are you using?
amd64
What steps will reproduce the bug?
- Kubernetes 1.29 (doesn't matter)
- Install chart with config
Are you using any custom parameters or values?
chart config:
image:
debug: true
postgresqlSharedPreloadLibraries: "pg_stat_statements"
primary:
initdb:
user: "postgres"
password: "admin-password" # set via secret
scripts:
init.sql: |
CREATE EXTENSION pg_stat_statements;
What is the expected behavior?
Init SQL should have ran and achieved enabling extension:
$ psql -U postgres
Password for user postgres:
psql (16.4)
Type "help" for help.
postgres=# \dx
List of installed extensions
Name | Version | Schema | Description
--------------------+---------+------------+------------------------------------------------------------------------
pg_stat_statements | 1.10 | public | track planning and execution statistics of all SQL statements executed
plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language
(2 rows)
What do you see instead?
Log shows that the script worked but it had not:
postgresql 11:37:33.53 INFO ==> Loading custom scripts...
postgresql 11:37:33.53 INFO ==> Loading user's custom files from /docker-entrypoint-initdb.d ...
postgresql 11:37:33.54 INFO ==> Starting PostgreSQL in background...
server starting
2024-10-08 11:37:33.557 GMT [142] LOG: pgaudit extension initialized
2024-10-08 11:37:33.565 GMT [142] LOG: starting PostgreSQL 16.4 on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit
2024-10-08 11:37:33.565 GMT [142] LOG: listening on IPv6 address "::1", port 5432
2024-10-08 11:37:33.565 GMT [142] LOG: listening on IPv4 address "127.0.0.1", port 5432
2024-10-08 11:37:33.566 GMT [142] LOG: listening on Unix socket "/tmp/.s.PGSQL.5432"
2024-10-08 11:37:33.568 GMT [147] LOG: database system was shut down at 2024-10-08 11:37:33 GMT
2024-10-08 11:37:33.571 GMT [142] LOG: database system is ready to accept connections
postgresql 11:37:34.56 DEBUG ==> Executing /docker-entrypoint-initdb.d/..2024_10_08_11_37_31.3173819220/init.sql
CREATE EXTENSION
postgresql 11:37:34.58 INFO ==> Enabling remote connections
postgresql 11:37:34.59 INFO ==> Stopping PostgreSQL...
Additional information
When updated the config and added:
primary:
extraEnvVars:
- name: POSTGRESQL_DATABASE
value: postgres
Then re-created the helm deployment, and everything worked fine.
Seems like the chart is using env var POSTGRES_DATABASE while scripts in the bitnami containers expect POSTGRESQL_DATABASE.
https://github.com/bitnami/containers/blob/main/bitnami/postgresql/16/debian-12/rootfs/opt/bitnami/scripts/libpostgresql.sh#L735 https://github.com/bitnami/charts/blob/main/bitnami/postgresql/templates/primary/statefulset.yaml#L257