โShow me how to create a managed Postgres database on Render and connect my deployed web service to it using the internal connection string.โ
15 โ [Optional] Add managed Postgres on Render
Category: Hosting & Deploy ยท Priority: Low ยท Optional
Render offers a free Postgres instance. Connect it to the app using the internal DB URL they provide.
โ ๏ธ OPTIONAL โ Only needed if deploying to Render with a database.
๐ฏ What is this task?
Render offers a free managed Postgres instance. Instead of running your own Postgres container in the cloud, you use Render's hosted database and connect your app to it via an internal connection URL.
๐ Step-by-step
Step 1 โ Create a Postgres database on Render
- Click "New +" โ "PostgreSQL"
- Name:
my-docker-app-db - Instance Type: Free
- Click "Create Database"
Step 2 โ Get the internal connection URL
On the database page, find the "Internal Database URL" โ it looks like:
postgresql://myuser:password@dpg-xxxxx-a/myapp
Copy this URL.
Step 3 โ Update your app's environment variables on Render
Go to your Web Service โ Environment tab โ Add:
| Key | Value |
|---|---|
DATABASE_URL | paste the Internal Database URL here |
Then update your index.js to use DATABASE_URL if you prefer the single-URL connection style, or break it into individual vars. Ask AI:
"Update my Node.js
pgPool connection to support both a singleDATABASE_URLenvironment variable and individualDB_HOST/DB_PORT/DB_NAME/DB_USER/DB_PASSWORDvariables as a fallback."
Step 4 โ Redeploy and test
After saving env vars, redeploy and hit https://your-app.onrender.com/db-test to confirm the database connection works.
โ Done when
- Render Postgres instance created
-
DATABASE_URLset in Web Service environment variables -
/db-testendpoint returns{ "status": "connected" }on the live URL
๐ Quiz
Answer all 1 questions correctly to complete this lesson.