Database is a Replit workspace tool that lets you set up a database for your apps to store and query your data.
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.
The Replit Database tool provides the following features:
You can access the Database tool directly in your Replit App workspace. The following sections guide you through setting up and managing your database.
How to access the Database tool
From the left Tool dock:
From the Search bar:
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.
The SQL runner is a workspace tool that lets you run SQL commands on your database and view the results.
How to access SQL runner
From the Database tool:
To run a query, enter the SQL statement in the text area and select the
adjacent run button
as shown below:
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:
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.
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.
How to access your database connection credentials
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 connectionPGHOST
: Database hostnamePGUSER
: Database usernamePGPASSWORD
: Database passwordTo learn how to use these credentials in your code, see Connect your app to a SQL database.
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:
How to access the Restore tool and History Retention setting
To restore your database to a specific time, follow the steps below:
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.
How to remove a database
From the Database tool:
Replit optimizes your cost savings for database usage by using Neon, a serverless database provider.
Neon’s serverless capabilities include the following:
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.
How to access database usage
To view your database compute time and storage usage for the current billing period, follow the steps below:
From the Database tool:
To view for every Replit App on your account from the Account resource usage section, follow the steps below:
To learn how Replit charges for database usage, see Deployments and Database Billing.
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:
To learn how to connect to a Replit SQL database from code, see Connect your app to a SQL database.