Create and Connect to a PostgreSQL Database

Migrating from Heroku?

We’re previewing an upcoming tool for low-downtime PostgreSQL migration and are looking for organizations with a large (50+ GB) Heroku Postgres database to migrate. We’ll work with selected organizations to help ensure a successful, speedy migration.

Apply for the preview.

Render provides fully managed PostgreSQL databases for encrypted, scalable storage of relational data.

All paid PostgreSQL databases provide point-in-time recovery and on-demand logical backups. Larger instances support read replicas and high availability for improved performance and reliability.

Quickstarts

These Render quickstarts include steps for provisioning a PostgreSQL database:

Create your database

Flexible PostgreSQL plans are now available for all Render workspaces.

You can now set your database’s storage separately from its RAM and CPU. Learn more.

  1. Go to dashboard.render.com/new/database, or select New > PostgreSQL from the Render Dashboard.

    This form appears:

    New PostgreSQL creation form.

  2. Provide a helpful Name for your database.

    • You can change this value at any time.
  3. Optionally fill in the Database and/or User fields if you want to set your PostgreSQL dbname and/or username.

    • Render generates values for either of these that you don’t specify.
    • You can’t change these values after creating your database.
  4. Choose a Region to run your database in.

    • Choose the same region as your services that will connect to the database. This minimizes latency and enables communication over your private network.
  5. Optionally change the PostgreSQL Version if you want to use an older version.

    • Major versions 13 through 16 are available for all new instances.
    • Versions 11 and 12 are available for workspaces that have at least one existing database on the corresponding version.
  6. Scroll down and select an instance type for your database. This determines its available RAM and CPU.

    Learn about Free instance type limitations.

    Selecting a PostgreSQL instance type

    You can change your instance type later.

  7. Scroll down and set your database’s initial storage, in GB.

    • You can specify 1 GB or any multiple of 5 GB.
    • You can increase your storage later, but you can’t decrease it.
  8. Click Create Database.

You’re all set! Your new database’s status updates to Available in the Render Dashboard when it’s ready to use.

Connect to your database

Every Render PostgreSQL database has two different URLs for incoming connections:

  • An internal URL for connections from your other Render services hosted in the same region
  • An external URL for connections from everything else
Render
Internal
URL
External
URL
Web
service
DB
Your dev machine
(admin tools, etc.)

Use the internal URL wherever possible. It minimizes query latency by enabling communication over your private network.

Both URLs are available from the Connect menu in the top-right corner of your database’s page in the Render Dashboard:

The Connect menu for a Render PostgreSQL database

How you connect to your database depends on your code: some frameworks expect a single connection string or URL in an environment variable, while others need multiple connection parameters in a configuration file. See Quickstarts for examples.

At a minimum, your app needs to know your database’s hostname, port, username, password, and database name (such as mydb in the official PostgreSQL tutorial).

Render databases use the default PostgreSQL port 5432. You can usually leave this port unspecified.

Internal connections

To use the internal URL, your connecting service and your database must belong to the same account and region.

Wherever possible, connect to your database using its internal URL. Internal connection details are available on your database’s Info page in the Render Dashboard:

PostgreSQL private connection details in the Render Dashboard

