In this tutorial, we are going to learn about DataStax Astra DB, how to create a database with Astra DB, how to load sample data to the database and finally how to connect the databases.
Before getting started with Astra DB, let me give you a brief introduction to Astra DB.
Table of Contents
1. What is DataStax Astra DB?
DataStax Astra DB is a Database as a service built on Apache Cassandra. Astra DB is a product of DataStax and it will be provided as Cassandra as a service.
Astra DB makes developing cloud-native Cassandra applications simple. It combines an extraordinary combination of serverless, pay-as-you-go pricing with the freedom and agility of multi-cloud and open source. It is reducing deployment time from weeks to minutes.
DataStax Astra DB is a cloud-native service that allows you to design and deploy data-driven apps without the headaches of database and infrastructure administration.
Astra DB dramatically simplifies database and streaming operations by automatic tuning and configuration.
2. Creating DataStax Astra DB account
Navigate to Astra DB sign in page. Create an account by filling basic details as shown below.
As soon as you accept the 'Terms and Policies', verification mail will be sent to the mail and it should be verified.
Go to your mailbox and click the confirmation link.
Once the Astra DB account is created, you can view the dashboard.
3. Create Astra DB Database
Click 'Create Database' button on the left pane of the Astra DB Dashboard. For the purpose of this guide, we are creating the DB under a free plan with 25$ credit. We can go for a pay-as-you-go plan at any time.
- Enter the Database name. Please not that the name of the DB can not be changed later.
- Enter the keyspace name to reflect your data model. It is like a table in SQL databases.
- Select the Cloud Provider name and region where you want to launch the DB.
After entering the database details, click 'Create Database' to proceed.
You will be redirected to your Dashboard. You can view the status of the Database under Databases section.
You will receive an email saying that a database has been created.
4. States of Databases
Your database can be in several different states. These statuses change depending on what you do in your database.
- Active: Your database is now accessible for use.
- Initializing: Once you selected the Database to use, it is being initialized and will be available soon.
- Terminating: The Database is being terminated, which means the Data belongs to the database are being deleted.
- Terminated: Your database has been terminated, which means all its contents have been deleted and it will not be available anymore.
- Error: There is something wrong with the Database; we need to contact DataStax support.
- Maintenance: When a database is being moved into standby or restarted from standby, it will show up in the Maintenance status.
- Standby: When a database has been idle for more than 15 days, it is placed in Standby mode. View your database in Astra Dashboard to restart it from Standby.
- Parking: The database is being parked.
- Parked: The database is parked. You cannot use the database until you unpark the database.
- Resizing: You increased the capacity of your database by resizing it. While your database is being resized, it has limited functionality.
5. Monitor Database
The Grafana dashboard incorporated in the Astra DB console shows database metrics. Metrics details are given in the graph and it is being captured over the time. In nanoseconds, read and write latencies are displayed.
Grafana is an open source analytical and visualisation application that comprises of several separate panels placed in a grid. Grafana dashboards allow you to visualise results from various data sources at the same time because they support several panels in a single grid.
6. Manage Organization
6.1. Add Organization
Using DataStax Astra DB, you can create several organisations which is useful for segmenting user groups and generating different environments.
By clicking the 'Manage Organization' in the drop down, you can add multiple organizations by entering the name and Mail ID. Notification will be sent to the mail address entered for the organization owner.
6.2. Add Users to the Organization
Go to Current Organization ? Organization Settings.
You can invite the users by entering their name and mail ID, and the invitation will be sent to the user's mail ID. As soon as the user accepted the invitation, he will be added to the Organization.
Under Role Management tab, you can create and manage the roles.
7. Loading Data
Astra DB has its own data loader embedded into the user interface. Using the DataStax Astra DB Data Loader, you can import your own data or sample data available in Astra DB.
Let us load the sample data using Data Loader in the Dashboard.
To import sample data, click the Load Data button:
Choose Option 1 to upload your own dataset.
Here, we are loading sample csv data named "heart.csv".
Once the data is uploaded, you can view the data in the Configure section. To complete the loading process, you need to mention the partition key.
Select the Database and keyspace where the data to be loaded. Click next to complete the loading process.
8. Connect the Database
Databases can be connected in various methods as listed below.
- Through APIs like Document API, Graph API and REST API.
- Using Drivers like Node.js, Python, Java and C++, we can connect the Database.
- Using SDK like JavaScript SDK, Python SDK and Java SDK can be used to connect the Database.
- We can integrate with other tools like Spark to connect the Database.
- CQL Console is provided in the dashboard itself to connect the database and query the data.
8.1. Connect database via CQL Console
To access CQL console, select Database ? CQL Console.
In the console, run the following command to select the keyspace:
token@cqlsh> use ostechnix_test;
To select all data with limit 5 rows:
token@cqlsh:ostechnix_test> select * from heart limit 5;
9. Conclusion
In this article, we briefly discussed what is DataStax Astra DB and the basic Astra DB usage like how to create, manage, monitor and connect databases in an easy-to-follow steps.
Resource: