Serverless Postgres for side projects: one database per project
Provision an isolated serverless Postgres database per project with a development branch and plain DATABASE_URL support across any host.
On this page 10 sections
- Why one database per project matters for side projects
- How serverless Postgres works on thelastapi
- Creating a project and getting your database
- Connecting with an ORM or standard client
- Running on external hosts
- What agents and keys can access
- Backups and leaving without lock-in
- Pricing and limits
- Next steps
- FAQ
thelastapi provisions a serverless Postgres database for each project, gives your app a plain DATABASE_URL, and automatically sets up an isolated development branch with production schemas and zero production rows. You get standard Postgres accessible over the internet, usable with your favorite ORM or migration tool. You can deploy on our hosting or run your database with an app hosted anywhere else.
Starting a side project often comes with database friction. You either run local Docker containers that desync from your server, share one messy shared database across multiple experiments, or manually spin up separate accounts across external database services. This guide covers how serverless Postgres per project works, how to manage environments safely, and how to connect your app.
Why one database per project matters for side projects
Side projects move fast, but mixing projects in a single database instance creates headaches:
- Schema collisions: Multiple experiments sharing one Postgres instance require custom prefixes, separate schemas, or careful namespacing to avoid clashes.
- Accidental data leaks: Mixing test records with real project data makes cleaning up or tearing down an experiment difficult.
- Agent risk: Coding agents like Claude Code or Cursor need to run migrations and test queries, but giving them raw access to production data invites accidental deletes.
With thelastapi, you provision one database per project. Every project also gets its own isolated development branch automatically.
How serverless Postgres works on thelastapi
Each database resource provides a direct connection string via DATABASE_URL. Any standard Postgres client (such as postgres or psql), ORM (like Prisma or Drizzle), or migration tool connects over the internet without custom drivers.
| Environment | Database URL | Schema & migrations | Rows | Who has access |
|---|---|---|---|---|
| Production | Live database | Production tables | Real live data | Full-access keys only |
| Development | Branch instance | Mirrored production schema | Zero rows (emptied) | Anyone, including Limited keys and AI agents |
When you run migrations or tests locally, you use the development copy. It mirrors the exact structure of production—keeping migration ledgers intact so tools like Drizzle and Prisma do not run duplicate migrations—while keeping your real user data private.
To learn more about connecting your database in a few seconds, see our guide on how to get a Postgres DATABASE_URL in one command.
Creating a project and getting your database
To start a new project with a serverless Postgres database, run:
vibiz init my-side-project --resources databaseIf you also want sign-in authentication, passing --resources auth provisions the database automatically.
Next, prepare your local development environment:
vibiz devvibiz dev provisions your development environment and writes your variables—including the development DATABASE_URL—into .env.development.local. It prints the variable names while keeping the values hidden.
If you want to run a script or development server immediately without writing to a local file, pass the command directly:
vibiz dev -- npm run devTo reset your development copy back to a fresh branch matching your production schema with zero rows, run:
vibiz dev --resetIf you are using Next.js, read our tutorial on how to use Postgres from Next.js with Drizzle or Prisma.
Connecting with an ORM or standard client
Because the connection string is standard Postgres, you do not need special adapters.
Here is how you connect in TypeScript using the postgres library:
import postgres from 'postgres';
const sql = postgres(process.env.DATABASE_URL!);
// Run standard SQL queries
const rows = await sql`select id, email from users limit 10`;
console.log(rows);You can run your usual schema migrations directly:
npx drizzle-kit migrate
# or: npx prisma migrate deployYou can also read tables and run ad-hoc read queries using the HTTP API:
# List schemas and tables with row estimates
curl "https://thelastapi.dev/v1/projects/prj_123/database?env=development" \
-H "Authorization: Bearer $VIBIZ_API_KEY"
# Run a read-only SQL query
curl https://thelastapi.dev/v1/projects/prj_123/database/query \
-H "Authorization: Bearer $VIBIZ_API_KEY" \
-H 'content-type: application/json' \
-d '{"sql":"select table_name from information_schema.tables where table_schema = '\''public'\''","env":"development"}'The database read view (/database, vibiz_database) supports single SELECT, WITH, TABLE, VALUES, EXPLAIN, or SHOW statements up to 20,000 characters, runs for up to 5 seconds, and returns up to the first 500 rows.
Running on external hosts
You do not need to host your web application on thelastapi to use its database. You can host your app on any server, container, or platform. Read more on how to use a managed Postgres database from an app hosted anywhere.
To connect an external host with minimal setup, supply a single secret: VIBIZ_APP_KEY. Then, load the project variables at boot:
import { vibiz } from '@vibiz/app';
// Injects DATABASE_URL and other project env vars into process.env
await vibiz.loadEnv();Or inject them in your container startup command:
eval "$(curl -fsS -H "Authorization: Bearer $VIBIZ_APP_KEY" \
https://thelastapi.dev/v1/app/env?format=shell)" && exec node server.jsFor more details on running individual components standalone, see our guide on how to use one service.
What agents and keys can access
thelastapi uses scoped API keys to protect production data from unintended access by AI assistants and CI runners:
- Full-access keys (
vz_sk_...,access: owner): Default for owners. Can read production rows, view production connection strings, export production data, and delete resources. - Limited keys (
vz_sk_...,access: agent): Designed for autonomous coding agents (Claude Code, Cursor). A Limited key can create projects, execute migrations against the development database branch, and list tables. If a Limited key attempts to read production rows or retrieve production secrets, it receives a403 owner_onlyerror.
If an agent needs temporary read access to production data, the owner can grant the database.production:read permission:
vibiz keys access key_123 allow database.production:readSee Keys and environments for full permission options.
Backups and leaving without lock-in
Your database is never locked into the platform. With the export feature, you can download a full snapshot of your schema and rows at any time:
# Export code, guide, and a complete SQL dump of the database
vibiz export
# Export only the database as an SQL dump and CSV tables
vibiz export --db --csvThe export generates a .sql.gz file containing all schemas, tables, rows, indexes, triggers, and sequences without custom owner constraints. You can restore it into any vanilla Postgres 15+ instance:
gunzip -c shop-production-database.sql.gz | psql "$NEW_DATABASE_URL"Pricing and limits
thelastapi makes budgeting simple while you experiment:
- Database pricing: While finalized pricing is pending, usage records each ready database at an estimated $0.02 a day of cost, billed with the default margin (+20% today, shown as
billed_usdin usage logs). - Database limits: One database instance per project, with one development branch per project. Table browser views show up to 200 rows; the read API returns up to 500 rows (
truncated: truepast that). - Account safety caps: Accounts start with a $5 daily spend limit and a $1 daily AI budget per project, both adjustable by the account owner.
To explore setup costs for projects, see our breakdown on the cheapest way to host a website and database for a side project.
Next steps
To spin up a new database for your side project, run vibiz init <project-name> --resources database and fetch your development connection string using vibiz dev. For more details on supported query operations, branching, and limits, read the full Database docs.
Frequently asked questions
Can my AI coding agent access my production database rows?
No. By default, Limited keys used by agents can only access the development database branch, which contains your schema but zero production rows. Reading production rows requires a full-access owner key or an explicit `database.production:read` grant.
How do I restore my database if I decide to move away?
You can run `vibiz export --db` to download a `.sql.gz` file containing your full database schema, rows, indexes, and sequences. It can be restored into any Postgres 15 or newer database using standard `psql`.
What happens when I reset my development database branch?
Running `vibiz dev --reset` discards the current development copy. The next time you run `vibiz dev`, the platform creates a fresh branch from your production schema with all data rows emptied while keeping migration ledgers intact.
How much does a side project Postgres database cost?
Ready databases are recorded at an estimated cost of $0.02 a day and billed with a default margin (+20% today, recorded as `billed_usd` in usage) while finalized pricing is being determined.