mirror of
https://github.com/supabase/supabase.git
synced 2026-07-07 01:34:22 +08:00
205 lines
5.8 KiB
Plaintext
205 lines
5.8 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](/docs/realtime/server/about).
|
|
- Every project is a full Postgres database, with `postgres` level access.
|
|
- Managed backups - Supabase handles all your database backups.
|
|
- Data imports - import directly from a CSV or excel spreadsheet.
|
|
|
|
## Extensions
|
|
|
|
|
|
### Enable and disable 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>
|
|
|
|
|
|
### Full list of extensions
|
|
|
|
Supabase is pre-configured with over 50 extensions. You can also install your own SQL extensions directly into the database through our SQL editor.
|
|
|
|
<ExtensionsComponent />
|
|
|
|
|
|
## 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)
|
|
|