Checkpoints
Create a baseline data set
/ 50
Testing the Columnar Engine
/ 50
Accelerating Analytical Queries using the AlloyDB Columnar Engine
GSP1087
Overview
AlloyDB for PostgreSQL is a fully managed PostgreSQL-compatible database service for your most demanding enterprise database workloads. AlloyDB combines the best of Google with one of the most popular open-source database engines, PostgreSQL, for superior performance, scale, and availability.
The Columnar Engine can significantly accelerate the speed at which AlloyDB processes SQL scans, joins, and aggregates. The Columnar Engine provides the following features: 1) a column store that contains table data for selected columns, reorganized into a column-oriented format and 2) a columnar query planner and execution engine to support use of the column store in queries.
In this lab you will explore features of the AlloyDB Columnar Engine.
Objectives
In this lab, you learn how to perform the following tasks:
-
Create Baseline Dataset for Testing the Columnar Engine
-
Run a Baseline Test
-
Verify the Database Flag for the Columnar Engine
-
Set or Verify the Database Extension for the Columnar Engine
-
Testing the Columnar Engine
Setup and requirements
Qwiklabs setup
Before you click the Start Lab button
Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources will be made available to you.
This hands-on lab lets you do the lab activities yourself in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials that you use to sign in and access Google Cloud for the duration of the lab.
What you need
To complete this lab, you need:
- Access to a standard internet browser (Chrome browser recommended).
- Time to complete the lab.
Cloud Console
Log in to Google Cloud Console
- Using the browser tab or window you are using for this lab session, copy the Username from the Connection Details panel and click the Open Google Console button.
- Paste in the Username, and then the Password as prompted.
- Click Next.
- Accept the terms and conditions.
Since this is a temporary account, which will last only as long as this lab:
-
Do not add recovery options
-
Do not sign up for free trials
- Once the console opens, view the list of services by clicking the Navigation menu (
) at the top-left.
Activate Cloud Shell
Cloud Shell is a virtual machine that contains development tools. It offers a persistent 5-GB home directory and runs on Google Cloud. Cloud Shell provides command-line access to your Google Cloud resources. gcloud
is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab completion.
-
Click the Activate Cloud Shell button (
) at the top right of the console.
-
Click Continue.
It takes a few moments to provision and connect to the environment. When you are connected, you are also authenticated, and the project is set to your PROJECT_ID.
Sample commands
-
List the active account name:
(Output)
(Example output)
-
List the project ID:
(Output)
(Example output)
Task 1. Create Baseline Dataset for Testing the Columnar Engine
-
An AlloyDB cluster and instance were provisioned when you started the lab. On the Cloud Console Navigation menu (
), under Databases click AlloyDB for PostgreSQL then Clusters to examine the cluster's details.
-
The cluster is named lab-cluster and the instance is named lab-instance.
-
The instance takes a while to be fully created and initialized. Please wait until you see a Status of Ready to proceed.
-
Please make note of the Private IP address in the instances section. Copy the Private IP address to a text file so that you can paste the value in a later step.
-
In order to evaluate the capabilities of the Columnar Engine you need a dataset of significant size against which to measure performance. You will utilize the Postgres tool pgbench to generate a synthetic dataset to evaluate the Columnar Engine.
-
On the Navigation menu (
), under Compute Engine click VM instances.
-
For the instance named alloydb-client, in the Connect column, click SSH to open a terminal window.
-
Set the following environment variable, replacing ALLOYDB_ADDRESS with the Private IP address of the AlloyDB instance.
-
Run the following command to store the Private IP address of the AlloyDB instance on the AlloyDB client VM so that it will persist throughout the lab.
- The first step of using pgbench is to create and populate the sample tables. Run the following command to create a set of four tables. You will be prompted for the postgres user's password which is Change3Me.
The largest table pgbench_accounts will be loaded with 50 million rows. The operation will take just a few minutes.
-
Connect to the psql client and run the following query to verify the row count in the pgbench_accounts table. You will be prompted for the postgres user's password which is Change3Me.
- Click Check my progress to verify the objective.
Task 2. Run a Baseline Test
-
For evaluation purposes you can run a very simple query that performs seq scans and then use explain query plans for that query before and after adding the test table to the Columnar Engine.
-
Return to the alloydb-client shell. The psql client should still be active. If not, reconnect using the instructions in Task 1. Run the following query to turn on timings for all query operations.
-
Next run the following query to evaluate the run time. This query performs seq scans of the entire pgbench_accounts table. Note: This sample query has a limit of 20 returned rows because this is for demonstration purposes.
- Run the following query to generate an explain plan for an unrestricted query. Your values should appear similar to those in the sample output but will vary because of the random nature of data generation.
-
In the results pay particular attention to the Planning Time and Execution Time values. In the sample output, the Planning Time is 0.117 milliseconds and the Execution Time is 11014.169 milliseconds or 11.014 seconds. Your values should appear similar to those in the sample output but will vary because of the random nature of data generation.
-
Copy the values for Planning Time and Execution Time from your run to text file so that you may compare them later with the results after the Columnar Engine is enabled. You may also copy the entire query plan results to a text file.
-
Press the Q key to close the query plan.
Task 3. Verify the Database Flag for the Columnar Engine
-
Next you will examine the Columnar Engine database flag in your instance.
-
On the Cloud Console Navigation menu (
), under Databases click AlloyDB for PostgreSQL then Clusters to examine the cluster's details.
-
In the Instances in your cluster section, select the lab-instance, and then click Edit Primary.
-
To add a database flag to your instance, click Add flag.
-
Browse the list of available flags to get a sense of the supported options. Observe the flag google_columnar_engine.enabled in the list. You will not add an additional flag as part of this lab.
-
Click Cancel twice to exit the Edit Primary instance screen.
Task 4. Set or Verify a Database Extension for the Columnar Engine
-
Continuing from the previous section you will setup a database extension to fully enable the Columnar Engine feature for your AlloyDB cluster.
-
Unlike configuring a flag, you must connect to your instance via the psql client to enable a database extension.
-
Return to the alloydb-client shell. The psql client should still be active. If not, reconnect using the instructions in Task 1.
-
Ensure that you are connected to the postgres database by running the following query.
- Run the following system query to see details on the extensions enabled in the database.
-
If google_columnar_engine appears in the list, skip to the next task (Task 5). If google_columnar_engine does not appear in the list run the following command.
-
Run the extension query again to confirm that the google_columnar_engine extension is enabled.
Task 5. Testing the Columnar Engine
-
Because your main table ( pgbench_accounts) is relatively small, you can add it directly to the Columnar Engine for evaluation. In a real-life deployment you would utilize the Columnar Engine's recommendation framework to automatically identify the most heavily used columns across all tables that would provide the most benefit from being managed by the engine.
-
Return to the alloydb-client shell. Run the following query to add pgbench_accounts to the columnar engine. The query should take a few minutes to complete.
-
Next run the same explain plan query you did earlier to see the affects of the Columnar Engine. Your values should appear similar to those in the sample output but will vary because of the random nature of data generation.
-
In the results pay particular attention to the Planning Time and Execution Time values. In the Post-Columnar Engine sample, the Planning Time is 2.022 milliseconds and the Execution Time is 78.804 milliseconds. Your values should appear similar to those in the sample output but will vary because of the random nature of data generation.
-
From the samples provided, the difference between the Execution Time Pre-Columnar Engine and Post-Columnar Engine is 10935.365 ms or 10.9 seconds. That is a decrease of 141 times. In the Post-Columnar Engine sample, also note that over 4.5 million rows were aggregated using a columnar scan rather than the core database engine.
-
Click Check my progress to verify the objective.
Congratulations!
You have now explored powerful features of the AlloyDB Columnar Engine.
Finish your quest
This self-paced lab is part of the Create and Manage AlloyDB Databases quest. A quest is a series of related labs that form a learning path. Completing this quest earns you a badge to recognize your achievement. You can make your badge (or badges) public and link to them in your online resume or social media account. Enroll in this quest and get immediate completion credit if you have successfully completed this lab. Search for other available quests in the Cloud Skills Boost catalog.
End your lab
When you have completed your lab, click End Lab. Qwiklabs removes the resources you’ve used and cleans the account for you.
You will be given an opportunity to rate the lab experience. Select the applicable number of stars, type a comment, and then click Submit.
The number of stars indicates the following:
- 1 star = Very dissatisfied
- 2 stars = Dissatisfied
- 3 stars = Neutral
- 4 stars = Satisfied
- 5 stars = Very satisfied
You can close the dialog box if you don't want to provide feedback.
For feedback, suggestions, or corrections, please use the Support tab.
Copyright 2022 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.