ATTACH DATABASE
On this page
Note
The AT MILESTONE
and AT TIME
options are available only in the Enterprise edition as they enable PITR, which is a Enterprise feature.
Restores an unlimited storage database at a restore point and then brings the database online.
See Permissions Matrix for the permissions required to use this command.
Syntax
ATTACH DATABASE remote_database_name [AS new_database_name] [AT MILESTONE milestone_name | AT TIME attach_time]
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
-
If
remote_
is currently attached, it must be detached (using DETACH DATABASE) before it can be reattached.database_ name 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 aDATETIME(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
andAT TIME
are not specified, the database is attached at the latest state where all information is available for committed transactions. -
You cannot specify both
AT MILESTONE
andAT TIME
. -
ATTACH DATABASE remote_
renamesdatabase_ name AS new_ database_ name remote_
todatabase_ name new_
, following the attach.database_ name -
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 workspace, 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 workspace. -
This command cannot be run on system databases.
Examples
ATTACH DATABASE db01;
ATTACH DATABASE db01 AT MILESTONE m01;
ATTACH DATABASE db01 AT TIME “2022-09-03 11:37:07”;
Attach a Database to a Workspace
You can only attach a database to a workspace within a single workspace group.
A database cannot have more than one read-write attachment.
Databases with a large number of partitions cannot be attached to a small workspace.
Here is an example of the error message when the total number of partitions is greater: "Creating or attaching a database with 32 total partitions to a cluster or workspace with 2 total cores is not supported.
To attach an existing database in the read-write mode to a workspace, connect to the target workspace and execute the following command:
ATTACH DATABASE db_name;
To attach an existing database to a workspace in the read-only mode, execute the following command:
ATTACH DATABASE db_name READ ONLY;
The read-only mode is mutually exclusive with the PITR options.
When the Enable SmartDR and Database Branching
checkbox is selected at the time of workspace group creation, you can attach a database to a milestone but you cannot rename the database.
Note
SHOW DATABASES
only lists the databases that are attached to the current workspace.
Last modified: November 26, 2024