59
Creating My Own PL/SQL Performance Monitoring Tool using PL/SQL and APEX Why do DBA’s get all the cool tools? Gary J. Propeck, Ph.D. 2/15/2018 RMOUG Training Days 2018 1

Creating My Own PL/SQL Performance Monitoring Package ... · Creating My Own PL/SQL Performance Monitoring Tool using PL/SQL and APEX Why do DBA’s get all the cool tools? Gary J

  • Upload
    others

  • View
    27

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Creating My Own PL/SQL Performance Monitoring Package ... · Creating My Own PL/SQL Performance Monitoring Tool using PL/SQL and APEX Why do DBA’s get all the cool tools? Gary J

Creating My Own PL/SQL

Performance Monitoring Tool

using PL/SQL and APEXWhy do DBA’s get all the cool tools?

Gary J. Propeck, Ph.D.

2/15/2018RMOUG Training Days 2018

1

Page 2: Creating My Own PL/SQL Performance Monitoring Package ... · Creating My Own PL/SQL Performance Monitoring Tool using PL/SQL and APEX Why do DBA’s get all the cool tools? Gary J

Objectives

Develop an Application around the PL/SQL Profiler (DBMS_PROFILER)

Monitor PL/SQL Profiler Data Collection

Create Baselines and Thresholds

Report Threshold Violations during PL/SQL execution.

Use only Oracle-supplied tools

SQL Developer (17.2.0)

Application Express (APEX 5.1.3)

Oracle RDBMS 12.1.0.2

SQL*Plus

2/15/2018RMOUG Training Days 2018

2

Page 3: Creating My Own PL/SQL Performance Monitoring Package ... · Creating My Own PL/SQL Performance Monitoring Tool using PL/SQL and APEX Why do DBA’s get all the cool tools? Gary J

Objectives

Demonstrate PL/SQL Programming Techniques

Anonymous Blocks

Named Procedures

Named Functions

Packages

Package Body

Package Specification

Triggers

2/15/2018RMOUG Training Days 2018

3

Page 4: Creating My Own PL/SQL Performance Monitoring Package ... · Creating My Own PL/SQL Performance Monitoring Tool using PL/SQL and APEX Why do DBA’s get all the cool tools? Gary J

Objectives

Use PL/SQL “Encapsulation”.

No Privileges for Select, Insert, Update, or Delete granted on tables.

Data Entered and Manipulated via:

PL/SQL

APEX

Create Package to invoke PL/SQL Profiler (DBMS_PROFILER).

2/15/2018RMOUG Training Days 2018

4

Page 5: Creating My Own PL/SQL Performance Monitoring Package ... · Creating My Own PL/SQL Performance Monitoring Tool using PL/SQL and APEX Why do DBA’s get all the cool tools? Gary J

MOTIVATIONWhy do this?

2/15/2018RMOUG Training Days 2018

5

Page 6: Creating My Own PL/SQL Performance Monitoring Package ... · Creating My Own PL/SQL Performance Monitoring Tool using PL/SQL and APEX Why do DBA’s get all the cool tools? Gary J

Motivating Factors

Unemployment?

Business?

Retirement?

2/15/2018RMOUG Training Days 2018

6

Page 7: Creating My Own PL/SQL Performance Monitoring Package ... · Creating My Own PL/SQL Performance Monitoring Tool using PL/SQL and APEX Why do DBA’s get all the cool tools? Gary J

Why do DBA’s get all the cool Oracle

tools?

Oracle Enterprise Manager (OEM)

AWR

ADDM

ASH

Metrics and Baselines

2/15/2018RMOUG Training Days 2018

7

Page 8: Creating My Own PL/SQL Performance Monitoring Package ... · Creating My Own PL/SQL Performance Monitoring Tool using PL/SQL and APEX Why do DBA’s get all the cool tools? Gary J

But…

Why?

2/15/2018RMOUG Training Days 2018

8

Page 9: Creating My Own PL/SQL Performance Monitoring Package ... · Creating My Own PL/SQL Performance Monitoring Tool using PL/SQL and APEX Why do DBA’s get all the cool tools? Gary J

Install the PL/SQL Profiler

2/15/2018RMOUG Training Days 2018

