Skip to main content

Database

Supabase is built on top of Postgres, an extremely scalable Relational Database.

Features#

Table View#

You don't have to be a database expert to start using Supabase. Our table view makes Postgres as easy to use as a spreadsheet.

Table View.

Relationships#

Dig into the relationships within your data.

Clone tables#

You can duplicate your tables, just like you would inside a spreadsheet.

The SQL Editor#

Supabase comes with a SQL Editor. You can also save your favorite queries to run later!

Additional features#

  • Supabase extends Postgres with realtime functionality using our Realtime Server.
  • Every project is a full Postgres database, with postgres level access.
  • Managed backups - Supabase handles all your database backups.backups
  • Data imports - import directly from a CSV or excel spreadsheet.

backups Database backups do NOT include objects stored via the Storage API, as the database only includes metadata about these objects. Restoring an old backup will not restore objects that have been deleted since then.

Extensions#

To expand the functionality of your Postgres database, you can use extensions. You can enable Postgres extensions with the click of a button within the Supabase dashboard.

Learn more about all the extensions provided on Supabase.

Tips#

Realtime#

Supabase provides a realtime engine on top of Postgres, so that you can listen to changes as they happen. Our realtime engine uses the built-in replication functionality of Postgres. You can manage the realtime system, simply by updating the supabase_realtime publication.

For example to enable realtime only for individual tables:

begin;   -- remove the realtime publication  drop publication if exists supabase_realtime; 
  -- re-create the publication but don't enable it for any tables  create publication supabase_realtime;  commit;
-- add a table to the publicationalter publication supabase_realtime add table products;
-- add other tables to the publicationalter publication supabase_realtime add table posts;
SECURITY WARNING
Please check Disable realtime for private tables for the current state of Realtime security.

By default only "new" values are sent, but if you want to receive the old record (previous values) whenever you update or delete a record, you can update the replica identity of your tables, setting it to full:

alter table your_table replica identity full;

Migrating between projects#

If you have an existing Supabase Project and you want to migrate it into a new (fresh) Project, you can simply follow these steps:

Before you begin#

  • Make sure Realtime is disabled. This will improve the performance of inserts on your new database.
  • Make sure you have psql installed on your computer so that you can run pg_dump.

Migrate the database#

First we want to grab the database structure only:

pg_dump \-h db.PROJECT_REF.supabase.co \-U postgres \--clean \--schema-only \> supabase_schema.sql

This command creates a file on your computer called supabase_schema.sql.

After creating a new Supabase project we can use it to restore the database structure:

psql \-h db.NEW_PROJECT_REF.supabase.co \-U postgres \< supabase_schema.sql

You may see some errors - the restore will attempt to drop any tables if they are present, and if they aren't present then an error will be displayed. These errors are informative only and nothing to worry about.

(Optionally) Migrate the data#

We can migrate everything in our database, however we don't want to migrate the data in our storage schema because the files exist outside of the database. For now, we can just get all the data inside the public and auth schemas:

pg_dump \-h db.PROJECT_REF.supabase.co \-U postgres \--data-only \-n public \-n auth \> supabase_data.sql

This command creates a file on your computer called supabase_data.sql. We can use this file to restore the data in our new database:

psql \-h db.NEW_PROJECT_REF.supabase.co \-U postgres \< supabase_data.sql

Resetting your project password#

When you create a new project in Supabase we ask for a password. You can use this password to connect directly to your Postgres database.

If you forget your password, you can reset it from the Dashboard SQL editor:

For example:

alter user postgres with password 'new_password';

Read more in Database Configuration.

Changing the timezone of your server.#

Your database is initialized with the UTC timezone. We recommend keeping it this way, as it is helpful for time calculations. If, however, you want to update the timezone, you can do so using any of the database timezones.

For example:

alter database postgres set timezone to 'America/New_York';

Read more in Database Configuration.

Next steps#