Which Database Should an AI-Built App Use?
The AI will happily pick a database for you — sometimes a file on disk that disappears on the next deploy. What the choice actually is, why Postgres is the right default for almost every app, and the mistakes that lose data.
Ask an AI to build an app that saves things, and it will choose somewhere to save them. Sometimes that's a sensible managed database. Sometimes it's a JSON file in the project folder, an in-memory array, or the browser's local storage — all of which work perfectly in the demo and lose everything in production.
The database is the one part of an AI-built app you can't treat as a detail. Code can be regenerated. Your users' data can't. Here's how to choose.
The short answer
Use PostgreSQL, managed by someone else, from day one.
That's the right answer for the overwhelming majority of apps: SaaS products, marketplaces, internal tools, client projects, anything with users and accounts. The rest of this article explains why, and covers the few exceptions.
First, make sure you have a database at all
Before choosing which database, check that your app isn't storing data somewhere that isn't one. Ask the AI directly, or search the code, for these:
| What it's doing | Why it fails |
|---|---|
| Arrays or objects in memory | Gone every time the server restarts |
| JSON or text files in the project | Wiped on redeploy on most hosts; breaks with two server instances |
Browser localStorage |
Lives on one user's device only; other users and devices never see it |
| SQLite file on an ephemeral disk | Works locally, disappears on hosts that rebuild the container |
If any of these is holding data you care about, fix that before launch. It's the most common way AI-built apps lose everything — usually the first time someone ships a fix.
Why Postgres is the default
It's what the AI knows best. PostgreSQL is enormously well represented in the code models learned from. Ask for a schema, a migration, or a query, and you'll get correct, idiomatic Postgres far more reliably than for less common databases.
It handles almost everything. Relational data, JSON documents (via jsonb), full-text search, geospatial data, and vector search for AI features (via extensions like pgvector). You rarely need a second database.
It enforces correctness. Foreign keys, unique constraints, and transactions stop bad data getting in — valuable when the code writing to it was generated rather than reviewed line by line.
It's portable. Every major host offers managed Postgres, and moving between them is a pg_dump away. No proprietary format to be stuck in.
When something else makes sense
- SQLite is excellent for small apps with one server and a persistent disk, and for local tools. Just make sure the disk genuinely persists, and plan for backups.
- Redis is a cache, a queue, or a session store alongside your main database — not a replacement for it.
- MongoDB suits genuinely document-shaped data with no relationships. Most app data is more relational than it first looks: users have orders, orders have items. Start with Postgres unless you have a specific reason.
- Supabase and Firebase are backend platforms, not just databases. Supabase is Postgres underneath, with auth and an API on top — a solid choice, as long as you configure its security (below). Firebase uses a document database and suits some mobile apps well, with more lock-in.
Managed, not self-installed
"Managed" means someone else runs the database server: installs it, patches it, backs it up, and restores it when something goes wrong. For an AI-built app it's almost always the right call, because the alternative is you becoming a database administrator.
What to check a managed database actually includes:
- Automated backups — how often, how long they're kept, and whether you can restore to a point in time.
- A restore you've tested. Backups you've never restored are a hope, not a plan.
- Connection over TLS, with credentials you can rotate.
- A connection string delivered as an environment variable (
DATABASE_URL), not pasted into your code.
Four mistakes that lose data
1. The app and the database are the same thing
If your data lives inside the app's container or folder, each redeploy replaces it. The database has to be a separate service with its own storage.
2. Changing the schema by hand
When you add a feature, the table structure changes. If those changes happen by someone clicking around a database dashboard, your environments drift apart and nobody knows what production looks like. Ask the AI to use migrations — versioned files that describe each change, committed with the code, applied the same way everywhere.
3. Developing against production
If your app, your AI agent, and your local testing all point at the same database, one bad command or test run affects real users. Keep a separate development database. We've written about how an AI agent deleted a company's production database in How to Stop an AI Agent From Deleting Your Production Database.
4. Open access
Backend platforms like Supabase put a key in your frontend that anyone can read. Without row-level security rules, that key can read every row in every table. In 2025 this exact misconfiguration exposed user data across a large number of AI-built apps. Enable RLS on every table and test it as a stranger. More in A Security Checklist for Vibe-Coded Apps.
A setup that will hold up
- A managed PostgreSQL database, separate from the app.
- The connection string in a
DATABASE_URLenvironment variable. - Migrations in the repository for every schema change.
- A separate development database for building and testing.
- Daily backups, and one restore you've actually tested.
- Access rules — RLS, or a backend that checks permissions — tested with a second user.
That's an afternoon of setup, and it's the difference between an app that can survive its first real users and one that can't.
EasySpawn provisions a managed PostgreSQL database for every workspace automatically — connection details delivered as DATABASE_URL, daily backups included — with MySQL, MongoDB, and Redis available too. See how it works for AI-built apps or join the waitlist.
Related: How to Back Up a Postgres Database — and Prove the Backup Works · You Built an App With AI. Now What?
Keep reading
How to Keep API Keys Out of an AI-Built App
AI-generated code hardcodes API keys all the time — and 'put it in an environment variable' isn't enough if the variable ends up in the browser. Which keys are safe to expose, which never are, and how to fix a key that's already leaked.
How to Hand Off an AI-Built App to a Client
Freelancers and agencies are shipping client apps faster than ever with AI. The handoff is where projects go wrong: accounts in the wrong name, no documentation, and an open-ended support expectation. A checklist for handing over cleanly — and keeping the relationship profitable.