9

Page 10: Creating My Own PL/SQL Performance Monitoring Package ... · Creating My Own PL/SQL Performance Monitoring Tool using PL/SQL and APEX Why do DBA’s get all the cool tools? Gary J

Install the PL/SQL Profiler

$ORACLE_HOME\rdbms\admin

proftab.sql

PLSQL_PROFILER_RUNS

PLSQL_PROFILER_DATA

PLSQL_PROFILER_UNITS

profload.sql

DBMS_PROFILER

2/15/2018RMOUG Training Days 2018

10

Page 11: Creating My Own PL/SQL Performance Monitoring Package ... · Creating My Own PL/SQL Performance Monitoring Tool using PL/SQL and APEX Why do DBA’s get all the cool tools? Gary J

PLSQL_PROFILER_RUNSInstalled into user schema

2/15/2018RMOUG Training Days 2018

11

Page 12: Creating My Own PL/SQL Performance Monitoring Package ... · Creating My Own PL/SQL Performance Monitoring Tool using PL/SQL and APEX Why do DBA’s get all the cool tools? Gary J

PLSQL_PROFILER_DATAInstalled in user schema

2/15/2018RMOUG Training Days 2018

12

Page 13: Creating My Own PL/SQL Performance Monitoring Package ... · Creating My Own PL/SQL Performance Monitoring Tool using PL/SQL and APEX Why do DBA’s get all the cool tools? Gary J

PLSQL_PROFILER_DATAInstalled in user schema

2/15/2018RMOUG Training Days 2018

13

Page 14: Creating My Own PL/SQL Performance Monitoring Package ... · Creating My Own PL/SQL Performance Monitoring Tool using PL/SQL and APEX Why do DBA’s get all the cool tools? Gary J

DBMS_PROFILERRUN AS SYSDBA

2/15/2018RMOUG Training Days 2018

14

Page 15: Creating My Own PL/SQL Performance Monitoring Package ... · Creating My Own PL/SQL Performance Monitoring Tool using PL/SQL and APEX Why do DBA’s get all the cool tools? Gary J

Create Procedures to invoke and

stop PL/SQL Profiler

2/15/2018RMOUG Training Days 2018

15

Page 16: Creating My Own PL/SQL Performance Monitoring Package ... · Creating My Own PL/SQL Performance Monitoring Tool using PL/SQL and APEX Why do DBA’s get all the cool tools? Gary J

Create Procedures and Functions for

Starting and Stopping the PL/SQL Profiler

start_profiler_proc1.pls

start_profiler_proc2.pls

start_profiler_func1.pls

start_profiler_func2.pls

2/15/2018RMOUG Training Days 2018

16

Page 17: Creating My Own PL/SQL Performance Monitoring Package ... · Creating My Own PL/SQL Performance Monitoring Tool using PL/SQL and APEX Why do DBA’s get all the cool tools? Gary J

Start_profiler_proc2.pls

2/15/2018RMOUG Training Days 2018

17

Page 18: Creating My Own PL/SQL Performance Monitoring Package ... · Creating My Own PL/SQL Performance Monitoring Tool using PL/SQL and APEX Why do DBA’s get all the cool tools? Gary J

2/15/2018RMOUG Training Days 2018

18

Page 19: Creating My Own PL/SQL Performance Monitoring Package ... · Creating My Own PL/SQL Performance Monitoring Tool using PL/SQL and APEX Why do DBA’s get all the cool tools? Gary J

Test using an Anonymous Block

2/15/2018RMOUG Training Days 2018

19

Page 20: Creating My Own PL/SQL Performance Monitoring Package ... · Creating My Own PL/SQL Performance Monitoring Tool using PL/SQL and APEX Why do DBA’s get all the cool tools? Gary J

The Anonymous Block

2/15/2018RMOUG Training Days 2018

20

Page 21: Creating My Own PL/SQL Performance Monitoring Package ... · Creating My Own PL/SQL Performance Monitoring Tool using PL/SQL and APEX Why do DBA’s get all the cool tools? Gary J

Capture The Anonymous Block

2/15/2018RMOUG Training Days 2018

21

