Lovable + Elestio: Use Managed Postgres in Your AI-Built App
Lovable is one of the fastest ways to go from "idea" to "deployed app" without writing the boilerplate. The catch: its bundled Supabase free tier caps you at 500 MB of storage on a shared CPU. The moment your AI-built app starts taking real users, you want a real database. One you own, one that gets backed up nightly, one that doesn't quietly throttle when you cross an invisible row count.
This guide walks through plugging an Elestio-managed Postgres into a Lovable project as the backing store. You keep Lovable for what it's good at (UI, prompts, iteration speed), and you put your data on infrastructure you actually control.
The architecture in 30 seconds
Three pieces:
- Lovable generates and hosts your frontend, and talks to your chosen backend via prompts.
- Supabase Edge Function sits between Lovable and your database. Lovable calls it natively; we use it as a tiny API gateway.
- Elestio Postgres holds the data. Daily snapshots, monitoring, root SSH, no shared neighbors.
The Edge Function reads your Elestio connection string from Supabase secrets at cold start, opens a connection, and answers Lovable's queries. From the frontend's perspective, it's just another HTTPS endpoint.
Step 1: Spin up Postgres on Elestio
Go to https://elest.io/open-source/postgresql and deploy. A MEDIUM (2c / 4 GB) at $16/month is enough for most early-stage Lovable apps. The wizard handles SSL, daily backups, monitoring, and pgAdmin, so you don't.
Once the service is up, open its overview page. You'll need five values: USER, PASSWORD, HOST, PORT, and DATABASE. Elestio surfaces them in a table at the top of the page, and also as a ready-to-paste connection string. The Elestio docs walk through exactly where each one lives: docs.elest.io/books/postgresql/page/connecting-with-nodejs.
Step 2: Build your connection string
Stitch the five values into a standard Postgres URI:
postgres://USER:PASSWORD@HOST:PORT/DATABASE?sslmode=require
The sslmode=require parameter is non-negotiable. Elestio Postgres has SSL on by default and the Edge Function will refuse to connect without it.
Step 3: Start a Lovable project
Visit lovable.dev, describe the app you want, and let it generate the skeleton. When it asks, connect your Supabase project and GitHub. Lovable will spin up the standard Supabase backend; that's fine for now. We'll keep Supabase as the function host, but the actual data lives on Elestio.
Step 4: Add a Supabase Edge Function as your Elestio bridge
In the Supabase dashboard, create a new Edge Function called elestio-db. Paste in something like this:
import postgres from "https://deno.land/x/postgresjs@v3.4.4/mod.js";
const sql = postgres(Deno.env.get("ELESTIO_DATABASE_URL")!, {
ssl: "require",
});
Deno.serve(async (req) => {
const { table, op, payload, where } = await req.json();
if (!/^[a-z_][a-z0-9_]*$/i.test(table)) {
return new Response("Invalid table name", { status: 400 });
}
switch (op) {
case "list":
return Response.json(
await sql`SELECT * FROM ${sql(table)} LIMIT 100`
);
case "insert":
return Response.json(
await sql`INSERT INTO ${sql(table)} ${sql(payload)} RETURNING *`
);
case "update":
return Response.json(
await sql`UPDATE ${sql(table)} SET ${sql(payload)} WHERE id = ${where?.id} RETURNING *`
);
case "delete":
return Response.json(
await sql`DELETE FROM ${sql(table)} WHERE id = ${where?.id} RETURNING id`
);
default:
return new Response("Unknown op", { status: 400 });
}
});
Store the connection string as a Supabase secret, then deploy:
supabase secrets set ELESTIO_DATABASE_URL="postgres://USER:PASSWORD@HOST:PORT/DATABASE?sslmode=require"
supabase functions deploy elestio-db
That's the whole bridge: one file, four operations, parameterized queries. The regex on the table name keeps Lovable from accidentally generating a SQL-injection vector when it improvises new tables.
Step 5: Tell Lovable to use the function
Back in your Lovable chat, send a prompt like this:
"Replace all data calls with calls to my Supabase Edge Function at/functions/v1/elestio-db. The function expects{ table, op, payload, where }and returns JSON. For any new feature that needs a table, generate theCREATE TABLEstatement so I can run it against Elestio Postgres."
Lovable will rewrite its data layer to hit your function. The first time a new feature runs, paste any CREATE TABLE it generates into Elestio's pgAdmin (linked from your service page) or run it through psql. From then on every read and write happens on your database.
Why Elestio?
A few reasons that start to matter as soon as you're past prototyping:
- Real specs at a predictable price. A MEDIUM VM gives you 2 dedicated CPUs, 4 GB RAM, and the full VM disk for $16/month flat. Lovable's bundled free tier caps you at 500 MB with a shared CPU, and the next paid step starts around $25/month with row and bandwidth ceilings that bite earlier than you'd expect.
- Standard Postgres, no vendor flavor. Anything that speaks Postgres talks to your Elestio DB. Move the same database to a different host, a different app, or your laptop without rewriting a line.
- Backups and monitoring included. Daily snapshots, point-in-time recovery, and a real metrics dashboard ship with the deployment.
- Root access. When you need to install an extension, run
pg_dump, or attach a second app to the same database, the box is yours.
Troubleshooting
SSL connection refused. Add ?sslmode=require to your connection string. For local testing only, ?sslmode=no-verify works too. Elestio Postgres rejects unencrypted connections.
"Permission denied" from Supabase secrets. Edge Functions only see secrets set via the Supabase CLI or dashboard. A local .env file is not shipped with the deploy.
Cold-start latency on the first request. Edge Functions sleep when idle. The first call after a quiet period opens a fresh Postgres connection and adds roughly 300 ms. For chatty apps, ping the function every few minutes, or move the function to a small Node or Deno service on Elestio right next to your database.
Lovable rewrites the data layer back to Supabase. Be explicit in your follow-up prompts: "Do not use the Supabase client for reads or writes, always call the elestio-db function." Pin the contract in the function's first reply so Lovable keeps it in context.
Effortless prompts, durable data
Lovable handles the iteration speed. Elestio handles the part where your data has to survive the night. The combination gives you AI-paced shipping on top of infrastructure you actually own, with a bridge that takes a single Edge Function and one secret.
Deploy your database here: https://elest.io/open-source/postgresql. Build the app here: lovable.dev. Then go ship something.
Thanks for reading ❤️ See you in the next one 👋