arrow_back

Accelerating Analytical Queries using the AlloyDB Columnar Engine

Anmelden Teilnehmen
Testen und teilen Sie Ihr Wissen mit unserer Community.
done
Sie erhalten Zugriff auf über 700 praxisorientierte Labs, Skill-Logos und Kurse

Accelerating Analytical Queries using the AlloyDB Columnar Engine

Lab 1 Stunde 30 Minuten universal_currency_alt 1 Guthabenpunkt show_chart Einsteiger
info Dieses Lab kann KI-Tools enthalten, die den Lernprozess unterstützen.
Testen und teilen Sie Ihr Wissen mit unserer Community.
done
Sie erhalten Zugriff auf über 700 praxisorientierte Labs, Skill-Logos und Kurse

GSP1087

Google Cloud self-paced labs logo

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 explore features of the AlloyDB Columnar Engine.

What you'll do

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

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.

To complete this lab, you need:

  • Access to a standard internet browser (Chrome browser recommended).
Note: Use an Incognito or private browser window to run this lab. This prevents any conflicts between your personal account and the Student account, which may cause extra charges incurred to your personal account.
  • Time to complete the lab---remember, once you start, you cannot pause a lab.
Note: If you already have your own personal Google Cloud account or project, do not use it for this lab to avoid extra charges to your account.

How to start your lab and sign in to the Google Cloud console

  1. Click the Start Lab button. If you need to pay for the lab, a pop-up opens for you to select your payment method. On the left is the Lab Details panel with the following:

    • The Open Google Cloud console button
    • Time remaining
    • The temporary credentials that you must use for this lab
    • Other information, if needed, to step through this lab
  2. Click Open Google Cloud console (or right-click and select Open Link in Incognito Window if you are running the Chrome browser).

    The lab spins up resources, and then opens another tab that shows the Sign in page.

    Tip: Arrange the tabs in separate windows, side-by-side.

    Note: If you see the Choose an account dialog, click Use Another Account.
  3. If necessary, copy the Username below and paste it into the Sign in dialog.

    {{{user_0.username | "Username"}}}

    You can also find the Username in the Lab Details panel.

  4. Click Next.

  5. Copy the Password below and paste it into the Welcome dialog.

    {{{user_0.password | "Password"}}}

    You can also find the Password in the Lab Details panel.

  6. Click Next.

    Important: You must use the credentials the lab provides you. Do not use your Google Cloud account credentials. Note: Using your own Google Cloud account for this lab may incur extra charges.
  7. Click through the subsequent pages:

    • Accept the terms and conditions.
    • Do not add recovery options or two-factor authentication (because this is a temporary account).
    • Do not sign up for free trials.

After a few moments, the Google Cloud console opens in this tab.

Note: To view a menu with a list of Google Cloud products and services, click the Navigation menu at the top-left. Navigation menu icon

Activate Cloud Shell

Cloud Shell is a virtual machine that is loaded with development tools. It offers a persistent 5GB home directory and runs on the Google Cloud. Cloud Shell provides command-line access to your Google Cloud resources.

  1. Click Activate Cloud Shell Activate Cloud Shell icon at the top of the Google Cloud console.

When you are connected, you are already authenticated, and the project is set to your Project_ID, . The output contains a line that declares the Project_ID for this session:

Your Cloud Platform project in this session is set to {{{project_0.project_id | "PROJECT_ID"}}}

gcloud is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.

  1. (Optional) You can list the active account name with this command:
gcloud auth list
  1. Click Authorize.

Output:

ACTIVE: * ACCOUNT: {{{user_0.username | "ACCOUNT"}}} To set the active account, run: $ gcloud config set account `ACCOUNT`
  1. (Optional) You can list the project ID with this command:
gcloud config list project

Output:

[core] project = {{{project_0.project_id | "PROJECT_ID"}}} Note: For full documentation of gcloud, in Google Cloud, refer to the gcloud CLI overview guide.

Task 1. Create Baseline Dataset for Testing the Columnar Engine

In this lab environment, an AlloyDB cluster and instance are provisioned when you start the lab.

  1. In the Google Cloud Console, click on the Navigation menu (Navigation menu icon) > View all products. Then, under Databases, select AlloyDB.

