Checkpoints
Enable the pgaudit extension
/ 40
Create a read pool instance
/ 30
Create a backup
/ 30
Administering an AlloyDB Database
GSP1086
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.
In this lab, you perform administrative tasks that are essential to the optimal use of an AlloyDB for PostgreSQL database.
What you'll do
In this lab, you learn how to perform the following tasks:
- Examine a Database Flag
- Setup a Database Extension
- Create a Read Pool Instance for an Existing Cluster
- Setup Backups
- Examine Monitoring in the AlloyDB Console
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).
- Time to complete the lab---remember, once you start, you cannot pause a lab.
How to start your lab and sign in to the Google Cloud console
-
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
-
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. -
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.
-
Click Next.
-
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.
-
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. -
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.
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.
- Click Activate Cloud Shell 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,
gcloud
is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.
- (Optional) You can list the active account name with this command:
- Click Authorize.
Output:
- (Optional) You can list the project ID with this command:
Output:
gcloud
, in Google Cloud, refer to the gcloud CLI overview guide.
Task 1. Examine a Database Flag
-
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.
Task 2. Setup a Database Extension
-
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.
- 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.
- Use the following command to launch the PostgreSQL (psql) client. You will be prompted to provide the postgres user's password (Change3Me) which you entered when you created the cluster.
- You will be presented the psql terminal prompt as shown below.
- Input and run the following SQL commands separately to enable the extension.
- Run the following system query to see details on the pgaudit extension.
-
Type \q to exit the psql client.
-
Type exit to close the terminal window.
-
Click Check my progress to verify the objective.
Task 3. Create a Read Pool Instance for an Existing Cluster
- One key feature of AlloyDB for PostgreSQL is the implementation of read pool instances. A read pool instance increases your cluster’s read capacity by aggregating nodes, which you can scale, enabling highly available reads.
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.
Task 4. Setup Backups
-
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.
- In the Cloud Shell, run the command below to see more details on your backup.
-
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.
Task 5. Examine Monitoring in the AlloyDB Console
-
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 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 5 million rows. The operation should be very brief.
- 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.
-
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.
- The workload operation will complete and report statistics for the run. The details will appear similar to the following:
-
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.
Congratulations!
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.