# ATTACH DATABASE

> **📝 Note**: The `AT MILESTONE` and `AT TIME` options are available only in the Enterprise edition as they enable PITR, which is an Enterprise feature. For more information, refer to [SingleStore Editions](https://docs.singlestore.com/db/v9.1/introduction/singlestore-editions.md).In the SingleStore Free version, this command is not supported.

> **📝 Note**: Prior to using this command, the `enable_bottomless` [engine variable](https://docs.singlestore.com/db/v9.1/reference/configuration-reference/engine-variables.md) must be set to `ON` (the default value).&#x20;

The `ATTACH DATABASE` command restores an unlimited storage database at a restore point and then brings the database online.

See [Permissions Matrix](https://docs.singlestore.com/db/v9.1/reference/sql-reference/security-management-commands/permissions-matrix.md) for the permissions required to use this command.

## Syntax

```
ATTACH DATABASE remote_database_name ON <object_store_settings> [AT MILESTONE milestone_name | AT TIME attach_time]

[STORAGEID <storage id>]

<object_store_settings>:
    <S3_object_store_configuration> |
    <AZURE_object_store_configuration> |
    <GCS_object_store_configuration>

<S3_object_store_configuration>:
    S3 "bucket/path" 
      [CONFIG '<configuration_json>']
      CREDENTIALS '<credentials_json>'

<configuration_json>
{"region":"your_region"}
<credentials_json>
{"aws_access_key_id":"your_access_key_id","aws_secret_access_key":"your_secret_access_key"}


<AZURE_object_store_configuration>:
    AZURE "container/blob-prefix" 
      [CONFIG '<configuration_json>']
      CREDENTIALS '<credentials_json>'

<configuration_json>
{}
<credentials_json>
{"account_name": "your_account_name_here", "account_key": "your_account_key_here"}


<GCS_object_store_configuration>: 
   GCS "bucket/path" 
    [CONFIG '<configuration_json>']
    CREDENTIALS '<credentials_json>'

<configuration_json>
{}
<credentials_json>
{"access_id": "your_google_access_key", "secret_key": "your_google_secret_key"}

```

## Arguments

## attach\_time

A `DATETIME` or `DATETIME(6)` literal.

## milestone\_name

A quoted string, which is the name of a milestone to restore to.

## Remarks

* Please note the following:

  * Attaching a database from an earlier version of SingleStore to a later version of SingleStore is supported.
  * Attaching a database from a later version of SingleStore to an earlier version of SingleStore is *not* supported.

  For example, while it is possible to attach a SingleStore 8.9 database to SingleStore 9.0, it is not possible to attach a SingleStore 9.0 database to SingleStore 8.9.
* If `remote_database_name` is currently attached, it must be detached (using [DETACH DATABASE](https://docs.singlestore.com/db/v9.1/reference/sql-reference/data-definition-language-ddl/detach-database.md)) before it can be reattached. At the time of reattaching ensure the object\_store\_settings and configurations are the same as those used at the time of the database creation.
* `AT TIME` attaches the database, with its contents restored to the specified point in time. The specified time may be a `DATETIME` or a `DATETIME(6)` literal. An error will be returned if you attempt to attach a database at time literal that is later than the time of the latest detach.
* If `AT MILESTONE` and `AT TIME` are not specified, the database is attached at the latest state where all information is available for committed transactions.
* If `AT MILESTONE` or `AT TIME` are specified, the restore point must be within the [unlimited storage database retention period](https://docs.singlestore.com/db/v9.1/manage-data/unlimited-data-storage/configure-the-retention-period-for-an-unlimited-storage-database.md).
* You cannot specify both `AT MILESTONE` and `AT TIME`.
* `remote_database_name` of the attached database can be different than the `remote_database_name` used when the database was detached.
* `ATTACH DATABASE remote_database_name AS new_database_name` renames `remote_database_name` to `new_database_name`, following the attach.
* `CONFIG '<configuration_json>'` and `CREDENTIALS '<credentials_json>'` : for S3 the options are anything that S3 supports. For Azure and GCS the config is optional. For configuration examples refer [BACKUP DATABASE](https://docs.singlestore.com/db/v9.1/reference/sql-reference/operational-commands/backup-database.md)
* `STORAGEID <storage id>`: should be used to avoid the 2523 error when multiple bottomless databases are created on S3 in the same folder, and any one of the database is detached and re-attached . The storage id value can be found from the STORAGE\_ID column in the information\_schema.MV\_BOTTOMLESS\_REMOTE\_STATS table.
* Attaching an unlimited storage database can be faster than restoring an equivalent local storage database. This is because an attach of an unlimited storage database does not copy all data to the cluster, as is the case with the restore of a local storage database. Note that after an unlimited storage database is attached, queries may be slower for some time until remote data is cached locally in the cluster.
* This command cannot be run on [system databases](https://docs.singlestore.com/db/v9.1/reference/system-databases.md).

## Examples

## Using S3

```sql
ATTACH DATABASE memsql_demo ON S3 "demo_bucket/"
  CONFIG '{"region":"us-east-1"}'
  CREDENTIALS '{"aws_access_key_id":"your_access_key_id","aws_secret_access_key":"your_secret_access_key"}';
```

## Using Azure

```sql
ATTACH DATABASE memsql_demo ON AZURE "demo_bucket/"
CREDENTIALS '{"account_name":"your_account_name_here","account_key":"your_account_key_here"}';
```

## Using GCS

```sql
ATTACH DATABASE memsql_demo ON GCS "demo_bucket/"
  CREDENTIALS '{"access_id":"your_google_access_key","secret_key":"your_google_secret_key"}';
```

***

Modified at: June 11, 2026

Source: [/db/v9.1/reference/sql-reference/data-definition-language-ddl/attach-database/](https://docs.singlestore.com/db/v9.1/reference/sql-reference/data-definition-language-ddl/attach-database/)

(An index of the documentation is available at /llms.txt)
