# Manage databases    
Stay organized with collections. Save and categorize content based on your preferences.

## Required roles and permissions
To create and manage databases, you'll need the following Identity and Access Management role:

- [Cloud Datastore Owner](/content/iam/docs/roles-permissions/firestore#datastore.owner) (`roles/datastore.owner`)

That role grants the following permissions that you need to create and manage databases:

- Create a database: `datastore.databases.create`
- Read database configuration: `datastore.databases.getMetadata`
- Configure a database: `datastore.databases.update`
- Delete a database: `datastore.databases.delete`
- Clone a database: `datastore.databases.clone`

## Create a database
To create a database, use one of the following methods:

[Console](/content/docs/firestore/manage-databases#console/index.html)[gcloud](/content/docs/firestore/manage-databases#gcloud/index.html)[Firebase CLI](/content/docs/firestore/manage-databases#firebase-cli/index.html)[Terraform](/content/docs/firestore/manage-databases#terraform/index.html)

### Firebase console
1. In the Firebase console, go to **Databases & Storage** > **Firestore**.  
    [Go to Firestore](https://console.firebase.google.com/project/_/firestore/databases)
2. Click **Add database**.
3. Select **Standard edition**. Click **Next**.
4. Enter a Database ID.
5. Select a location for your database. Click **Next**.
6. Select a starting mode for your Cloud Firestore Security Rules:
   - Test mode: Good for getting started with the mobile and web client libraries, but allows anyone to read and overwrite your data. After testing, **make** **sure to review the [Secure your data](/content/docs/firestore/enterprise/security/overview/index.html)** section.
   - Production mode: Denies all reads and writes from mobile and web clients. Your authenticated application servers (Node.js, Python, Java) can still access your database.
7. Click **Create**.

### Using gcloud command
Use the [`gcloud firestore databases create`](https://cloud.google.com/sdk/gcloud/reference/firestore/databases/create) command.

```bash
gcloud firestore databases create \
  --database=DATABASE_ID \
  --location=LOCATION \
  --edition=standard \
  --type=DATABASE_TYPE
```

Replace the following:
- DATABASE_ID: a [valid database ID](/content/docs/firestore/manage-databases#database_id/index.html).
- LOCATION: the name of a [Cloud Firestore multi-region or region](/content/docs/firestore/locations#types/index.html).
- DATABASE_TYPE: either `firestore-native` for Native mode or `datastore-mode` for Datastore mode.

`--delete-protection` is an optional flag to enable deletion protection.

### Tags
To add [tags](https://cloud.google.com/firestore/docs/tags) to the database, use the [`--tags`](https://cloud.google.com/sdk/gcloud/reference/firestore/databases/create#--tags) flag:

```bash
--tags=123/environment=production,123/costCenter=marketing
```

## Update database configuration
To update the configurations settings of a database, use the [`gcloud firestore databases update`](https://cloud.google.com/sdk/gcloud/reference/firestore/databases/update) command.

## Delete a database
To delete a database, use the console or command-line tool.
1. In the Firebase console, go to **Databases & Storage** > **Firestore**.  
2. In the **Data** tab, above the data table view for the database, click more_vert, then select **Delete database**.  
3. Follow the instructions to delete the database.

Use the [`gcloud firestore databases delete`](https://cloud.google.com/sdk/gcloud/reference/firestore/databases/delete) command.

```bash
gcloud firestore databases delete --database=DATABASE_ID
```

Replace DATABASE_ID with the ID of the database to delete. To delete the default database use the ID `'(default)'`.

## Clone a database
You can clone an existing database at a selected timestamp into a new database:

- The cloned database is a new database that will be created in the same location as the source database.
- To make a clone, Cloud Firestore uses [point-in-time recovery (PITR) data](/content/docs/firestore/pitr/index.html) of the source database. The cloned database includes all data and indexes.

Use the [`gcloud firestore databases clone`](https://cloud.google.com/sdk/gcloud/reference/firestore/databases/clone) command to clone a database:

```bash
gcloud firestore databases clone \
--source-database='SOURCE_DATABASE' \
--snapshot-time='PITR_TIMESTAMP' \
--destination-database='DESTINATION_DATABASE_ID'
```

Replace the following:
- SOURCE_DATABASE: the database name of an existing database that you want to clone.
- PITR_TIMESTAMP: a [PITR timestamp](/content/docs/firestore/use-pitr#get-period/index.html) in the [RFC 3339 format](https://tools.ietf.org/html/rfc3339).
- DESTINATION_DATABASE_ID: a [database ID](/content/docs/firestore/manage-databases#database_id/index.html) for a new cloned database.

### IAM Conditions
You can use [Identity and Access Management Conditions](https://cloud.google.com/iam/docs/conditions-overview) to configure access permissions on a per-database level. The following examples use the Google Cloud CLI to assign conditional access.

## Cloud Monitoring
Cloud Firestore metrics are reported under two monitored resources:
- [firestore.googleapis.com/Database](https://cloud.google.com/monitoring/api/resources#tag_firestore.googleapis.com/Database)
- [firestore_instance](https://cloud.google.com/monitoring/api/resources#tag_firestore_instance)(Legacy)

## Limitations
- You can have a maximum of 100 databases per project. You can [contact support](/content/support/index.html) to request an increase to this limit.
- You cannot delete your `(default)` database if it contains any [GAE search data](https://cloud.google.com/appengine/docs/legacy/standard/python/search).

### Next Steps
- [Add data](/content/docs/firestore/manage-data/add-data/index.html)
- [Get data](/content/docs/firestore/query-data/get-data/index.html)
- [Delete data](/content/docs/firestore/manage-data/delete-data/index.html)