You can view individual details, along with the assembled internal URL (of the format postgresql://USER:PASSWORD@INTERNAL_HOST:PORT/DATABASE). Use whichever format your framework expects for database credentials.

External connections

External URL connections are slower because they traverse the public internet.

To minimize latency, use your database’s internal URL when connecting from a Render service running in the same region.

Tools and systems outside of Render can connect to your database via its external URL, available in the Render Dashboard:

PostgreSQL public connection details in the Render Dashboard

Most database clients understand the external URL, which has the format postgresql://USER:PASSWORD@EXTERNAL_HOST:PORT/DATABASE.

You can also run the provided PSQL Command directly in your terminal to start a psql session.

If you encounter an SSL error, confirm that your PostgreSQL client supports TLS version 1.2 or higher, and that it supports any of the following cipher suites:

+ Click to show
  • TLS_AES_128_GCM_SHA256
  • TLS_AES_256_GCM_SHA384
  • TLS_CHACHA20_POLY1305_SHA256
  • TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
  • TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256
  • TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384

Restricting external access

By default, your PostgreSQL instance is accessible from any IP address (if the connection uses valid credentials). You can modify this default behavior by restricting access to a set of IPs or even disabling external access entirely.

In the Render Dashboard, go to your database’s Info page and scroll down to the Access Control section:

Setting PostgreSQL access control in the Render Dashboard

You can specify IP address blocks using CIDR notation.

These rules apply only to connections that use your database’s external URL.

Your Render services in the same region as your database can always connect using your database’s internal URL.

Connection limits

Your database’s maximum number of simultaneous connections depends on its instance type’s total memory (RAM):

MemoryMax Connections
< 8GB100 connections
8 GB <= memory < 16 GB200 connections
16 GB <= memory < 32 GB400 connections
>= 32GB500 connections

If you’re approaching your connection limit, consider upgrading your instance type or implementing connection pooling.

Databases on a legacy instance type support fewer connections:

+ View legacy instance connection limits
MemoryMax Connections
<= 6GB97 connections
Between 6GB and 10GB197 connections
>= 10GB397 connections

You can move your database to a flexible plan by changing its instance type.

Storage capacity

You set your database’s initial storage during the creation flow. You can set your storage to 1 GB or any multiple of 5 GB.

Increasing storage

Databases on a legacy instance type have a fixed storage capacity.

You can move your database to a flexible plan by changing its instance type.

You can increase your database’s storage at any time. Adding storage doesn’t require any downtime, unless you also change your instance type.

  1. From your database’s Info page in the Render Dashboard, scroll down to the PostgreSQL Instance section and click Update:

    Update PostgreSQL storage in the Render Dashboard

  2. Scroll down to the Storage field and provide a new value.

    • You can increase your storage to any multiple of 5 GB.
    • You can’t decrease your storage.
  3. Click Save Changes.

That’s it! The additional storage becomes available within a minute or two.

After you increase a database’s storage, you can’t increase it again for 12 hours.

Running out of storage

If your database exceeds its storage limit, it becomes unhealthy. Render automatically suspends the database to prevent data loss or other unexpected behavior.

To restore your database:

  1. In the Render Dashboard, scroll to the bottom of your database’s Info page and click Resume Database.

  2. Wait a minute or two for the database to finish resuming.

  3. Follow the steps to increase your database’s storage capacity.

    • If you wait too long after resuming, Render will suspend your database again. In this case, return to step 1.

Your database will become healthy within a few minutes.

Changing your instance type

You can change your PostgreSQL database’s instance type, which determines its available RAM and CPU. View available instance types.

Your database will be unavailable for a few minutes during the change.

Schedule your instance type change during off hours to minimize user impact.

  1. From your database’s Info page in the Render Dashboard, scroll down to the PostgreSQL Instance section and click Update:

    Update PostgreSQL instance type in the Render Dashboard

  2. Under Plan Options, select a new Instance Type.

    • If your database currently uses a legacy instance type, you won’t be able to move back to a legacy instance type after changing.
  3. Click Save Changes.

That’s it! Your new instance will be available within a few minutes.

Adding multiple databases to a single instance

You can create additional databases in your Render PostgreSQL instance with the following steps:

  1. In your terminal, open a psql session to your instance using the PSQL Command provided in the Render Dashboard:

    PostgreSQL public connection details in the Render Dashboard

  2. Run CREATE DATABASE <name>, providing the name for your new database.

You’re all set! Use your instance’s same internal and external URLs to connect, except substitute your new database’s name as the final component:

postgresql://USER:PASSWORD@INTERNAL_HOST:PORT/DATABASE

Encryption

Render encrypts PostgreSQL databases at rest using AES-256 data encryption. This encryption applies to both primary and replica instances, along with all automated backups. External connections to your database are encrypted in transit using Render-managed TLS certificates.

Metrics and logs

Dashboard

You can view metrics for your database from its Metrics page in the Render Dashboard:

PostgreSQL metrics in the Render Dashboard

This page provides interactive graphs for:

  • Memory
  • CPU
  • Storage
  • Active connections
  • Replication lag (if your database has a read replica)

Datadog

The Datadog integration provides additional metrics related to your PostgreSQL instance’s host and disk. You can also use the Datadog UI to create dashboards and alerts for your database.

For details, see the Datadog integration docs.

Viewing slow query logs

Queries that take longer than 2 seconds are logged with a line that starts with duration: followed by the SQL statement. Here’s an example:

PostgreSQL slow query log

Deleting your database

Render does not retain backups or snapshots of a deleted database instance!

Make sure to download any necessary backups before deleting your database.

You can delete a database instance in the Render Dashboard. Scroll down to the bottom of your database’s Info page and click Delete Database.

Additional topics

See articles on the following: