> ## Documentation Index
> Fetch the complete documentation index at: https://docs.replit.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Troubleshoot databases

> Safely investigate database connection failures, paused endpoints, missing production data, and recovery options without deleting or overwriting your data.

## Identify the affected database

In the **Database** pane, check whether the problem affects development or
production. Compare this with the environment running the failing request.
See [Development and production databases](https://docs.replit.com/features/data-and-storage/development-and-production.md).

Check [Replit Status](https://status.replit.com) for a matching incident.
Do not infer an outage solely from a connection error.

## “The endpoint has been disabled”

1. Check for an outstanding billing issue or usage restriction.
2. Open the **Database** pane and select the affected environment.
3. If **Unpause database** is available, select it, then retry the connection.
4. If the control is missing, check whether a manually configured `DATABASE_URL`
   points to a different database than the one shown in the pane.

Compare connection settings privately. Do not print or share the full connection
string. Do not remove an intentional external-database configuration.

If unpause fails, or the control is still missing, contact Support with the
environment, error, and steps attempted. Repeated restarts are not a substitute
for investigating a paused database.

## Preview connects, but the published app does not

Check the published app's production secrets and database configuration,
especially after a restore or migration. Workspace secrets alone do not verify
the production connection.

In **Publishing**, review **Adjust settings** and the production secrets.
If your app uses both `DATABASE_URL` and individual PostgreSQL variables,
ensure they refer to the same intended database. Save and publish the intended
configuration, then verify a read before testing writes.

Never copy production credentials into frontend code or a public repository.

## Tables or records are missing

First verify which database the app is reading. An empty development database
or a different connection target can look like data loss.

Check whether a recent migration changed table names or schema. Publishing app
code does not establish that development records were copied to production.
Do not run a reset, drop tables, or copy development data over production as a
diagnostic step.

## Unsupported database objects

Replit uses drizzle-kit, the migration tool for Drizzle ORM, to manage your
databases at two points:

* **In development**, Agent updates your Drizzle schema file and runs
  drizzle-kit to apply it to your development database.
* **When you publish**, Replit compares your development database with your
  production database and generates the SQL needed to bring production up to
  date. It compares the databases themselves, not your schema file.

Drizzle-kit only works with what a Drizzle schema can describe: tables,
columns, indexes, constraints, enums, sequences, views, and row-level security
policies. Row-level security has
[some limits when you publish](#limited-support-row-level-security).

### Not supported

These objects aren't part of a Drizzle schema, so drizzle-kit can't compare or
create them in development, and publishing doesn't copy them to production:

* **Domains**, custom types created with `CREATE DOMAIN`.
* **Functions, procedures, and triggers.**
* **Grants**, table permissions given with `GRANT`.

### Limited support: roles

Drizzle can declare roles, but support for them is limited. Therefore publishing doesn't
create, change, or remove roles currently.

### Limited support: row-level security

Publishing copies row-level security policies to production, with these
limits:

* **`FORCE ROW LEVEL SECURITY` isn't copied.** If a table is forced in
  development, production only enables row-level security on it. The table's
  owner, often the role your app connects as, then isn't restricted by the
  table's policies in production.
* **Roles and functions that a policy uses aren't created.** They must already
  exist in production, or publishing stops with an error such as
  `role "app_user" does not exist` or
  `function my_function(text) does not exist`.
* **The first policy turns on row-level security.** Adding the first policy to
  a table turns on row-level security for that table in production, even if
  it's off in development.
* **Policy conditions aren't always copied.** Before you select **Approve and
  publish**, check that each policy in the generated migration includes its
  `USING` and `WITH CHECK` conditions.

### Objects created with SQL

You can create any of the unsupported objects above manually via the [SQL console](https://docs.replit.com/features/data-and-storage/work-with-your-data.md#run-sql-commands) or Agent can also run SQL directly on your development database. They will work in development and Preview, but any unsupported objects will not be copied to production on publish.

### What happens when an object isn't supported

If a table, view, default, or policy depends on one of these objects,
publishing stops at the database migration with an error such as:

* `function my_function(text) does not exist`
* `type "my_domain" does not exist`
* `role "app_user" does not exist`

Replit rolls back the failed migration, so your production database isn't
changed.

Triggers and grants usually don't cause an error. Publishing succeeds, but your
published app may behave differently from Preview. For example, a trigger that
updates a timestamp doesn't run in production.

To fix either case, [find what's missing](#find-whats-missing-in-production)
and [apply it to production](#apply-missing-objects-to-production), then
publish again.

## Find what's missing in production

Agent can run this comparison for you, because it has read-only access to
your production database. See the prompt in
[Apply missing objects to production](#apply-missing-objects-to-production).
To check it yourself, run the same read-only queries on both databases from
the **SQL console**, then compare the results:

```sql theme={null}
-- Functions you created (excludes functions installed by extensions)
SELECT p.proname FROM pg_proc p
WHERE p.pronamespace = 'public'::regnamespace
  AND NOT EXISTS (
    SELECT 1 FROM pg_depend d WHERE d.objid = p.oid AND d.deptype = 'e'
  )
ORDER BY 1;

-- Triggers
SELECT DISTINCT event_object_table, trigger_name
FROM information_schema.triggers
ORDER BY 1, 2;

-- Domains
SELECT typname FROM pg_type
WHERE typtype = 'd' AND typnamespace = 'public'::regnamespace
ORDER BY 1;

-- Roles
SELECT rolname FROM pg_roles
WHERE rolname NOT LIKE 'pg\_%'
ORDER BY 1;

-- Grants to roles other than the one you're connected as
SELECT table_name, grantee, privilege_type
FROM information_schema.role_table_grants
WHERE table_schema = 'public' AND grantee <> current_user
ORDER BY 1, 2, 3;
```

Anything that appears only in development needs to be applied to production.
Some roles are created by Replit and differ between the two databases; you
only need the roles your app's policies or grants use.

## Apply missing objects to production

> [!WARNING]
>
> **Advanced:** these steps run SQL directly on your live production database
> to add objects Publishing doesn't carry over, like functions, triggers and
> roles. Running SQL manually is an unsupported flow that we can only help with
> in a limited way, so we recommend it only if you're comfortable working with
> SQL.
>
> Review your options in
> [Data recovery](https://docs.replit.com/features/data-and-storage/data-recovery.md) first, and apply
> changes when your app has little traffic.

1. Ask Agent to compare your databases and write a script for anything
   missing. Paste this prompt into Agent in your project:

   First, run a read-only query on my Replit-managed production database to
   confirm you can reach it. If you can't, stop and tell me why. Then compare
   my development and production databases and find any functions,
   triggers, domains, roles, or grants that exist only in development. Write
   one SQL script that creates only the missing objects. Put roles and
   domains first, then functions, then triggers and grants. Make every
   statement safe to run more than once. Save the script in my project as
   db/production-objects.sql. Don't run it, and don't try to change the
   production database.

   Agent can read your production database but can't change it, so you run
   the script yourself in the next steps.
2. In the **Database** tool, select the production database, open **My Data**,
   and turn on **Enable Editing**.
3. Open the **[SQL console](https://docs.replit.com/features/data-and-storage/work-with-your-data.md#run-sql-commands)** and run the script.
4. Turn off **Enable Editing**, then publish again.

Publishing doesn't remove these objects, so they stay in place for future
publishes. Keep the script in your project and run it again whenever you add or
change one of these objects in development.

## Data was deleted or overwritten

> [!WARNING]
>
> Stop avoidable writes to the affected data while evaluating recovery. A restore
> can replace newer data. Preserve the current state and understand the scope
> before confirming a recovery action.

Record the affected environment, approximate last known good time and timezone,
and what changed. Check the recovery options and available history shown for
that database. Retention and recovery methods depend on the database and
configuration; do not assume an older timestamp is recoverable.

Use the database-specific instructions in
[Data recovery](https://docs.replit.com/features/data-and-storage/data-recovery.md).
Do not assume that rolling back app code also restores production data.

Contact Support if you cannot identify a safe recovery path. Recovery is not
guaranteed, and increasing retention cannot recreate history that was not kept.

## Credentials may have been exposed

Remove exposed values from shared material. For a supported production database,
[regenerate its credentials](https://docs.replit.com/features/data-and-storage/connection-details.md#regenerate-production-database-credentials)
in the **Database** tool. Review the eligibility requirements and interruption warning first.
Update external clients with the new connection string. If the action isn't
available, contact Support. Do not delete the database to rotate credentials.

## Details for Support

Include the project URL, environment, sanitized error, time and timezone,
recent migrations or restores, and checks already completed. Do not include
database credentials, full connection strings, or customer records.
See the [support checklist](https://docs.replit.com/help/troubleshooting/overview.md#when-to-contact-support).
