![](https://cdn.qwiklabs.com/assets/labs/start_lab-f45aca49782d4033c3ff688160387ac98c66941d.png)
Before you begin
- Labs create a Google Cloud project and resources for a fixed time
- Labs have a time limit and no pause feature. If you end the lab, you'll have to restart from the beginning.
- On the top left of your screen, click Start lab to begin
Enable the pgaudit extension
/ 40
Create a read pool instance
/ 30
Create a backup
/ 30
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.
In this lab, you perform administrative tasks that are essential to the optimal use of an AlloyDB for PostgreSQL database.
In this lab, you learn how to perform the following tasks:
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:
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:
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.
If necessary, copy the Username below and paste it into the Sign in dialog.
You can also find the Username in the Lab Details panel.
Click Next.
Copy the Password below and paste it into the Welcome dialog.
You can also find the Password in the Lab Details panel.
Click Next.
Click through the subsequent pages:
After a few moments, the Google Cloud console opens in this tab.
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.
When you are connected, you are already authenticated, and the project is set to your Project_ID,
gcloud
is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.
Output:
Output:
gcloud
, in Google Cloud, refer to the gcloud CLI overview guide.
An AlloyDB cluster and instance were provisioned when you started the lab. On the Cloud Console Navigation menu (), click VIEW ALL PRODUCTS. In Databases section click AlloyDB 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.
The instance was also configured with the enable_pgaudit database flag already set. Pgaudit is a popular feature of PostgreSQL that provides detailed session and object audit logging via the standard logging facility. To fully enable pgaudit you must also enable the corresponding database extension which you will do in the next section.
In the Instances in your cluster section, select the lab-instance, and then click Edit Primary.
To add a database flag to your instance, expand Advanced Configuration Options and click on Add a Database Flag.
Browse the list of avaiable flags (inside Choose a flag) to get a sense of the supported options. You will not add an additional flag as part of this lab.
Click Cancel twice to exit the Edit Primary instance screen.
Continuing from the previous you will setup a database extension to fully enable the pgaudit feature for your AlloyDB cluster.
Unlike configuring a flag, you must connect to your instance via the psql client to enable a database extension.
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.
Type \q to exit the psql client.
Type exit to close the terminal window.
Click Check my progress to verify the objective.
You are not required to have any read pool instances in a cluster, but they provide better support for data analytics workloads than do primary instances. Therefore they are the best choice for your data analytics needs.
To add a read pool instance click Add Read Pool or Add Read Pool Instance in the Instances in your cluster section of the Overview page for your cluster.
For Read pool instance ID input lab-instance-rp1. Set the Node count to 2.
Select 2 vCPU, 16 GB as your machine type.
Click Create Read Pool.
Read pool instance creation will take approximately 8 to 11 minutes.
Your read pool instance now appears on the Overview page. Notice the Private IP is in the same pool of addresses as the Primary Instance. The direct IP address allows you to funnel read-specific queries to the read pool, thereby enhancing overall cluster performance.
Click Check my progress to verify the objective.
Automatic backups are configured by default when every AlloyDB cluster is created. You can however create backups as needed, on-demand for additional recovery options based on workload requirements.
On the Cloud Console Navigation menu (), click on VIEW ALL PRODUCTS and under Databases click AlloyDB then Backups to launch the Backups page.
Your instance was too recently created to have any automatic backups so you will proceed with creating an on-demand backup. Click Create backup.
Ensure lab-cluster is selected as the source for the backup.
Enter a unique ID for the backup. In this case enter lab-backup.
Click Create.
AlloyDB checks that the source cluster is in the Ready state and then starts a long-running operation to perform the backup. The Backups page shows the backup with a status of In progress until the operation finshes. The speed varies based on the size of the instance but in the lab environment the backup should be created quickly -- within 1 minute.
Recovery of a backup is very simple. Click the Restore link at the end of the backup row. Inspect the information for the backup and the proposed target for recovery. For this lab you will not restore the backup you just created. Click Cancel to close the wizard.
Click Check my progress to verify the objective.
The AlloyDB Monitoring dashboard contains a great deal of information about the usage, size, and performance of the clusters and instances. The dashboard displays metrics of the resources that you use and lets you monitor any trends that result.
From the Cluster Overview select the Monitoring link on the left side of the page.
Very little activity has occurred on the lab-instance so the metrics displayed at the moment will not offer much insight. You will utilize the Postgres tool pgbench to generate a synthetic dataset and run a simulated workload to place the lab-instance under a representative burden.
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 ALLOYDB environment variable by running the following command.
The largest table pgbench_accounts will be loaded with 5 million rows. The operation should be very brief.
Type \q to exit the psql client.
Run the following pgbench operation to simulate a workload against lab-instance. The operation corresponds to a load of fifty (50) clients, across two (2) threads, polling every thirty (30) seconds, over the course of three (3) minutes. You will be prompted for the postgres user's password which is Change3Me.
Return to the AlloyDB Monitoring dashboard and set the time horizon to 1 hour. In the tiles below you will see details on Mean CPU utilization, Minimum available memory, Connections, Transactions per second, Cluster storage, Maximum replication lag, and Active nodes.
Click the Query insights link on the left for details on the queries that the pgbench operation issued against the instance.
Under Top Queries and Tags, you will see an ordering of queries. In the image below the query UPDATE pgbench_branches SET ... was the top query by Load by total time. Your results may vary.
The Load by total time column has a selector option. You may also view the queries by Load by CPU, Load by IO wait, and Load by lock wait.
Feel free to explore queries in detail by clicking on any of the values in the Query column in the Top Queries and Tags section or links in other areas of the dashboard.
You have now performed administrative tasks that are essential to the optimal use of an AlloyDB for PostgreSQL database.
Manual Last Updated August 28, 2024
Lab Last Tested August 28, 2024
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.
This content is not currently available
We will notify you via email when it becomes available
Great!
We will contact you via email if it becomes available
One lab at a time
Confirm to end all existing labs and start this one