Skip to content

Commit 66833aa

Browse files
Merge pull request #286 from oracle-devrel/Ulrikests-assets
Ulrikests assets
2 parents 7a1d247 + d6765f2 commit 66833aa

12 files changed

+173
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# SQL Tuning Sets
2+
3+
A SQL Tuning Set (aka STS) is a database object that you can use as input to tuning tools. An STS includes SQL statements, associated execution context, associated basic execution statistics, and associated execution plans. It enables you to group SQL statements and related metadata in a single database object, which you can use to meet your tuning goals.
4+
STS can be generated from various sources such as Automatic Workload Repository (AWR), Cursor Cache or Real Application Testing Database Replay.
5+
6+
## Useful Links
7+
8+
### Documentation
9+
10+
- [PL/SQL Package DBMS_SQLTUNE 19c](https://docs.oracle.com/en/database/oracle/oracle-database/19/arpls/DBMS_SQLTUNE.html#GUID-821462BF-1695-41CF-AFF7-FD23E9999C6A)
11+
- [SQL Tuning Gudide 19c](https://docs.oracle.com/en/database/oracle/oracle-database/19/tgsql/managing-sql-tuning-sets.html#GUID-91D1B886-A6D7-40B8-93D5-112B8C6E6AFE)
12+
- [Database Reference 19c ALL_SQLSET](https://docs.oracle.com/en/database/oracle/oracle-database/19/refrn/ALL_SQLSET.html#GUID-7F8980B0-1B5F-4E0E-A79D-CA6B7FD23D8E)
13+
- [Database Reference 19c ALL_SQLSET_STATEMENTS](https://docs.oracle.com/en/database/oracle/oracle-database/19/refrn/ALL_SQLSET_STATEMENTS.html#GUID-1EE16029-9312-4280-B7BD-396B84652FFE)
14+
15+
### Team Publications
16+
17+
- [Oracle SQL Tuning Sets (STS) - The foundation for SQL Tuning](https://blogs.oracle.com/coretec/post/oracle-sql-tuning-sets-the-basis-for-sql-tuning)
18+
19+
20+
### Blogs
21+
22+
- [What is the Automatic SQL Tuning Set?](https://blogs.oracle.com/optimizer/post/what-is-the-automatic-sql-tuning-set)
23+
- [Introducing Oracle Database 23c Free – Developer Release](https://blogs.oracle.com/database/post/oracle-database-23c-free)
24+
25+
### Videos
26+
27+
- [Capture workload information with SQL Tuning Set](https://www.youtube.com/watch?v=V4VlGNPI62g)
28+
- [Creating SQL Tuning Sets](https://www.youtube.com/watch?v=f3f182gxODY)
29+
30+
31+
# License
32+
33+
Copyright (c) 2023 Oracle and/or its affiliates.
34+
35+
Licensed under the Universal Permi
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
REM Script: 1-transport-sts-from-source.sql
2+
REM Create a staging table and add the statements to it (source system)
3+
4+
-- don't use SYS user for this
5+
-- Use CREATE_STGTAB_SQLSET to create the staging table
6+
7+
execute dbms_sqltune.create_stgtab_sqlset(table_name => '&tablename', schema_name => '&owner');
8+
9+
-- Load the staging table with data from one or more STS with PACK_STGTAB_SQLSET
10+
11+
execute dbms_sqltune.pack_stgtab_sqlset(sqlset_name => '&stsname', -
12+
  sqlset_owner => '&owner', -
13+
  staging_table_name => '&stagingtab_name',-
14+
  staging_schema_owner=> '&stagingtab_owner');
15+
16+
17+
-- use datapump to export the staging table and import it to the target system
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
REM Script: 2-transport-sts-to-target.sql
2+
REM on the the source system create a staging table and add the statements to it
3+
4+
-- first import the staging table
5+
-- copy the SQL tuning sets from the staging table into the database
6+
7+
execute dbms_sqltune.unpack_stgtab_sqlset(sqlset_name => '&stsname', -
8+
  sqlset_owner => '&owner', -
9+
        replace => TRUE, -
10+
  staging_schema_owner=>'&stagingtab_owner',-
11+
  staging_table_name => '&stagingtab_name');
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# scripts-for-sts
2+
This folder provides useful SQL scripts for SQL Tuning Sets. You may change and edit them accordingly.
3+
4+
## scripts
5+
You must have the ADMINISTER SQL TUNING SET system privilege to manage SQL tuning sets that you own, or the ADMINISTER ANY SQL TUNING SET system privilege to manage any SQL tuning sets.
6+
7+
- create_sts.sql: Create a new SQL Tuning Set
8+
- drop-sts.sql: Drop an existing SQL Tuning Set
9+
- create-sts-from-cursorcache.sql: Load STS from Cursor Cache
10+
- list_snapshots.sql: Helper script to list and find the required begin and end snap id
11+
- create-sts-from-awr.sql: Load STS from AWR
12+
- reduce-sts.sql: Reduce and existing STS
13+
- check-sts-information.sql: Monitor STS
14+
- check-sts-statements.sql: Monitor STS with statement execution
15+
- 1-transport-sts-from-source.sql: Tasks on the source system to transport STS
16+
- 2-transport-sts-to-target.sql: Tasks on the remote system to transport STS
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
REM Script: check-sts-information.sql
2+
REM Use view ALL_SQLSET
3+
4+
-- check all sts
5+
6+
col name format a20
7+
col owner format a20
8+
9+
select name, owner, created, statement_count
10+
from all_sqlset
11+
where owner= '&owner';
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
REM Script: check-sts-statements.sql
2+
REM Use view ALL_SQLSET_STATEMENTS
3+
4+
-- check the tuning set, enter name and owner
5+
6+
select executions, cpu_time/1000 cpu_in_ms, elapsed_time/1000 elapsed_in_ms, sql_id, substr(sql_text,1,80)
7+
from all_sqlset_statements
8+
where sqlset_name='&name' and owner='&owner'
9+
order by 3 desc;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
REM Script: create-sts-from-awr.sql
2+
REM Load STS from AWR with SELECT_WORKLOAD_REPOSITORY and LOAD_SQLSET
3+
4+
-- first create a STS with create-sts.sql
5+
-- find snap ids with list-snapshots.sql
6+
-- load statements in the SQL Tuning Set and enter two snap ids
7+
8+
DECLARE
9+
cur dbms_sqltune.sqlset_cursor;
10+
BEGIN
11+
OPEN cur FOR
12+
SELECT VALUE(P)
13+
FROM dbms_sqltune.select_workload_repository(begin_snap=>&startid, end_snap=>&endid) P;
14+
dbms_sqltune.load_sqlset (sqlset_name => '&name', sqlset_owner=>'&schema', populate_cursor => cur);
15+
END;
16+
/
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
REM Script: create-sts-from-cursorcache.sql
2+
REM Load statements from cursor cache with SELECT_CURSOR_CACHE and LOAD_SQLSET
3+
4+
-- first create STS with create-sts.sql
5+
6+
-- enter filter criteria for parsing schema and sql text
7+
8+
DECLARE
9+
cur dbms_sqltune.SQLSET_CURSOR;
10+
BEGIN
11+
OPEN cur FOR
12+
SELECT VALUE(P)
13+
FROM dbms_sqltune.select_cursor_cache(basic_filter =>
14+
'parsing_schema_name = ''&schema'' and upper(sql_text) like ''SELECT%''') P;
15+
dbms_sqltune.load_sqlset(sqlset_name => '&stsname', sqlset_owner=>'&owner', populate_cursor => cur);
16+
CLOSE cur;
17+
END;
18+
/
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
REM Script: create-sts.sql
2+
REM Create a new SQL Tuning Set with DBMS_SQLTUNE.CREATE_SQLSET
3+
4+
execute dbms_sqltune.create_sqlset(sqlset_name=>'&stsname', sqlset_owner=>'&owner');
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
REM Script: drop-sts.sql
2+
REM Drop an existing SQL Tuning Set with DBMS_SQLTUNE.DROP_SQLSET
3+
4+
-- check sts first with check-sts-information.sql
5+
-- drop sts
6+
execute dbms_sqltune.drop_sqlset(sqlset_name=>'&stsname', sqlset_owner=>'&owner');

0 commit comments

Comments
 (0)