Managed Database
moonbase provides the database
moonbase hosts your app and its database. An app that moonbase builds and runs (a Node.js or Python app, such as Next.js, Express, Flask or Django) can add one managed PostgreSQL database (up to one per mission), run by moonbase, where it is enabled for your account. You don't sign up anywhere else, and you don't copy a connection string: on an eligible deploy moonbase creates the database and gives your app its connection settings.
Who gets it
Every plan, Free included, can add one managed PostgreSQL database per mission (up to one), where it is enabled for your account. It is created only when your project asks for one, during a deploy, so no app gets one automatically. A mission served as plain static files, with no build step and no server, can't have one: a database entry there stops the deploy.
Storage
The database uses your plan's storage: there is no separate database allowance. See Pricing for each plan's storage.
Backups and export
The mission's Database page shows the database's backup status to the mission's owner, when that status is available. The backup schedule and retention on the [Infrastructure](/infrastructure) page describe moonbase's own platform database, not a mission's managed database. The owner can also download a copy of the database when exports are available; see Export Your Database.
Your AI agent creates it for you
Ask your AI agent for an app that keeps data, and deploy it to moonbase. An agent connected with the moonbase connector can do the rest:
1. It reads the database section of moonbase's build guide with the get_build_guide tool.
2. It adds a database entry to the moonbase.json file at the root of your project, with the command that creates your tables.
3. It deploys with create_mission or deploy. A larger project goes through create_upload, which gives the agent an upload link and one command to send the ZIP; where the agent can't run that command, it sends the files with upload_files and publishes them with commit_upload. On that deploy, when a managed database is enabled for your account and the mission has no DATABASE_URL of your own, moonbase creates the database, runs the command and gives the app its connection settings.
4. It checks the result with deploy_status and mission_info, which report the database, and account_usage, which shows your plan's storage and what is using it.
The database entry looks like this:
{
"database": { "engine": "postgresql", "migrate": "node migrate.js" }
}The migrate command runs on every deploy, before the new version goes live; if it fails, the previous version stays live. A failed migration can leave changes in the database even though the new app version is not published. Make migrations safe to repeat and compatible with the version still running.
How your app connects
For a managed database you don't type the connection string. On every deploy moonbase gives the running app, and the migrate command, three environment variables:
• DATABASE_URL: the connection string (user, password, host, port and database name). It is managed by moonbase and refreshed at each deploy, so it can't be replaced or deleted.
• PILOT_DB_CA_FILE: the path of the certificate file used to verify the database server.
• PILOT_DB_SERVER_NAME: the name on the database server's certificate.
This is the required connection recipe: the app must connect with TLS and verify the server's certificate, using the certificate file and the server name above in its database driver's own TLS options. DATABASE_URL alone does not set that up. Your agent's build guide carries the connection code; don't add sslmode or other parameters to DATABASE_URL.
If you saved a DATABASE_URL of your own on a mission before it ever had a managed database, that value stays: moonbase creates no managed database over it, and the app keeps using yours. To switch to the managed database, delete your DATABASE_URL on the Environment Variables screen and deploy again.
Where you see it
The mission's page shows a Database card to the mission's owner, with a link to the Database page. The status, backup status and export shown there are for the owner, and each appears when it is available.
Without an AI agent
Add the same database entry to moonbase.json at the root of your project and upload the project as usual. For an app that moonbase builds and runs, on an account where a managed database is enabled, moonbase creates the database on that deploy.