Page 22: Creating My Own PL/SQL Performance Monitoring Package ... · Creating My Own PL/SQL Performance Monitoring Tool using PL/SQL and APEX Why do DBA’s get all the cool tools? Gary J

Results

2/15/2018RMOUG Training Days 2018

22

Page 23: Creating My Own PL/SQL Performance Monitoring Package ... · Creating My Own PL/SQL Performance Monitoring Tool using PL/SQL and APEX Why do DBA’s get all the cool tools? Gary J

Test using a Named Procedure

2/15/2018RMOUG Training Days 2018

23

Page 24: Creating My Own PL/SQL Performance Monitoring Package ... · Creating My Own PL/SQL Performance Monitoring Tool using PL/SQL and APEX Why do DBA’s get all the cool tools? Gary J

Compare the Anonymous Block to a

Named Procedure

2/15/2018RMOUG Training Days 2018

24

Page 25: Creating My Own PL/SQL Performance Monitoring Package ... · Creating My Own PL/SQL Performance Monitoring Tool using PL/SQL and APEX Why do DBA’s get all the cool tools? Gary J

Compare the Anonymous Block to a

Named Procedure

2/15/2018RMOUG Training Days 2018

25

Page 26: Creating My Own PL/SQL Performance Monitoring Package ... · Creating My Own PL/SQL Performance Monitoring Tool using PL/SQL and APEX Why do DBA’s get all the cool tools? Gary J

Does Flushing the Shared Pool change

Performance

2/15/2018RMOUG Training Days 2018

26

Page 27: Creating My Own PL/SQL Performance Monitoring Package ... · Creating My Own PL/SQL Performance Monitoring Tool using PL/SQL and APEX Why do DBA’s get all the cool tools? Gary J

Using DBMS_PROFILER to Demonstrate the Effectiveness of the Shared Pool

2/15/2018RMOUG Training Days 2018

27

Page 28: Creating My Own PL/SQL Performance Monitoring Package ... · Creating My Own PL/SQL Performance Monitoring Tool using PL/SQL and APEX Why do DBA’s get all the cool tools? Gary J

Display Data with APEX

2/15/2018RMOUG Training Days 2018

28

Page 29: Creating My Own PL/SQL Performance Monitoring Package ... · Creating My Own PL/SQL Performance Monitoring Tool using PL/SQL and APEX Why do DBA’s get all the cool tools? Gary J

Query for APEX Chart

2/15/2018RMOUG Training Days 2018

29

Page 30: Creating My Own PL/SQL Performance Monitoring Package ... · Creating My Own PL/SQL Performance Monitoring Tool using PL/SQL and APEX Why do DBA’s get all the cool tools? Gary J

APEX App Home Page

2/15/2018RMOUG Training Days 2018

30

Page 31: Creating My Own PL/SQL Performance Monitoring Package ... · Creating My Own PL/SQL Performance Monitoring Tool using PL/SQL and APEX Why do DBA’s get all the cool tools? Gary J

Chart of Execution - Flush Shared Pool

for Each Execution

2/15/2018RMOUG Training Days 2018

31

Page 32: Creating My Own PL/SQL Performance Monitoring Package ... · Creating My Own PL/SQL Performance Monitoring Tool using PL/SQL and APEX Why do DBA’s get all the cool tools? Gary J

Chart of Execution - Flush Shared Pool

for First Execution

2/15/2018RMOUG Training Days 2018

32

Page 33: Creating My Own PL/SQL Performance Monitoring Package ... · Creating My Own PL/SQL Performance Monitoring Tool using PL/SQL and APEX Why do DBA’s get all the cool tools? Gary J

Create a PL/SQL Package

2/15/2018RMOUG Training Days 2018

33

Page 34: Creating My Own PL/SQL Performance Monitoring Package ... · Creating My Own PL/SQL Performance Monitoring Tool using PL/SQL and APEX Why do DBA’s get all the cool tools? Gary J

Benefits of a PL/SQL Package

2/15/2018RMOUG Training Days 2018

34

Page 35: Creating My Own PL/SQL Performance Monitoring Package ... · Creating My Own PL/SQL Performance Monitoring Tool using PL/SQL and APEX Why do DBA’s get all the cool tools? Gary J

