Supabase

How to implement data replication between Supabase and another PostgreSQL database?

Dive into this all-encompassing guide to seamlessly replicate data between Supabase and any PostgreSQL database. Make the entire process a breeze today!

Developer profile skeleton
a developer thinking

Overview

Connecting Supabase with another PostgreSQL database for data replication has several key steps. It begins with setting up the PostgreSQL database, configuring Supabase, and linking the two. Along the way, there's an explanation of data replication—its role in boosting data availability and security. Supabase, positioned as an open-source Firebase alternative, relies on PostgreSQL at its core. The article will go into detail on how to synchronize data between these platforms, highlighting possible hurdles and how to overcome them. This sets the stage for a detailed, step-by-step guide.

Get a Free No-Code Consultation
Meet with Will, CEO at Bootstrapped to get a Free No-Code Consultation
Book a Call
Will Hawkins
CEO at Bootstrapped

How to implement data replication between Supabase and another PostgreSQL database?

Step 1: Set Up Remote Server Configuration In Supabase

Alright, let's get started with connecting to a remote PostgreSQL database through Supabase. First things first, we need to define the remote server parameters. Here's what you'll need:

  • PostgreSQL host: This is the IP address or hostname of your remote server.
  • PostgreSQL port: The port where your PostgreSQL service is running.
  • PostgreSQL user: Usually, this is 'postgres'.
  • PostgreSQL password: The password for your PostgreSQL user.
  • PostgreSQL database: The name of your database.

Head over to the Dashboard, then navigate to ‘Settings’ -> ‘Database’ -> ‘Connections’.

Step 2: Virtual Private Network Connection

Next up, we need to set up a VPN for secure communication between Supabase and your remote PostgreSQL server. You can either go for a full network-level VPN or a client-server VPN on the PostgreSQL server itself. This will create a secure tunnel for your data to travel through.

Step 3: Set Up Logical Replication On Supabase

Now, let's talk replication. Physical replication copies the entire database cluster, which can be a bit heavy for large databases. Instead, we can use logical replication to selectively copy data changes to specific tables.

To set up logical replication in Supabase, follow these steps:

  • Open the dashboard and go to the SQL page.
  • Run this SQL command to set up logical replication:
    ALTER SYSTEM SET wal_level = logical;
    
  • Restart the PostgreSQL service to apply the changes.

Step 4: Create a Publication On the Remote PostgreSQL Server

A Publication in PostgreSQL defines which tables should be replicated. Run this SQL command on your remote PostgreSQL server to create a Publication:

CREATE PUBLICATION my_publication FOR TABLE my_table;

Replace 'my_publication' with your chosen name for the Publication, and ‘my_table’ with the name of the table you want to replicate.

Step 5: Create a Subscription On Supabase

A Subscription links the Supabase database to the remote Publication. Run this SQL command in Supabase to create a Subscription:

CREATE SUBSCRIPTION my_subscription
CONNECTION 'dbname=my_database host=my_host port=my_port user=my_user password=my_password'
PUBLICATION my_publication;

Replace 'my_subscription' with your chosen name for the Subscription, and 'my_database', 'my_host', 'my_port', 'my_user', and 'my_password' with your remote PostgreSQL server details. Also, replace 'my_publication' with the name of the Publication you created earlier.

Supabase will now start replicating data from the remote PostgreSQL database. You can monitor the replication process in the PostgreSQL statistical views or through system logs.

Note on Potential Pitfalls

  • Make sure you have enough disk space before starting the replication, especially with large datasets.
  • Ensure the entire replication process is encrypted for data privacy and security.
  • Using a private VPN connection between Supabase and the remote PostgreSQL database is highly recommended.
  • If you run into performance issues during replication, consider increasing network bandwidth, hardware configuration, or the PostgreSQL shared_buffers parameter.

Following these steps, you can set up data replication between Supabase and another PostgreSQL database. This setup is particularly useful for teams working on data science and analytics applications that need reliable, secure, and real-time access to production data.

Explore more Supabase tutorials

Complete Guide to Supabase: Tutorials, Tips, and Best Practices

Explore our Supabase tutorials directory - an essential resource for learning how to create, deploy and manage robust server-side applications with ease and efficiency.

Why are companies choosing Bootstrapped?

40-60%

Faster with no-code

Nocode tools allow us to develop and deploy your new application 40-60% faster than regular app development methods.

90 days

From idea to MVP

Save time, money, and energy with an optimized hiring process. Access a pool of experts who are sourced, vetted, and matched to meet your precise requirements.

1 283 apps

built by our developers

With the Bootstrapped platform, managing projects and developers has never been easier.

hero graphic

Our capabilities

Bootstrapped offers a comprehensive suite of capabilities tailored for startups. Our expertise spans web and mobile app development, utilizing the latest technologies to ensure high performance and scalability. The team excels in creating intuitive user interfaces and seamless user experiences. We employ agile methodologies for flexible and efficient project management, ensuring timely delivery and adaptability to changing requirements. Additionally, Bootstrapped provides continuous support and maintenance, helping startups grow and evolve their digital products. Our services are designed to be affordable and high-quality, making them an ideal partner for new ventures.

Engineered for you

1

Fast Development: Bootstrapped specializes in helping startup founders build web and mobile apps quickly, ensuring a fast go-to-market strategy.

2

Tailored Solutions: The company offers customized app development, adapting to specific business needs and goals, which ensures your app stands out in the competitive market.

3

Expert Team: With a team of experienced developers and designers, Bootstrapped ensures high-quality, reliable, and scalable app solutions.

4

Affordable Pricing: Ideal for startups, Bootstrapped offers cost-effective development services without compromising on quality.

5

Supportive Partnership: Beyond development, Bootstrapped provides ongoing support and consultation, fostering long-term success for your startup.

6

Agile Methodology: Utilizing agile development practices, Bootstrapped ensures flexibility, iterative progress, and swift adaptation to changes, enhancing project success.

Yes, if you can dream it, we can build it.