# Databases and files You can start a project with just a PostgreSQL database or a file bucket. Both live on your workspace’s compute. You can create them, check their status and see how much data they hold before you create an app. When you want to query the database or upload files, connect an app. A persistent disk belongs to the app that mounts it. ## Create a database In **Services**, choose **New → Database**, select a project and give the database a name. Or use the CLI: ```sh smolcloud database PROJECT_ID "My database" ``` Save the returned `id`. Open the database in **Services** to see when it’s ready and check its storage usage. PostgreSQL starts with 256 MiB of memory by default. If you need a different size, choose it at creation or resize the database later in its settings. ## Create a bucket In **Services**, choose **New → Bucket**, select a project and give the bucket a name. From the CLI: ```sh smolcloud bucket PROJECT_ID "My files" ``` Save the returned `id`. The bucket’s page shows the object count and bytes stored. Files you add later live on a private volume on your workspace’s compute. [Where bucket files and metadata live](workspace-architecture.md). For either resource, you can use `smolcloud database list` or `smolcloud bucket list` to find its ID again. Both commands return the same index. In `resources`, match the `projectId`, `kind` and `name`, then read `id` and `state`. ## Connect an app when you need access Choose a ready resource and an app you administer. You can create the app and connect it before its first deployment. Use the command for the resource you want, replacing `RESOURCE_ID` with the ID from the create or list command. | To connect | Run | | ----------- | ----------------------------------------------- | | PostgreSQL | `smolcloud database connect APP_ID RESOURCE_ID` | | File bucket | `smolcloud bucket connect APP_ID RESOURCE_ID` | **Query PostgreSQL.** Read `DATABASE_URL` in your app’s backend and use a PostgreSQL driver. Your app manages its schema and migrations. Connecting a database to an app that’s already serving triggers a redeployment with the new connection. **Upload a file.** Once the bucket is connected and enabled, the workspace owner can open the app’s **Files** tab and choose **Upload file**. This works before any app code is deployed. **Use S3 from your app.** Deploy the app after connecting the bucket. Configure a SigV4 S3 client with path-style addressing using `S3_ENDPOINT`, `S3_REGION`, `S3_BUCKET`, `S3_ACCESS_KEY_ID` and `S3_SECRET_ACCESS_KEY` from its backend environment. Keep the credentials out of browser code. An app administrator can check readiness with `smolcloud capabilities APP_ID`. An agent working in a sandbox can also [request temporary access to a connected database or bucket](sandbox-resources.md). ## Use a persistent disk Use a disk when your app needs files at a filesystem path across deployments. Request `volume` with its size in [innie-resources.json](resource-declarations.md) and deploy for owner approval. The app reads and writes its files under `/data`. ## Manage access and data Workspace owners, admins, builders and named agents with builder access can create resources. You can connect a resource you created to an app you administer. The workspace owner can manage connections for other people’s resources. Disconnecting an app preserves the database or bucket and its contents. Other connected apps keep their access. [Rolling back app code](rollback.md) also preserves the current data. ## Limits - Hosted workspaces need allocated compute to create a database or bucket. - A workspace can have up to four databases. Workspaces on a shared runtime pool can have four buckets. Other installations allow up to sixteen. Deleted resources don’t count. - Each app can connect to one managed database and one managed bucket at a time. A managed database can serve up to four connected apps.