Exercise: Assess query performance using Query Store
Important
You need your own Azure subscription to complete the exercises in this module. If you don't have an Azure subscription, you can set up a free trial account at Build in the cloud with an Azure free account.
Create the exercise environment
Before you start
- You have installed and started Azure Database for PostgreSQL flexible server.
- You have installed Azure Data Studio.
- Download the lab scripts from PostgreSQL Labs.
- Download and install pgAdmin 4 from Download
- Open Azure Data Studio and connect to your Azure Database for PostgreSQL flexible server.
Restore AdventureWorks database
Start pgAdmin and enter the password that you specified during installation.
Right-click Servers, select Register, and select Server.
In Name, type PostgreSQL Exercise 10 and select the Connection tab.
In Host name/address, type the value that you specified when you deployed the server.
In Username, type demo.
In Password, type Pa$$w0rd.
Select Save password.
Select Save.
Expand PostgreSQL Exercise, right-click Databases, select Create, and select Database.
In Database, type adventureworks and select Save.
Right-click adventureworks and select Restore.
In Filename, type the path location that you specified when you downloaded the lab scripts plus \AdventureWorksPG.gz.
In Number of jobs, type 1.
In Role name, select demo.
Select Restore.
Wait until the restore process completes.
You can disregard any errors that occur because those objects are not required for these modules.
Task 1: Turn on query capture mode
Navigate to the Azure portal and sign in.
Select your Azure Database for PostgreSQL server for this exercise.
In Settings, select Server parameters.
Navigate to the pg_qs.query_capture_mode setting.
Select TOP.
Navigate to p g m s_wait_sampling.query_capture_mode, select ALL, and select Save.
Wait for the server parameters to update.
View pg_stat data
Start Azure Data Studio.
Select Connect.
Select your PostgreSQL server and select Connect.
Type each of the following query and select Run.
SELECT * FROM pg_stat_activity;
Review the metrics that are available.
Leave Azure Data Studio open for the next task.
Task 2: Examine query statistics
Note
For a newly created database, there might be limited statistics, if any. If you wait for 30 minutes there will be statistics from background processes.
Select the azure_sys database.
Type each of the following queries and select Run.
SELECT * FROM query_store.query_texts_view;
SELECT * FROM query_store.qs_view;
SELECT * FROM query_store.runtime_stats_view;
SELECT * FROM query_store.pgms_wait_sampling_view;
Review the metrics that are available.
Task 3: Delete the PostgreSQL server
When you have completed all of the exercises, you can delete the Azure Database for PostgreSQL with the following steps:
- In Azure Data Studio, on your Azure Database for PostgreSQL page, select Overview.
- Select Delete.
- Select Skip feedback.
- Type the server name.
- Select Delete.