On the AlloyDB page, there is a cluster named lab-cluster and an instance named lab-instance. The instance takes a few minutes to be fully created and initialized.

Please wait until you see a green checkmark (status of Ready) beside the instance named lab-instance in the Resource name column before you proceed to the next step.

  1. On the row for the instance named lab-instance, under Private IP address, copy the Private IP address (such as 10.100.0.2) to a text file so that you can paste the value in a later step. Do not include the colon and port number (:5432).

To evaluate the capabilities of the Columnar Engine, you need a dataset of significant size against which to measure performance. In the next steps, you utilize the PostgreSQL tool pgbench to generate a synthetic dataset to evaluate the Columnar Engine.

  1. From the Navigation menu (Navigation menu icon), under Compute Engine, click VM instances.

  2. For the instance named alloydb-client, in the Connect column, click SSH to open a terminal window.

  3. Set the following environment variable, replacing ALLOYDB_ADDRESS with the Private IP address of the AlloyDB instance.

export ALLOYDB=ALLOYDB_ADDRESS
  1. 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.
echo $ALLOYDB > alloydbip.txt
  1. 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 takes a few minutes to complete.

pgbench -h $ALLOYDB -U postgres -i -s 500 -F 90 -n postgres dropping old tables... NOTICE: table "pgbench_accounts" does not exist, skipping NOTICE: table "pgbench_branches" does not exist, skipping NOTICE: table "pgbench_history" does not exist, skipping NOTICE: table "pgbench_tellers" does not exist, skipping creating tables... generating data (client-side)... 50000000 of 50000000 tuples (100%) done (elapsed 91.26 s, remaining 0.00 s) creating primary keys... done in 167.61 s (drop tables 0.00 s, create tables 0.01 s, client-side generate 93.16 s, primary keys 74.43 s).
  1. 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.
psql -h $ALLOYDB -U postgres select count (*) from pgbench_accounts; count ---------- 50000000 (1 row)

Click Check my progress to verify the objective. Create a baseline data set

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.

  1. 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.
\timing on
  1. 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.

SELECT aid, bid, abalance FROM pgbench_accounts WHERE bid < 189 OR abalance > 100 LIMIT 20; aid | bid | abalance -----+-----+---------- 1 | 1 | 0 2 | 1 | 0 3 | 1 | 0 4 | 1 | 0 5 | 1 | 0 6 | 1 | 0 7 | 1 | 0 8 | 1 | 0 9 | 1 | 0 10 | 1 | 0 11 | 1 | 0 12 | 1 | 0 13 | 1 | 0 14 | 1 | 0 15 | 1 | 0 16 | 1 | 0 17 | 1 | 0 18 | 1 | 0 19 | 1 | 0 20 | 1 | 0 (20 rows)
  1. 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.
Note: You may have to press the spacebar to advance through the query explain plan. EXPLAIN (ANALYZE,COSTS,SETTINGS,BUFFERS,TIMING,SUMMARY,WAL,VERBOSE) SELECT count(*) FROM pgbench_accounts WHERE bid < 189 OR abalance > 100; QUERY PLAN --------------------------------------------------------------------------------------------------------------- --------------------------------------------------- Finalize Aggregate (cost=1242226.53..1242226.54 rows=1 width=8) (actual time=11010.409..11014.083 rows=1 loop s=1) Output: count(*) Buffers: shared hit=20921 read=888170 I/O Timings: read=19536.769 -> Gather (cost=1242226.32..1242226.53 rows=2 width=8) (actual time=11010.398..11014.075 rows=3 loops=1) Output: (PARTIAL count(*)) Workers Planned: 2 Workers Launched: 2 Buffers: shared hit=20921 read=888170 I/O Timings: read=19536.769 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !! Section removed for pasting !! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Filter: ((pgbench_accounts.bid < 189) OR (pgbench_accounts.abalance > 100)) Rows Removed by Filter: 10400000 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !! Section removed for pasting !! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Buffers: shared hit=6 Planning Time: 0.117 ms Execution Time: 11014.169 ms (38 rows)
  1. 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.

  2. 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.

  3. Press the Q key to close the query plan.

