Skip to main content

Database Bootstrap Troubleshooting

Guidance for PostgreSQL application database setup after infrastructure provisioning and before or after Helm deployment.

Bootstrap script: create-dbs-azure.sh (deployment repository) or equivalent SQL from sql/grant_application_schemas.sql.

Related: Infrastructure — PostgreSQL, Key Vault Secrets, Scripts Reference — Database creation

Overview

Infrastructure provisioning creates:

  • PostgreSQL Flexible Server and application database (e.g. bighammer_db_<env>)
  • Database users: admin, bh_dev_user, bh_app_user, keycloak_db_user
  • Key Vault passwords: azure-postgres-master-password, bh-app-user-password, bh-kcdbpwd

Provisioning does not always create application schemas or grants. Run create-dbs-azure.sh as the admin user on the application database.

Infrastructure (instance, database, users, Key Vault passwords)
→ create-dbs-azure.sh (schemas and grants on application database)
→ Helm deploy / pod startup

Running the bootstrap script before app deployment avoids schema ownership and permission errors.

If Helm deploys before bootstrap, pods may create schemas as the wrong user. Recovery steps are in Recovery — wrong schema ownership below.

Prerequisites

Verify before running bootstrap or debugging pod errors:

CheckExpected
Application databaseExists; name matches POSTGRES_DB in Helm values
Usersbh_dev_user, bh_app_user exist
Key Vault passwordsazure-postgres-master-password, bh-app-user-password match PostgreSQL users
Helm migration userPOSTGRES_USER: bh_dev_user
Helm runtime userBH_APP_USER: bh_app_user
remoteSecrets.postgres.passwordazure-postgres-master-password or bh-dev-user-password per your overlay
Bootstrap executedFull schema grants on application database
Bootstrap identityScript run as PostgreSQL admin with DDL privileges

Credential model (dual-role)

K8s env varsDB userKey Vault secretPurpose
POSTGRES_USER / POSTGRES_PASSWORDbh_dev_userazure-postgres-master-password or bh-dev-user-passwordAlembic, migrations, DDL
BH_APP_USER / BH_APP_USER_PASSWORDbh_app_userbh-app-user-passwordRuntime SQLAlchemy queries (DML)

Keycloak server DB (separate): keycloak_db_user / bh-kcdbpwd on keycloak_db_<env>.

Running create-dbs-azure.sh

When the database and users already exist (typical IaC flow):

  1. Connect as admin to the application database.
  2. Ensure TARGET_DB in config matches POSTGRES_DB in Helm values.
  3. Run ./create-dbs-azure.sh — idempotent when AUTO_SKIP_EXISTING_DATABASES is enabled.
  4. Confirm CREATE EXTENSION IF NOT EXISTS vector succeeds on catalog_db (requires admin privileges).

Common errors

Error / symptomWhat to checkFix
password authentication failed for user "bh_dev_user"POSTGRES_PASSWORD ExternalSecret; Key Vault vs PostgreSQLAlign secret with DB user; refresh ExternalSecret; redeploy
password authentication failed for user "bh_app_user"BH_APP_USER_PASSWORD; Key Vault bh-app-user-passwordAlign secret with DB user
permission denied for schema <name> (Alembic / bh_dev_user)Schema owner; POSTGRES_USER in valuesOwner should be bh_dev_user. If bh_app_user owns schemas, see Recovery
permission denied for schema catalog_db (runtime / bh_app_user)has_schema_privilege('bh_app_user', 'catalog_db', 'USAGE')Re-run grant SQL as bh_dev_user
permission denied for schema celery_db at pod startupGrants on celery_dbRe-run full bootstrap grants for all six schemas
Cross-schema query failsApp user USAGE on every schema the service queriesGrant USAGE on all required schemas
Bootstrap hangsActive pod DB connectionsScale affected deployments to 0; retry
CREATE EXTENSION vector failsExtension allow-list on Flexible ServerEnable vector on server; run as admin

Diagnostic queries

Run on the application database.

Session:

SELECT current_user, current_database();

Schema ownership (expect bh_dev_user for all application schemas):

SELECT n.nspname AS schema, r.rolname AS owner
FROM pg_namespace n
JOIN pg_roles r ON r.oid = n.nspowner
WHERE n.nspname IN (
'catalog_db', 'agent_db', 'audit_db',
'celery_db', 'keycloakapi_db', 'llm_observability_db'
);

Recovery — wrong schema ownership

If pods created schemas as bh_app_user before bootstrap:

  1. Scale platform deployments to 0.
  2. As admin, reassign ownership to bh_dev_user:
REASSIGN OWNED BY bh_app_user TO bh_dev_user;
  1. Re-run grant sections from sql/grant_application_schemas.sql as bh_dev_user.
  2. Scale deployments back up.

Post-fix verification

  • Diagnostic queries: all schemas owned by bh_dev_user; app user has USAGE on required schemas.
  • Pod logs: schema setup and alembic upgrade head complete without permission denied.
  • Restart affected deployments after grant changes.

Platform-managed Key Vault secrets

Infrastructure provisioning creates prerequisite DB and SSL secrets. Do not recreate them manually — see Platform prerequisites.

Integration and license secrets: see install scripts in Scripts Reference.

TopicLink
ScriptsScripts Reference
SecretsKey Vault Secrets
GCP equivalentGCP Database Bootstrap Troubleshooting
General troubleshootingTroubleshooting