Database
Zilliz Cloud introduces a database layer in between the clusters and collections, providing a more efficient way to manage and organize your data while supporting multi-tenancy.
What is a database
In Zilliz Cloud, a database serves as a logical unit for organizing and managing data. To enhance data security and achieve multi-tenancy, you can create multiple databases to logically isolate data for different applications or tenants. For example, you create a database to store the data of user A and another database for user B.
The resources are structured in the following hierarchical order in Zilliz Cloud.
It can be noted that the concept of database is only available to Dedicated clusters. Serverless and Free clusters do not have databases.
Prerequisites
You need to have Organization Owner or Project Admin access to manage databases.
Create database
Databases can only be created in Dedicated clusters. Upon the creation of a cluster, a default database will be created.
You can create up to 1,024 databases in a Dedicated cluster either manually on the console or programmatically.
Create a database on the console
You can create a database on the console as shown in the following figure.
You can also move created collections from one database to another. For more details, refer to Manage Collections (Console).
Create a database programmatically
You can use the Milvus RESTful API or SDKs to create data programmatically.
- Python
- Java
- NodeJS
- Go
- cURL
from pymilvus import MilvusClient
client = MilvusClient(
uri="YOUR_CLUSTER_ENDPOINT",
token="YOUR_CLUSTER_TOKEN"
)
client.create_database(
db_name="my_database_1"
)
import io.milvus.v2.client.MilvusClientV2;
import io.milvus.v2.client.ConnectConfig;
import io.milvus.v2.service.database.request.*;
ConnectConfig config = ConnectConfig.builder()
.uri("YOUR_CLUSTER_ENDPOINT")
.token("YOUR_CLUSTER_TOKEN")
.build();
MilvusClientV2 client = new MilvusClientV2(config);
CreateDatabaseReq createDatabaseReq = CreateDatabaseReq.builder()
.databaseName("my_database_1")
.build();
client.createDatabase(createDatabaseReq);
import {MilvusClient} from '@zilliz/milvus2-sdk-node';
const client = new MilvusClient({
address: "YOUR_CLUSTER_ENDPOINT",
token: 'YOUR_CLUSTER_TOKEN'
});
await client.createDatabase({
db_name: "my_database_1"
});
// TODO
export CLUSTER_ENDPOINT="YOUR_CLUSTER_ENDPOINT"
export TOKEN="YOUR_CLUSTER_TOKEN"
curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/vectordb/databases/create" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
-d '{
"dbName": "my_database_1"
}'
You can also set properties for the database when you create it. The following example sets the number of replicas of the database.
- Python
- Java
- NodeJS
- Go
- cURL
client.create_database(
db_name="my_database_2",
properties={
"database.replica.number": 3
}
)
Map<String, String> properties = new HashMap<>();
properties.put("database.replica.number", "3");
CreateDatabaseReq createDatabaseReq = CreateDatabaseReq.builder()
.databaseName("my_database_2")
.properties(properties)
.build();
client.createDatabase(createDatabaseReq);
// TODO
// TODO
export CLUSTER_ENDPOINT="YOUR_CLUSTER_ENDPOINT"
export TOKEN="YOUR_CLUSTER_TOKEN"
curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/vectordb/databases/create" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
-d '{
"dbName": "my_database_2",
"properties": {
"database.replica.number": 3
}
}'
View databases
You can use the Milvus RESTful API or SDKs to list all existing databases and view their details.
- Python
- Java
- NodeJS
- Go
- cURL
# List all existing databases
client.list_databases()
# Output
# ['default', 'my_database_1', 'my_database_2']
# Check database details
client.describe_database(
db_name="default"
)
# Output
# {"name": "default"}
import io.milvus.v2.service.database.response.*;
ListDatabasesResp listDatabasesResp = client.listDatabases();
DescribeDatabaseResp descDBResp = client.describeDatabase(DescribeDatabaseReq.builder()
.databaseName("default")
.build());
await client.describeDatabase({
db_name: 'default'
});
// TODO
export CLUSTER_ENDPOINT="YOUR_CLUSTER_ENDPOINT"
export TOKEN="YOUR_CLUSTER_TOKEN"
curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/vectordb/databases/describe" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
-d '{
"dbName": "default"
}'
Manage database properties
Each database has its own properties, you can set the properties of a database when you create the database as described in Create a database programmatically or you can alter and drop the properties of any existing database.
The following table lists possible database properties.
Property Name | Type | Property Description |
---|---|---|
| integer | The number of replicas for the specified database. |
| integer | The maximum number of collections allowed in the specified database. |
| boolean | Whether to force the specified database to deny writing operations. |
| boolean | Whether to force the specified database to deny reading operations. |
Alter database properties
You can alter the properties of an existing database as follows. The following example limits the number of collections you can create in the database.
- Python
- Java
- NodeJS
- Go
- cURL
client.alter_database_properties(
db_name: "my_database_1",
properties: {
"database.max.collections": 10
}
)
client.alterDatabaseProperties(AlterDatabasePropertiesReq.builder()
.databaseName("my_database_1")
.property("database.max.collections", "10")
.build());
await milvusClient.alterDatabaseProperties({
db_name: "my_database_1",
properties: {"database.max.collections", "10" },
})
// TODO
export CLUSTER_ENDPOINT="YOUR_CLUSTER_ENDPOINT"
export TOKEN="YOUR_CLUSTER_TOKEN"
curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/vectordb/databases/alter" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
-d '{
"dbName": "my_database",
"properties": {
"database.max.collections": 10
}
}'
Drop database properties
You can also reset a database property by dropping it as follows. The following example removes the limit on the number of collections you can create in the database.
- Python
- Java
- NodeJS
- Go
- cURL
client.drop_database_properties(
db_name: "my_database_1",
property_keys: [
"database.max.collections"
]
)
client.dropDatabaseProperties(DropDatabasePropertiesReq.builder()
.databaseName("my_database_1")
.propertyKeys(Collections.singletonList("database.max.collections"))
.build());
await milvusClient.dropDatabaseProperties({
db_name: my_database_1,
properties: ["database.max.collections"],
});
// TODO
export CLUSTER_ENDPOINT="YOUR_CLUSTER_ENDPOINT"
export TOKEN="YOUR_CLUSTER_TOKEN"
curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/vectordb/databases/alter" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
-d '{
"dbName": "my_database",
"propertyKeys": [
"database.max.collections"
]
}'
Drop database
Once a database is no longer needed, you can drop the database. Note that:
-
Default databases cannot be dropped.
-
Before dropping a database, you need to drop all collections in the database first.
Drop a database on the console
You can drop the database on the console by following the procedure in the figure below.
Drop a database programmatically
You can use the Milvus RESTful API or SDKs to create data programmatically.
- Python
- Java
- NodeJS
- Go
- cURL
client.drop_database(
db_name="my_database_2"
)
client.dropDatabase(DropDatabaseReq.builder()
.databaseName("my_database_2")
.build());
await milvusClient.dropDatabase({
db_name: "my_database_2",
});
// TODO
export CLUSTER_ENDPOINT="YOUR_CLUSTER_ENDPOINT"
export TOKEN="YOUR_CLUSTER_TOKEN"
curl --request POST \
--url "${CLUSTER_ENDPOINT}/v2/vectordb/databases/drop" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
-d '{
"dbName": "my_database"
}'