Prevents Supabase from pausing after 7 days of inactivity by running a lightweight database query every 6 hours.
- ✅
vercel.json- Cron job configuration (runs every 6 hours) - ✅
/api/keep-alive- Keep-alive endpoint with Vercel authentication - ✅ Automatic setup - Vercel detects
vercel.jsonand configures the cron job
The code is already committed. After you push:
- Vercel will automatically detect the new
vercel.jsonfile - A new deployment will be triggered
- The cron job will be automatically configured
No manual action needed - just push and Vercel handles the rest!
Ensure these environment variables are set in your Vercel project:
NEXT_PUBLIC_SUPABASE_URL- Your Supabase project URLSUPABASE_SECRET_KEYorSUPABASE_SERVICE_ROLE_KEY- Your Supabase secret key
To check/update:
- Go to Vercel Dashboard → Your Project → Settings → Environment Variables
- Verify the above variables are present
After pushing the code, verify the cron job is set up:
- Go to your Vercel project dashboard
- Navigate to Settings → Cron Jobs
- You should see:
- Path:
/api/keep-alive - Schedule:
0 */6 * * *(every 6 hours) - Status: Active
- Path:
Note: It may take a few minutes after deployment for the cron job to appear.
Test that the endpoint works:
# Replace with your Vercel deployment URL
curl https://your-project.vercel.app/api/keep-aliveExpected response:
{
"success": true,
"message": "Supabase keep-alive successful",
"timestamp": "2024-01-15T10:30:00.000Z",
"database": "active"
}- Go to your Vercel project dashboard
- Navigate to Deployments tab
- Click on any deployment
- Go to Functions tab
- Look for
/api/keep-alivefunction logs
You can also check the Cron Jobs section in Settings to see execution history.
The current schedule is 0 */6 * * * (every 6 hours). You can modify it in vercel.json:
| Schedule | Cron Expression | Description |
|---|---|---|
| Every 6 hours | 0 */6 * * * |
✅ Current (very safe) |
| Every 12 hours | 0 */12 * * * |
Safe |
| Every day | 0 0 * * * |
Safe |
| Every 3 days | 0 0 */3 * * |
Safe |
| Every 6 days | 0 0 */6 * * |
Minimum (matches Supabase's 7-day threshold) |
Recommendation: Keep the current schedule (every 6 hours) to ensure your Supabase instance never pauses.
- ✅ Vercel cron jobs are automatically authenticated via the
x-vercel-cronheader - ✅ The endpoint verifies this header before processing
- ✅ Optional
KEEP_ALIVE_SECRETcan be added for additional security
-
Check vercel.json is deployed:
- Ensure
vercel.jsonis in your repository root - Verify it was included in your deployment
- Ensure
-
Check Vercel Dashboard:
- Go to Settings → Cron Jobs
- Verify the cron job is listed and active
-
Check Deployment Logs:
- Look for any errors in the function execution logs
-
Check Environment Variables:
- Verify
NEXT_PUBLIC_SUPABASE_URLis set - Verify
SUPABASE_SECRET_KEYorSUPABASE_SERVICE_ROLE_KEYis set
- Verify
-
Check Supabase Status:
- Your Supabase instance might be paused (wake it up manually first)
- Verify your Supabase project is active
-
Check Function Logs:
- Go to Vercel Dashboard → Deployments → Functions
- Look for error messages in the logs
- Verify the cron job is actually running (check execution logs)
- Try reducing the interval (e.g., every 3 hours instead of 6)
- Check that your Vercel deployment is active and not paused
You can monitor the keep-alive endpoint by:
-
Vercel Dashboard:
- Settings → Cron Jobs → View execution history
- Deployments → Functions → View logs
-
Add Logging (optional):
- The endpoint already logs to console
- Check Vercel function logs for execution details
After pushing the code:
- Wait for deployment (usually 1-2 minutes)
- Check Cron Jobs: Vercel Dashboard → Settings → Cron Jobs
- Should see
/api/keep-alivewith schedule0 */6 * * *
- Should see
- Optional: Test endpoint manually:
curl https://your-project.vercel.app/api/keep-alive
That's it! Your Supabase instance will now stay active. 🎉
- Vercel Cron Jobs are available on all plans (including free tier)
- Cron jobs run on Vercel's infrastructure, so they're reliable
- The keep-alive query is lightweight and won't impact your Supabase usage
- You can manually trigger the endpoint anytime for testing