Task 3. Verify the Database Flag for the Columnar Engine

In this task, you examine the Columnar Engine database flag in your instance.

  1. In the Google Cloud Console, click on the Navigation menu (Navigation menu icon) > View all products. Then, under Databases, select AlloyDB.

  2. On the row for the instance named lab-instance, click on Actions (icon with three vertical dots), and then click Edit.

  3. Expand the section named Advanced Configuration Options.

  4. Under Flags, click Add a database flag.

  5. Click Choose a flag to browse the list of available flags to get a sense of the supported options.

Notice that the flag named google_columnar_engine.enabled is already enabled (status of on). You will not add an additional flag as part of this lab.

  1. Click Cancel to exit the Edit instance page.

Task 4. Set or Verify a Database Extension for the Columnar Engine

Continuing from the previous section, in this task, you set up 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.

  1. Return to the alloydb-client shell. The psql client should still be active. If not, reconnect using the instructions in Task 1.

  2. Ensure that you are connected to the postgres database by running the following query.

\c postgres
  1. Run the following system query to see details on the extensions enabled in the database.
Note: Your list of extensions may vary. \dx List of installed extensions Name | Version | Schema | Description ------------------------+---------+------------+--------------------------------------- google_columnar_engine | 1.0 | public | Google extension for columnar engine google_db_advisor | 1.0 | public | Google extension for Database Advisor hypopg | 1.3.2 | public | Hypothetical indexes for PostgreSQL plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language (4 rows)
  1. 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.
CREATE EXTENSION IF NOT EXISTS google_columnar_engine;
  1. Run the extension query again to confirm that the google_columnar_engine extension is enabled.
\dx

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.

  1. Return to the alloydb-client shell. Run the following query to add pgbench_accounts to the columnar engine. The query takes a few minutes to complete.
SELECT google_columnar_engine_add('pgbench_accounts');
  1. Next run the same explain plan query you did earlier to see the effects 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.
EXPLAIN (ANALYZE,COSTS,SETTINGS,BUFFERS,TIMING,SUMMARY,WAL,VERBOSE) SELECT count(*) FROM pgbench_accounts WHERE bid < 189 OR abalance > 100; QUERY PLAN ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Finalize Aggregate (cost=142400.72..142400.73 rows=1 width=8) (actual time=75.948..78.680 rows=1 loops=1) Output: count(*) -> Gather (cost=142400.51..142400.72 rows=2 width=8) (actual time=71.555..78.667 rows=3 loops=1) Output: (PARTIAL count(*)) Workers Planned: 2 Workers Launched: 2 -> Partial Aggregate (cost=141400.51..141400.52 rows=1 width=8) (actual time=45.768..45.771 rows=1 loops=3) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Section removed for pasting ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Rows Removed by Columnar Filter: 10400000 Rows Aggregated by Columnar Scan: 4505600 Columnar cache search mode: native ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Section removed for pasting ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Buffers: shared hit=22 read=3 dirtied=1 I/O Timings: read=0.560 Planning Time: 2.022 ms Execution Time: 78.804 ms (29 rows)
  1. 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.

  2. 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. Testing the Columnar Engine

Note: If after completing all tasks and your scoring does not fully update, expand the scoring Checkpoints box (the yellow side bar on the right side of the page), and click Check my progress for each task for the scoring to update.

Congratulations!

You have now explored powerful features of the AlloyDB Columnar Engine.

Google Cloud training and certification

...helps you make the most of Google Cloud technologies. Our classes include technical skills and best practices to help you get up to speed quickly and continue your learning journey. We offer fundamental to advanced level training, with on-demand, live, and virtual options to suit your busy schedule. Certifications help you validate and prove your skill and expertise in Google Cloud technologies.

Manual Last Updated October 28, 2024

Lab Last Tested August 9, 2023

Copyright 2024 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.

Diese Inhalte sind derzeit nicht verfügbar

Bei Verfügbarkeit des Labs benachrichtigen wir Sie per E-Mail

Sehr gut!

Bei Verfügbarkeit kontaktieren wir Sie per E-Mail