·5 MIN READ

Keeping a Supabase Database Active Automatically with GitHub Actions

How to prevent free-tier Supabase PostgreSQL databases from pausing during low-traffic periods using a scheduled GitHub Actions heartbeat workflow.

#supabase#github-actions#devops#postgresql

Why Free-Tier Supabase Projects Pause

When running mobile or web projects like MyBBM on Supabase's free tier for regional users or staging environments, Supabase automatically pauses PostgreSQL instances after 7 days of inactivity to conserve compute resources.

For an Android application using an offline-first architecture, a paused cloud database means the local Room database continues working fine on the user's phone, but background delta synchronization for updated regional fuel prices silently fails until the database is manually restored from the dashboard.

Designing a Lightweight Heartbeat Query

Instead of running an external VPS cron server, we can use a scheduled GitHub Actions workflow that executes a lightweight read query against a dedicated health table every 72 hours.

Step 1: Create a Minimal Read-Only Table Policy

In Supabase SQL Editor, create a tiny system_heartbeat table with Row Level Security (RLS) enabled and a read-only policy for the anon key:

LANG // SQL
create table if not exists public.system_heartbeat (
  id int primary key default 1,
  service_name text not null default 'mybbm-fuel-sync',
  last_checked_at timestamptz not null default now()
);

insert into public.system_heartbeat (id, service_name)
values (1, 'mybbm-fuel-sync')
on conflict (id) do nothing;

alter table public.system_heartbeat enable row level security;

create policy "Allow public read heartbeat"
  on public.system_heartbeat
  for select
  to anon
  using (true);

Step 2: Configure the Scheduled GitHub Actions Workflow

Add .github/workflows/supabase-keep-alive.yml to your repository and store SUPABASE_URL and SUPABASE_ANON_KEY in your GitHub Repository Secrets:

LANG // YAML
name: Supabase Database Heartbeat

on:
  schedule:
    # Runs at 01:00 UTC every Monday and Thursday (09:00 WITA)
    - cron: "0 1 * * 1,4"
  workflow_dispatch:

jobs:
  ping-supabase:
    runs-on: ubuntu-latest
    timeout-minutes: 2
    steps:
      - name: Query Supabase REST Endpoint
        env:
          SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
          SUPABASE_ANON_KEY: ${{ secrets.SUPABASE_ANON_KEY }}
        run: |
          HTTP_STATUS=$(curl -s -o response.json -w "%{http_code}" \
            -H "apikey: ${SUPABASE_ANON_KEY}" \
            -H "Authorization: Bearer ${SUPABASE_ANON_KEY}" \
            "${SUPABASE_URL}/rest/v1/system_heartbeat?select=id,service_name&limit=1")

          echo "Supabase responded with HTTP ${HTTP_STATUS}"
          cat response.json

          if [ "$HTTP_STATUS" -ne 200 ]; then
            echo "Heartbeat check failed!"
            exit 1
          fi

Operational Reliability Tips

  1. 01.Always Include `workflow_dispatch`: Allows manual one-click verification from the GitHub Actions tab right after setting repository secrets.
  2. 02.Fail Loudly on Non-200 Status: Capturing %{http_code} ensures GitHub sends you an email notification immediately if a database migration accidentally breaks the REST endpoint.
  3. 03.Respect Fair-Use Limits: Running twice a week (1,4) is more than enough to prevent the 7-day inactivity pause while consuming negligible CI minutes.