Connection and Setup
supabase init
Initializes a new Supabase project in the current directory
supabase start
Starts the local Supabase development environment
supabase login
Log into your Supabase account
supabase link --project-ref
Link to an existing Supabase project
supabase db connect
Connect to the PostgreSQL database with psql
Database Management
supabase db pull
Pull the database schema from remote to the local migrations folder
supabase db push
Push local migrations to the remote database
supabase db diff
Generate a migration by diffing the local database with the remote database
supabase db reset
Reset the local database
supabase migration new
Create a new migration file
SQL Editor Commands
SELECT * FROM ;
Query all data from a specific table
INSERT INTO (column1, column2) VALUES (value1, value2);
Insert new data into a table
UPDATE SET column1 = value1 WHERE condition;
Update existing data in a table
DELETE FROM WHERE condition;
Delete data from a table
CREATE TABLE (column1 datatype, column2 datatype);
Create a new table
Row Level Security
ALTER TABLE ENABLE ROW LEVEL SECURITY;
Enable RLS for a table
CREATE POLICY "policy_name" ON FOR SELECT USING (auth.uid() = user_id);
Create a policy for SELECT operations
CREATE POLICY "policy_name" ON FOR INSERT WITH CHECK (auth.uid() = user_id);
Create a policy for INSERT operations
Functions and Triggers
CREATE FUNCTION () RETURNS trigger AS $$
Create a PostgreSQL function for triggers
CREATE TRIGGER AFTER INSERT ON FOR EACH ROW EXECUTE FUNCTION ();
Create a trigger
DROP FUNCTION IF EXISTS CASCADE;
Remove a function and dependent objects
Monitoring and Debugging
SELECT * FROM pg_stat_activity;
View active database connections and queries
EXPLAIN ANALYZE SELECT * FROM ;
Analyze query execution plan
SELECT pg_size_pretty(pg_database_size(''));
Check database size
SELECT pg_size_pretty(pg_total_relation_size(''));
Check table size including indexes