DEV Community

Cover image for I tried to locally-host supabase and followed the production recommendations
Grover Sean Reyes
Grover Sean Reyes

Posted on


I tried to locally-host supabase and followed the production recommendations

This is more like my experiences in setting up supabase and some docker configuration stuff... I'm just basically exploring some stuff.

Supabase local-hosting basically uses docker to do
while I also use docker for local development, specifically the devilbox instance. (which already has pgsql running)

Anyways, Supabase recommend decoupling the pg-database

It is recommended that you decouple your database from the middleware so that you can upgrade the middleware without any downtime. The "middleware" is everything except Postgres, and it should work with any Postgres provider (such as AWS RDS), or your own Postgres cluster.

So I tried it,

First thing I had to do was add this to my .env file

## DB Connection to use Devilbox pgsql
Enter fullscreen mode Exit fullscreen mode

now I had to remove the entire db section on the docker-compose.yml file
and replace it with a network config

    external: true
Enter fullscreen mode Exit fullscreen mode

this network configuration should allow supabase to connect to my devilbox docker bridge network

With this added I had to add a networks config for every container that needs to connect to devilbox-pgsql

    - devilbox_app_net
    - devilbox_app_net
    - devilbox_app_net
    - devilbox_app_net
    - devilbox_app_net
Enter fullscreen mode Exit fullscreen mode

Now I had to change all connection-url string that is used in the docker-compose.yml file

from postgres://postgres:${POSTGRES_PASSWORD}@db:5432/postgres

I also had to change realtime environments to use POSTGRES_* environment values

with all those stuff changed...

I then need to manually install the pgsql extensions needed for supabase to run...

there was no problem installing uuid-ossp and pgcrypto because they are already in devilbox postgres container.
the problem is pgjwt because it's not... I had to manually copy the extension files from host machine to the container and make sure it's in the right directory which is

extension files can be found in this repository and the important files that I copied are the following:

  1. pgjwt--0.1.0--0.1.1.sql
  2. pgjwt--0.1.1--0.2.0.sql
  3. pgjwt--0.1.1.sql
  4. pgjwt.control

After copying those files I was finally able to install the last extension (pgjwt)

After making sure that all 3 extensions are properly installed in the devilbox postgres instance,

I had to configure another thing again...

the devilbox postgres should be configured to have a wal_level of logical because if not supabase_realtime will scream at you. so I fixed that by putting this on my devilbox docker-compose.yml file, under the pgsql container configurations.

command: [ "postgres", "-c", "wal_level=logical" ]

You might think I'm done!... but I'm not... I'm still stuck!

I'm gettings this error from supabase_realtime

could not access file "wal2json": No such file or directory

this means that I had to install a wal2json plugin for postgres... installing a plugin on a docker container instance that does not have a make command is really hard, and up to this point, I got tired and just gave up...

I know I'm almost there, but the fact the it took this much configuration to just change a database instance literally took me a whole night to research and find solutions.

It's already 6:00 AM! and it's Christmas Morning, I need to sleep!

PS. I started tinkering around 10:00 PM, also this is my first Dev post

Top comments (0)

Timeless DEV post...

Git Concepts I Wish I Knew Years Ago

The most used technology by developers is not Javascript.

It's not Python or HTML.

It hardly even gets mentioned in interviews or listed as a pre-requisite for jobs.

I'm talking about Git and version control of course.

One does not simply learn git