Database Initialization Configuration
October 28, 2025 ยท View on GitHub
This document explains how to configure custom DuckDB initialization SQL at startup instead of using the bundled initialization code.
Configuration Options
The application supports two methods for providing database initialization SQL, in order of priority:
1. Custom SQL File
Set the duckdb_init_sql_file environment variable to point to a custom SQL file:
export duckdb_init_sql_file=/path/to/your/custom-init.sql
Or in your .env file:
duckdb_init_sql_file=/path/to/your/custom-init.sql
2. Bundled Default (Fallback)
If no custom file is provided, the application will use the bundled src/app/db/duckdb_init.sql file.
Environment Variable Substitution
All initialization SQL (regardless of source) supports environment variable substitution using the ${VARIABLE_NAME} syntax. The following variables are automatically available:
UC_CATALOG_ENDPOINTUC_CATALOG_TOKENAZURE_STORAGE_ACCOUNT_NAMEAZURE_STORAGE_ACCOUNT_KEYAZURE_ACCOUNT_NAMEAZURE_CLIENT_IDAZURE_CLIENT_SECRETAZURE_TENANT_ID
Example Custom Initialization File
See examples/custom-duckdb-init.sql for a complete example of how to structure your custom initialization SQL.
Use Cases
Development vs Production
Use different initialization SQL for different environments:
Development (.env.dev):
duckdb_init_sql_file=./config/dev-duckdb-init.sql
Production (.env.prod):
duckdb_init_sql_file=./config/prod-duckdb-init.sql
Docker Deployment
Mount your custom initialization file and configure the path:
# In your Dockerfile
COPY custom-init.sql /app/config/init.sql
# Set environment variable
ENV duckdb_init_sql_file=/app/config/init.sql
Kubernetes ConfigMap
Create a ConfigMap with your initialization SQL:
apiVersion: v1
kind: ConfigMap
metadata:
name: duckdb-init-config
data:
init.sql: |
INSTALL delta;
LOAD delta;
CREATE SECRET (TYPE UC, TOKEN '${UC_CATALOG_TOKEN}', ENDPOINT '${UC_CATALOG_ENDPOINT}');
-- Your custom initialization here
Then mount it and configure the path in your deployment.
Dynamic File Generation
For dynamic configuration, generate an SQL file at runtime:
# Generate SQL file at runtime
cat > /tmp/custom-init.sql << EOF
INSTALL delta;
LOAD delta;
ATTACH '${ENVIRONMENT}' AS main (TYPE UC_CATALOG);
EOF
export duckdb_init_sql_file=/tmp/custom-init.sql
Migration from Hardcoded Configuration
If you were previously modifying the bundled src/app/db/duckdb_init.sql file:
- Copy your modified SQL to a new file (e.g.,
config/custom-init.sql) - Set
duckdb_init_sql_file=config/custom-init.sqlin your environment - The bundled file will remain unchanged and serve as a fallback
Troubleshooting
Initialization Logs
The application logs detailed information about which initialization source is being used:
"Using initialization SQL from configured file: /path/to/file"- Custom file config is active"Using bundled initialization SQL file: /path/to/bundled"- Fallback to bundled file"No initialization SQL available from any source, using fallback"- All sources failed
Common Issues
- File not found: Ensure the path in
duckdb_init_sql_fileexists and is readable - Permission errors: Ensure the application has read access to the custom SQL file
- SQL syntax errors: Check logs for specific SQL statement failures
- Environment variable substitution: Verify all referenced variables are set
Validation
You can validate your custom SQL before deployment:
# Test environment variable substitution
envsubst < your-custom-init.sql
# Test SQL syntax (requires DuckDB CLI)
duckdb -c ".read your-custom-init.sql"