CSE 340: Web Backend Development

W05 Learning Activity: Re-Create Your Render Database

Overview

In this activity, you will re-create your PostgreSQL database at Render, update your environment variables, and reconnect your application to the new database.

Why Now?

Render's free PostgreSQL databases are deleted after about 30 days. Since you first created your database in Week 02, this is a good time to re-create it so it remains available through the rest of the course.

Activity Instructions

Complete the following steps to replace your Render database and reconnect your project to it.

Delete the Old Database at Render

If your old database still exists, delete it before creating a new one.

  1. In a browser, navigate to Render.com.
  2. Sign in and open your dashboard.
  3. Select your existing PostgreSQL database service if it still appears.
  4. Delete that database service from Render.
  5. If the database has already been removed by Render, simply continue to the next step.

Create a New PostgreSQL Database at Render

Now create a fresh PostgreSQL database, similar to the one you created in Week 02.

  1. From the Render dashboard, click the + New button and choose Postgres or PostgreSQL.
  2. Complete the database form.
    • Name: Use a unique name for your database.
    • Project: Select your project.
    • Database: Use the same name as your database service, or a slight variation if needed.
    • User: Use the same name as your database to make it easier to remember.
    • Region: Select the same region as your web service.
    • PostgreSQL version: The default is fine.
    • Plan Options / Instance Type: Select the free plan.
  3. Click Create Database.
  4. Wait for the database to finish provisioning.
  5. Open the database details page and locate the External Database URL in the connection information.

Update Your Local Environment Variables

Your local application must now use the new database connection string.

  1. Copy the new External Database URL from your Render database.
  2. Open your local .env file.
  3. Replace the old DB_URL value with the new connection string.
DB_URL=your_new_render_database_url_here

New Connection String

Because this is a brand new database, your old connection string will no longer work. Your local Node.js application must use the new DB_URL value.

Update Your Hosted Environment Variables at Render

Your deployed web service also needs to point to the new database.

  1. Return to the Render dashboard.
  2. Open the database details page and location the Internal Database URL in the connection information and copy this value.
  3. Next, open your web service for this course project.
  4. Go to the environment variable settings for that web service.
  5. Find the DB_URL environment variable.
  6. Replace the old value with the new Internal Database URL.
  7. Save the change and allow Render to redeploy your application if needed.

Reconnect pgAdmin to the New Database

You also need pgAdmin connected to the new database so you can restore your tables and data.

  1. Open pgAdmin.
  2. Update your existing connection, using the connection information from the new Render database.
  3. Right click on the connection and select Properties.
  4. On the Connection tab, update the connection information with the new host name, database name, username, and password as found in the External Database URL from Render.
  5. On the Parameters tab, make sure the SSL mode is set to Require.
  6. Connect to the new database and verify that the connection works.

Restore Your Database Structure and Data

Because this database is brand new, it does not contain any tables yet. Use your saved SQL file to rebuild it.

  1. Open your src/setup.sql file.
  2. Run the SQL statements in pgAdmin against your new Render database.
  3. Verify that your tables and seed data were created successfully.
  4. Start your application locally and test that it still works.
  5. Open your deployed site and verify that it also works with the new database.

Keep your setup.sql file updated

Your src/setup.sql file should always contain the SQL needed to rebuild your database. As you add more tables later in the course, keep adding those changes to this file.

Next Step

Complete the other Week 05 Learning Activities.

Other Links: