mirror of
https://github.com/supabase/supabase.git
synced 2026-07-06 04:54:23 +08:00
198 lines
5.9 KiB
Plaintext
198 lines
5.9 KiB
Plaintext
---
|
|
id: database
|
|
title: Database
|
|
description: Use Supabase to manage your data.
|
|
---
|
|
|
|
import ExtensionsComponent from '../../src/components/Extensions'
|
|
|
|
Supabase is built on top of [Postgres](/docs/postgres/server/about), 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.
|
|
|
|

|
|
|
|
|
|
### Relationships
|
|
|
|
Dig into the relationships within your data.
|
|
|
|
|
|
<video width="99%" loop="" muted="" playsInline="" controls="true">
|
|
<source src="/videos/relational-drilldown-zoom.mp4" type="video/mp4" />
|
|
</video>
|
|
|
|
|
|
### Clone tables
|
|
|
|
You can duplicate your tables, just like you would inside a spreadsheet.
|
|
|
|
<video width="99%" muted playsInline controls={true}>
|
|
<source src="/videos/duplicate-tables.mp4" type="video/mp4" muted playsInline />
|
|
</video>
|
|
|
|
|
|
### The SQL Editor
|
|
|
|
Supabase comes with a SQL Editor. You can also save your favorite queries to run later!
|
|
|
|
<video width="99%" muted playsInline controls={true}>
|
|
<source src="/videos/favorites.mp4" type="video/mp4" muted playsInline />
|
|
</video>
|
|
|
|
|
|
### Additional features
|
|
|
|
- Supabase extends Postgres with realtime functionality using our [Realtime Server](https://github.com/supabase/realtime).
|
|
- 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.
|
|
|
|
<video width="99%" muted playsInline controls={true}>
|
|
<source src="/videos/toggle-extensions.mp4" type="video/mp4" muted playsInline />
|
|
</video>
|
|
|
|
[Learn more](/docs/guides/database/extensions) 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](/docs/reference/postgres/publications) the `supabase_realtime` publication.
|
|
|
|
For example to enable realtime only for individual tables:
|
|
|
|
```sql
|
|
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 publication
|
|
alter publication supabase_realtime add table products;
|
|
|
|
-- add other tables to the publication
|
|
alter publication supabase_realtime add table posts;
|
|
```
|
|
|
|
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`:
|
|
|
|
```sql
|
|
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](/docs/guides/api#managing-realtime). This will improve the performance of inserts on your new database.
|
|
- Make sure you have [`psql`](https://www.postgresql.org/docs/13/app-psql.html) installed on your computer so that you can run `pg_dump`.
|
|
|
|
#### Migrate the database
|
|
|
|
First we want to grab the database structure only:
|
|
|
|
```sh
|
|
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:
|
|
|
|
```sh
|
|
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:
|
|
|
|
```sh
|
|
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:
|
|
|
|
```sh
|
|
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:
|
|
|
|
```sql
|
|
alter user postgres
|
|
with password 'new_password';
|
|
```
|
|
|
|
Read more in [Database Configuration](/docs/reference/postgres/database-passwords).
|
|
|
|
### 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](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones).
|
|
|
|
For example:
|
|
|
|
```sql
|
|
alter database postgres set timezone to 'America/New_York';
|
|
```
|
|
|
|
Read more in [Database Configuration](/docs/reference/postgres/changing-timezones).
|
|
|
|
## Next steps
|
|
|
|
- Read more about [Postgres](/docs/postgres/server/about)
|
|
- Sign in: [app.supabase.io](https://app.supabase.io)
|
|
|