By tomahony
I have a Django app running on the app platform. I want to switch over to use connection pooling.
my_db.my_pool.Additionally, you can use these same variable names to refer to your database connection pool (PostgreSQL only). To do so, use the syntax
${<database component name>.<connection pool name>.VARIABLE_NAME}. For example, to create a bindable variable for a pool’s connection string, you can use${mydb.mypool.DATABASE_URL}.
So now my (abbreviated) appspec now looks like:
databases:
- cluster_name: postgres
db_name: my_db
db_user: my_db
engine: PG
name: postgres
production: true
version: "13"
# ...
envs:
- key: DATABASE_URL
scope: RUN_AND_BUILD_TIME
value: ${postgres.my_pool.DATABASE_URL}
This flat out doesn’t work. The error from the build is:
07:24] django.core.exceptions.ImproperlyConfigured: Set the {postgres.my_pool.DATABASE_URL}
Which would indicate that the environment variable hasn’t been set correctly. Why doesn’t this format work?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
To follow up, if I set two environment variables:
envs:
- key: DATABASE_URL
scope: RUN_AND_BUILD_TIME
value: ${postgres.DATABASE_URL}
- key: DATABASE_POOL_URL
scope: RUN_AND_BUILD_TIME
value: ${postgres.my_pool.DATABASE_URL}
After deployment, echoing the two variables via the console confirms that ${postgres.my_pool.DATABASE_URL} format doesn’t work:
/app # echo $DATABASE_POOL_URL
${postgres.my_pool.DATABASE_URL}
The variable isn’t being replaced, it’s just being set as the literal string ${postgres.my_pool.DATABASE_URL}. In other words, variable binding isn’t working.
Hi there,
I’ve tested this with the following app spec file and it seems to be working as expected:
alerts:
- rule: DEPLOYMENT_FAILED
- rule: DOMAIN_FAILED
databases:
- cluster_name: db-postgresql-fra1-1234
db_name: defaultdb
db_user: doadmin
engine: PG
name: db-postgresql-fra1-1234
production: true
version: "15"
ingress:
rules:
- component:
name: sample-nodejs
match:
path:
prefix: /
name: sample-nodejs
region: fra
services:
- environment_slug: node-js
envs:
- key: DATABASE_URL
scope: RUN_TIME
value: ${db-postgresql-fra1-1234.your-pool.DATABASE_URL}
git:
branch: main
repo_clone_url: https://github.com/digitalocean/sample-nodejs.git
http_port: 8080
instance_count: 1
instance_size_slug: basic
name: sample-nodejs
When you attached the database to your app, did you also select the pool?

Also as a side note, database values are not available during build time but are available at runtime.
Best,
Bobby
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.