Replit Database uses a fully-managed, serverless SQL database that lets you add persistent data storage to your Replit App from the workspace. This serverless database implementation lets you pay only for what you use, making it ideal for projects of any size.

Replit Database uses PostgresSQL 15 hosted on Neon.

Features

The Replit Database tool provides the following features:

  • Instant setup: Add a production-ready SQL database with a single click
  • Database tools: Run queries, manage database schema, and visualize data with the built-in SQL tools
  • Point-in-time restore: Restore your database to a specific point in time within your specified retention period
  • Usage-based billing: Pay only for the storage and data transfer you use
  • Environment variables: Use environment variables in your Replit App to securely access the database

Usage

You can access the Database tool directly in your Replit App workspace. The following sections guide you through setting up and managing your database.

Add a database

Use one of the following methods to add a Replit database integration to your Replit App:

  • Ask Agent to add a PostgresSQL database to your Replit App, including details on what data your Replit App should store. Agent adds the integration, creates the database schema, and updates the app to communicate with the database.

  • From the Database tool, select Create a database. When using this method, you must create the tables and update your app to connect to the database.

Run database commands

The SQL runner is a workspace tool that lets you run SQL commands on your database and view the results.

To run a query, enter the SQL statement in the text area and select the adjacent sql run icon run button as shown below:

Browse and modify data visually

The Replit Database tool includes Drizzle Studio, a tool that lets you browse and modify data visually.

These visual tools help you avoid syntax errors and offer the following functionality:

  • Filter and sort data to focus on specific information
  • Export data to a files for external use
  • Insert or modify row data
  • Create and manage schema, tables, views, and enums

You can access these tools in the My Data tab in the Database tool.

The following image shows a view from the Drizzle Studio user interface:

You can connect to your database using any PostgresSQL-compatible SQL client using the connection string found in your environment variables.

View database connection credentials

When you add a database, the Database tool automatically saves your connection credentials as environment variables in your Replit App. Your app uses the credentials to securely connect to the database and run commands.

The list includes the following environment variables, which you can reference from your Replit App’s code:

  • DATABASE_URL: Database connection string which contains all details for a secure connection
  • PGHOST: Database hostname
  • PGUSER: Database username
  • PGPASSWORD: Database password

To learn how to use these credentials in your code, see Connect your app to a SQL database.

Restore tool

The Restore tool lets you revert your database to a specific point in time. To activate this tool, you must select a retention period in the History Retention option. You can then restore from any point within that period.

Common uses for the Restore tool include the following:

  • Recovering from accidental data deletion or corruption
  • Reverting to a previous state for testing or debugging
  • Reviewing historical data from a specific point in time

To restore your database to a specific time, follow the steps below:

  1. Enter the target date and time in the Timestamp field
  2. Select Restore. Select Continue to proceed in the confirmation dialog.

Remove tool

The remove action is irreversible. Make sure to back up any important data before proceeding.

If you no longer need a database for your Replit App, you can remove it and all its data.

Billing and resource usage

Replit optimizes your cost savings for database usage by using Neon, a serverless database provider.

Neon’s serverless capabilities include the following:

  • Zero infrastructure setup or maintenance
  • Automatic scaling to handle your usage needs
  • Compute time billing only when the database is active

The database enters an idle state after five minutes of inactivity, pausing compute time billing. It instantly reactivates when it receives a query.

To learn more about this serverless database technology, see the Neon Compute lifecycle documentation.

Replit provides real-time tracking of your database usage. You can view the breakdown of compute time and storage usage for the current Replit App or for each Replit App on your account.

To learn how Replit charges for database usage, see Deployments and Database Billing.

Security features

When you add a database integration using Agent, it adds an Object-Relational Mapper (ORM) that handles all database communications with built-in security.

This ORM layer, combined with Agent’s security best practice implementation, protects your app from exploits through the following features:

  • Schema validation: Verifies data conforms to expected formats
  • Data sanitization: Automatically cleans up user input to prevent SQL injection attacks