Package Specification

2/15/2018RMOUG Training Days 2018

35

Page 36: Creating My Own PL/SQL Performance Monitoring Package ... · Creating My Own PL/SQL Performance Monitoring Tool using PL/SQL and APEX Why do DBA’s get all the cool tools? Gary J

SQL Developer Code Snippets

2/15/2018RMOUG Training Days 2018

36

Page 37: Creating My Own PL/SQL Performance Monitoring Package ... · Creating My Own PL/SQL Performance Monitoring Tool using PL/SQL and APEX Why do DBA’s get all the cool tools? Gary J

Compare Explicit Cursor Fetch

SyntaxesBasic Fetch

Cursor For Loop

Bulk Collect

2/15/2018RMOUG Training Days 2018

37

Page 38: Creating My Own PL/SQL Performance Monitoring Package ... · Creating My Own PL/SQL Performance Monitoring Tool using PL/SQL and APEX Why do DBA’s get all the cool tools? Gary J

Basic Fetch

2/15/2018RMOUG Training Days 2018

38

Page 39: Creating My Own PL/SQL Performance Monitoring Package ... · Creating My Own PL/SQL Performance Monitoring Tool using PL/SQL and APEX Why do DBA’s get all the cool tools? Gary J

Cursor For Loop

2/15/2018RMOUG Training Days 2018

39

Page 40: Creating My Own PL/SQL Performance Monitoring Package ... · Creating My Own PL/SQL Performance Monitoring Tool using PL/SQL and APEX Why do DBA’s get all the cool tools? Gary J

Bulk Collect

2/15/2018RMOUG Training Days 2018

40

Page 41: Creating My Own PL/SQL Performance Monitoring Package ... · Creating My Own PL/SQL Performance Monitoring Tool using PL/SQL and APEX Why do DBA’s get all the cool tools? Gary J

View Result Data in APEX

2/15/2018RMOUG Training Days 2018

41

Page 42: Creating My Own PL/SQL Performance Monitoring Package ... · Creating My Own PL/SQL Performance Monitoring Tool using PL/SQL and APEX Why do DBA’s get all the cool tools? Gary J

Regular Fetch in APEX

2/15/2018RMOUG Training Days 2018

42

Page 43: Creating My Own PL/SQL Performance Monitoring Package ... · Creating My Own PL/SQL Performance Monitoring Tool using PL/SQL and APEX Why do DBA’s get all the cool tools? Gary J

Regular Fetch Chart with Average

2/15/2018RMOUG Training Days 2018

43

Page 44: Creating My Own PL/SQL Performance Monitoring Package ... · Creating My Own PL/SQL Performance Monitoring Tool using PL/SQL and APEX Why do DBA’s get all the cool tools? Gary J

Regular Fetch Chart with Average

and Standard Deviations

2/15/2018RMOUG Training Days 2018

44

Page 45: Creating My Own PL/SQL Performance Monitoring Package ... · Creating My Own PL/SQL Performance Monitoring Tool using PL/SQL and APEX Why do DBA’s get all the cool tools? Gary J

Build a semi-automatic Collection

SystemTables

PL/SQL Package

PL/SQL Triggers

APEX

Test

2/15/2018RMOUG Training Days 2018

45

Page 46: Creating My Own PL/SQL Performance Monitoring Package ... · Creating My Own PL/SQL Performance Monitoring Tool using PL/SQL and APEX Why do DBA’s get all the cool tools? Gary J

Create New User TOPT_PROF

Schema – TOPT_PROF

Owns PL/SQL Profiler Tables

OWNS TOPT_PROF Collection Tables

Owns TOPT_PROF_PKG

Grants EXECUTE on TOPT_PROF_PKG to PUBLIC

NO SELECT, INSERT, UPDATE, DELETE Privileges Granted on TOPT_PROF Tables

Schema Owner GPRO1 owns COMP_REG_BULK and demo table

2/15/2018RMOUG Training Days 2018

46

Page 47: Creating My Own PL/SQL Performance Monitoring Package ... · Creating My Own PL/SQL Performance Monitoring Tool using PL/SQL and APEX Why do DBA’s get all the cool tools? Gary J

