Project 1 โ€บ 15 Add managed Postgres on RenderGitHub โ†—
๐Ÿค– AI Prompt โ€” stuck? paste this

โ€œ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

  1. Click "New +" โ†’ "PostgreSQL"
  2. Name: my-docker-app-db
  3. Instance Type: Free
  4. 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:

KeyValue
DATABASE_URLpaste 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 pg Pool connection to support both a single DATABASE_URL environment variable and individual DB_HOST/DB_PORT/DB_NAME/DB_USER/DB_PASSWORD variables 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_URL set in Web Service environment variables
  • /db-test endpoint returns { "status": "connected" } on the live URL

๐Ÿ“ Quiz

Answer all 1 questions correctly to complete this lesson.

1. What's an advantage of managed Postgres on Render?
โ† PreviousPass the quiz to completeNext โ†’