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.
- In a browser, navigate to Render.com.
- Sign in and open your dashboard.
- Select your existing PostgreSQL database service if it still appears.
- Delete that database service from Render.
- 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.
- From the Render dashboard, click the + New button and choose Postgres or PostgreSQL.
- 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.
- Click Create Database.
- Wait for the database to finish provisioning.
- 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.
- Copy the new External Database URL from your Render database.
- Open your local
.envfile. - Replace the old
DB_URLvalue 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.
- Return to the Render dashboard.
- Open the database details page and location the Internal Database URL in the connection information and copy this value.
- Next, open your web service for this course project.
- Go to the environment variable settings for that web service.
- Find the
DB_URLenvironment variable. - Replace the old value with the new Internal Database URL.
- 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.
- Open pgAdmin.
- Update your existing connection, using the connection information from the new Render database.
- Right click on the connection and select Properties.
- 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.
- On the Parameters tab, make sure the SSL mode is set to Require.
- 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.
- Open your
src/setup.sqlfile. - Run the SQL statements in pgAdmin against your new Render database.
- Verify that your tables and seed data were created successfully.
- Start your application locally and test that it still works.
- 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:
- Return to: Week Overview | Course Home