Create Collection Tables

TOPT_PROF_COLLECTIONS

TOPT_PROF_BASELINE

TOPT_PROF_VIOLATIONS

2/15/2018RMOUG Training Days 2018

47

Page 48: Creating My Own PL/SQL Performance Monitoring Package ... · Creating My Own PL/SQL Performance Monitoring Tool using PL/SQL and APEX Why do DBA’s get all the cool tools? Gary J

DBMS_SCHEDULER Job

2/15/2018RMOUG Training Days 2018

48

Page 49: Creating My Own PL/SQL Performance Monitoring Package ... · Creating My Own PL/SQL Performance Monitoring Tool using PL/SQL and APEX Why do DBA’s get all the cool tools? Gary J

Create an Issue with the Cursor Query

Alter index BIG_TAB_OWNER_IDX invisible;

Query cannot use index

2/15/2018RMOUG Training Days 2018

49

Page 50: Creating My Own PL/SQL Performance Monitoring Package ... · Creating My Own PL/SQL Performance Monitoring Tool using PL/SQL and APEX Why do DBA’s get all the cool tools? Gary J

TOPT_PROF_APP APEX Application

2/15/2018RMOUG Training Days 2018

50

Page 51: Creating My Own PL/SQL Performance Monitoring Package ... · Creating My Own PL/SQL Performance Monitoring Tool using PL/SQL and APEX Why do DBA’s get all the cool tools? Gary J

APEX FORM on Table

TOPT_PROF_COLLECTIONS

2/15/2018RMOUG Training Days 2018

51

Page 52: Creating My Own PL/SQL Performance Monitoring Package ... · Creating My Own PL/SQL Performance Monitoring Tool using PL/SQL and APEX Why do DBA’s get all the cool tools? Gary J

Regular Fetch Chart of Profiler Runs

2/15/2018RMOUG Training Days 2018

52

Page 53: Creating My Own PL/SQL Performance Monitoring Package ... · Creating My Own PL/SQL Performance Monitoring Tool using PL/SQL and APEX Why do DBA’s get all the cool tools? Gary J

Create Baseline (and Threshold 3 STD.)

2/15/2018RMOUG Training Days 2018

53

Page 54: Creating My Own PL/SQL Performance Monitoring Package ... · Creating My Own PL/SQL Performance Monitoring Tool using PL/SQL and APEX Why do DBA’s get all the cool tools? Gary J

Chart with Baseline and Threshold

2/15/2018RMOUG Training Days 2018

54

Page 55: Creating My Own PL/SQL Performance Monitoring Package ... · Creating My Own PL/SQL Performance Monitoring Tool using PL/SQL and APEX Why do DBA’s get all the cool tools? Gary J

Create an Issue with the Cursor Query

Alter index BIG_TAB_OWNER_IDX invisible;

Query cannot use index

2/15/2018RMOUG Training Days 2018

55

Page 56: Creating My Own PL/SQL Performance Monitoring Package ... · Creating My Own PL/SQL Performance Monitoring Tool using PL/SQL and APEX Why do DBA’s get all the cool tools? Gary J

Chart with Induced Error

2/15/2018RMOUG Training Days 2018

56

Page 57: Creating My Own PL/SQL Performance Monitoring Package ... · Creating My Own PL/SQL Performance Monitoring Tool using PL/SQL and APEX Why do DBA’s get all the cool tools? Gary J

Reporting Threshold Violations

2/15/2018RMOUG Training Days 2018

57

Page 58: Creating My Own PL/SQL Performance Monitoring Package ... · Creating My Own PL/SQL Performance Monitoring Tool using PL/SQL and APEX Why do DBA’s get all the cool tools? Gary J

TO-DO List

Send email notification

Incorporate the Hierarchical Profiler

Clean up and standardize APEX Application

2/15/2018RMOUG Training Days 2018

58

Page 59: Creating My Own PL/SQL Performance Monitoring Package ... · Creating My Own PL/SQL Performance Monitoring Tool using PL/SQL and APEX Why do DBA’s get all the cool tools? Gary J

FINAL THOUGHTSYes we can!!!

www.theoldprotraining.com

2/15/2018RMOUG Training Days 2018

59