Logo

dev-resources.site

for different kinds of informations.

How to Transfer PostgreSQL Database from Local to Supabase on macOS

Published at
12/31/2024
Categories
postgres
supabase
macos
database
Author
7twilight
Categories
4 categories in total
postgres
open
supabase
open
macos
open
database
open
Author
9 person written this
7twilight
open
How to Transfer PostgreSQL Database from Local to Supabase on macOS

If you’ve been working with a PostgreSQL database locally and now want to move it to Supabase for production or sharing, this guide is for you. I’ll walk you through the process using terminal commands, focusing specifically on macOS users.


Why Supabase?

Supabase is a powerful, open-source alternative to Firebase. It provides a fully managed PostgreSQL database, making it an excellent choice for hosting your database in the cloud.


Prerequisites

Before you start, ensure you have:

  1. PostgreSQL installed locally (including pg_dump and psql).
  2. A Supabase account with a project created.
  3. Basic familiarity with the terminal.

Step 1: Install PostgreSQL on macOS (If Needed)

If you don’t already have PostgreSQL installed, follow these steps:

brew install postgresql
Enter fullscreen mode Exit fullscreen mode

Check if the required tools are installed:

pg_dump --version
psql --version
Enter fullscreen mode Exit fullscreen mode

Step 2: Export Your Local Database

Use pg_dump to create a backup file of your local database:

pg_dump -U <local_username> -h localhost -d <local_database_name> -F c -b -v -f backup.dump
Enter fullscreen mode Exit fullscreen mode
  • Replace <local_username> with your PostgreSQL username (usually postgres).
  • Replace <local_database_name> with the name of your database.
  • backup.dump is the file name where your database dump will be stored.

For example:

pg_dump -U postgres -h localhost -d my_local_db -F c -b -v -f my_local_db_backup.dump
Enter fullscreen mode Exit fullscreen mode

Step 3: Get Your Supabase Connection Details

  1. Log in to Supabase and navigate to your project.
  2. Go to SettingsDatabase.
  3. Copy your PostgreSQL connection string, which will look like this:
postgresql://<username>:<password>@<host>:5432/<database>
Enter fullscreen mode Exit fullscreen mode

Step 4: Import the Data into Supabase

Once you have your database dump, use pg_restore to load it into Supabase:

pg_restore -U <supabase_username> -h <supabase_host> -d <supabase_database> -p 5432 -v backup.dump

Enter fullscreen mode Exit fullscreen mode

Replace <supabase_username>, <supabase_host>, and <supabase_database> with the details from your Supabase connection string.


Conclusion

Congratulations! 🎉 You’ve successfully migrated your PostgreSQL database from local to Supabase using terminal commands on macOS. Supabase makes it easy to manage your database in the cloud while keeping full control.

Have questions or tips to share? Drop a comment below!

supabase Article's
30 articles in total
Favicon
Building Production-Grade Web Applications with Supabase – Part 1
Favicon
Tracing and Metrics in supabase/storage
Favicon
Understanding Storage backends in supabase/storage
Favicon
Auth in Supabase storage
Favicon
Overview of supabase storage repository
Favicon
Harnessing the Power of Self-Hosted Supabase on Coolify: A Complete Guide to Server Setup and OAuth Providers Integration
Favicon
checa como se hace una conexión entre nextjs y la autenticación de supabase
Favicon
Deploying an Existing Express API + Prisma + Supabase Project to Vercel
Favicon
Custom schema specific Supabase Server Component clients in Grida Form workspace
Favicon
Custom schema specific Supabase Client Component clients in Grida Form workspace
Favicon
Introducing Supabase Client Playground: The Ultimate Tool for Streamlined Query Testing
Favicon
hCaptcha, a bot detection tool, usage in Supabase and Chatwoot
Favicon
Securing Client-Side Routes in Next.js with Supabase
Favicon
How to Transfer PostgreSQL Database from Local to Supabase on macOS
Favicon
Supabase | My Way of Designing & Managing DB
Favicon
What does Supabase use for its Authentication?
Favicon
É seguro guardar dados do usuário no localStorage?
Favicon
Supabase RLS Alternative
Favicon
Build Queue Worker using Supabase Cron, Queue and Edge Function
Favicon
Supabase Just Got More Powerful: Queue, Cron, and Background Tasks in Edge Functions
Favicon
Comparison of the middleware implementation between Supabase Auth documentation and the nextjs-stripe-supabase.
Favicon
How Supabase implemented micro-frontends using Multi Zones in Next.js
Favicon
Unlocking User Data: Building a Secure Supabase Edge Function
Favicon
Usecase: TumbleLog
Favicon
Supabase Edge Functions
Favicon
Setup Astro With Supabase and Prisma
Favicon
We launched SupaCharts! Visualize Beautiful Charts from your Supabase Data.
Favicon
A Free Minimalistic SaaS Starter Kit for Fast MVP Building
Favicon
supabase注册并创建项目和添加数据表
Favicon
Integrating GitHub Authentication with NextAuth.js: A Step-by-Step Guide

Featured ones: