How to execute sql tuning advisor for SQL ID in 19c

 

Description: - SQL Tuning Advisor is a program provided by sql that comes along with oracle installation. This advisor can be executed against a sql id and it generates a report with recommendations which generally includes

·       Collection of object statistics

·       Creation of indexes

·       Rewriting SQL statements

·       Creation of SQL profiles

·       Creation of SQL plan baselines

 

The objective to use this program is to avoid tedious manual tuning which DBA’s generally do to fix a bad query.

Note:-As mentioned earlier, this advisor comes along with default  oracle installation but It requires Diagnostic and Tuning packs to use the SQL Tuning Advisor.  

 

Let me demonstrate how to execute SQL tuning advisor against a SQL id

 

Step 1.

To run the advisor we need to create tuning task ,

But before that , we need to have the sql id against which we would run the advisor.

For e.g. let us assume the sql id is – 8d5cry63fwerg65

SET serveroutput ON

DECLARE

  l_sql_tune_task_id  VARCHAR2(100);

BEGIN

  l_sql_tune_task_id := DBMS_SQLTUNE.create_tuning_task (

                          sql_id      => '&&my_sql_id',

                          scope       => DBMS_SQLTUNE.scope_comprehensive,

                          time_limit  => 120000,

                          task_name   => 'sql_tuning_task_&&my_sql_id',

                          description => 'Tuning task for statement &&my_sql_id.');

  DBMS_OUTPUT.put_line('l_sql_tune_task_id: ' || l_sql_tune_task_id);

END;

/

 

Enter value for my_sql_id: 8d5cry63fwerg65

 

Step 2.

Check the task status.

SELECT task_name, STATUS FROM dba_advisor_log WHERE task_name LIKE 'sql_tuning_task_&&my_sql_id';

 

TASK_NAME                                      STATUS

------------------------------             -----------

sql_tuning_task_8d5cry63fwerg65    INITIAL

 

 

 

 

Step 3.

Execute the sql tuning task

EXEC DBMS_SQLTUNE.execute_tuning_task(task_name => 'sql_tuning_task_&&my_sql_id');

 

Step 4.

Check the task status again

SELECT task_name, STATUS FROM dba_advisor_log WHERE task_name LIKE 'sql_tuning_task_&&my_sql_id';

 

TASK_NAME                                                 STATUS

------------------------------                              -----------

sql_tuning_task_8d5cry63fwerg65     COMPLETED

 

 

Step 5.

Review the recommendations by SQL Tuning Advisor

SET LINES 222

SET pages 30000

SET long 999999

SET longc 99999999

 

SELECT DBMS_SQLTUNE.report_tuning_task('sql_tuning_task_&&my_sql_id') AS recommendations FROM dual;

 

 

Step 5.

Implement the Recommendations only if you find the recommendations are satisfactory.

execute dbms_sqltune.accept_sql_profile(task_name => ‘sql_tuning_task_8d5cry63fwerg65', task_owner => 'SYS', replace => TRUE);

 

 

Stpe 6.

To drop the tuning task

BEGIN

  DBMS_SQLTUNE.drop_tuning_task (task_name => 'sql_tuning_task_&&my_sql_id');

END;

/

 

Step 7.

Verify the task status

SELECT task_name, STATUS FROM dba_advisor_log WHERE task_name LIKE 'sql_tuning_task_&&my_sql_id';

 

 

Unexpected error occurred during authentication in ODA

 

Issue:- oda-admin credential is not working

 

So, few days ago while trying to login ODA management url using its credential, it gave me following message


 

Solution:-

This issue happens when there is some problem with the credential of the user or maybe the password is expired.

 

To reset the password,

Login to oda compute node as root user and execute the following command.

[root@server1 ~]# /opt/oracle/dcs/bin/odacli-adm set-credential --username oda-admin

Enter user password:

Retype user password:

 

 

More info:
The password length (minimum:9 maximum:30) characters
The password should start with an alpha character (a-z, A-Z)
The password should contain ALL of the following:

a) At least two uppercase letters
b) At least two lowercase letters
c) At least two numbers
d) At least two special characters, valid characters are # _ -

 

Once, password is reset try to login the console. It should work.




Handy Oracle Data guard Broker Commands Part-I

 

Handy Oracle Data guard Broker Commands: -

Here,

Primary database is : ORCL

Standby Database is : ORCLDR


Login DGMGRL utility

dgmgrl / [Here connection happens through os authentication]

or

dgmgrl sys/<sys_password>@<connect dentifier>

 

 

To check current status and configuration

DGMGRL> show configuration;

 

Configuration - my_dg_config

 

  Protection Mode: MaxPerformance

  Members:

  orcl   - Primary database

    orcldr - Physical standby database

 

Fast-Start Failover:  Disabled

 

Configuration Status:

SUCCESS   (status updated 16 seconds ago)

 

 

To Display information of members under Dataguard configuration

DGMGRL> show database orcl

 

Database - orcl

 

  Role:               PRIMARY

  Intended State:     TRANSPORT-ON

  Instance(s):

    orcl

 

Database Status:

SUCCESS

 

DGMGRL> show database orcldr

 

Database - orcldr

 

  Role:               PHYSICAL STANDBY

  Intended State:     APPLY-ON

  Transport Lag:      0 seconds (computed 0 seconds ago)

  Apply Lag:          0 seconds (computed 0 seconds ago)

  Average Apply Rate: 30.00 KByte/s

  Real Time Query:    OFF

  Instance(s):

    orcl

 

Database Status:

SUCCESS

 

 

Performing a Switchover using dataguard broker

DGMGRL> switchover to orcldr;

Performing switchover NOW, please wait...

Operation requires a connection to database "orcldr"

Connecting ...

Connected to "ORCLDR"

Connected as SYSDBA.

New primary database "orcldr" is opening...

Operation requires start up of instance "orcl" on database "orcl"

Starting instance "orcl"...

Connected to an idle instance.

ORACLE instance started.

Connected to "orcl"

Database mounted.

Switchover succeeded, new primary is "orcldr"

 

 

To Display detailed information of configuration

DGMGRL> show configuration verbose

 

Configuration - my_dg_config

 

  Protection Mode: MaxPerformance

  Members:

  orcl   - Primary database

    orcldr - Physical standby database

 

  Properties:

    FastStartFailoverThreshold      = '30'

    OperationTimeout                = '30'

    TraceLevel                      = 'USER'

    FastStartFailoverLagLimit       = '30'

    CommunicationTimeout            = '180'

    ObserverReconnect               = '0'

    FastStartFailoverAutoReinstate  = 'TRUE'

    FastStartFailoverPmyShutdown    = 'TRUE'

    BystandersFollowRoleChange      = 'ALL'

    ObserverOverride                = 'FALSE'

    ExternalDestination1            = ''

    ExternalDestination2            = ''

    PrimaryLostWriteAction          = 'CONTINUE'

    ConfigurationWideServiceName    = 'orcl_CFG'

 

Fast-Start Failover:  Disabled

 

Configuration Status:

SUCCESS

 

 

To Display properties and a brief information of the database

DGMGRL> show database verbose orcldr

 

Database - orcldr

 

  Role:               PHYSICAL STANDBY

  Intended State:     APPLY-ON

  Transport Lag:      0 seconds (computed 1 second ago)

  Apply Lag:          0 seconds (computed 1 second ago)

  Average Apply Rate: 23.00 KByte/s

  Active Apply Rate:  765.00 KByte/s

  Maximum Apply Rate: 2.26 MByte/s

  Real Time Query:    OFF

  Instance(s):

    orcl

 

  Properties:

    DGConnectIdentifier             = 'orcldr'

    ObserverConnectIdentifier       = ''

    FastStartFailoverTarget         = ''

    PreferredObserverHosts          = ''

    LogShipping                     = 'ON'

    RedoRoutes                      = ''

    LogXptMode                      = 'ASYNC'

    DelayMins                       = '0'

    Binding                         = 'optional'

    MaxFailure                      = '0'

    ReopenSecs                      = '300'

    NetTimeout                      = '30'

    RedoCompression                 = 'DISABLE'

    PreferredApplyInstance          = ''

    ApplyInstanceTimeout            = '0'

    ApplyLagThreshold               = '30'

    TransportLagThreshold           = '30'

    TransportDisconnectedThreshold  = '30'

    ApplyParallel                   = 'AUTO'

    ApplyInstances                  = '0'

    StandbyFileManagement           = ''

    ArchiveLagTarget                = '0'

    LogArchiveMaxProcesses          = '0'

    LogArchiveMinSucceedDest        = '0'

    DataGuardSyncLatency            = '0'

    LogArchiveTrace                 = '0'

    LogArchiveFormat                = ''

    DbFileNameConvert               = ''

    LogFileNameConvert              = ''

    ArchiveLocation                 = ''

    AlternateLocation               = ''

    StandbyArchiveLocation          = ''

    StandbyAlternateLocation        = ''

    InconsistentProperties          = '(monitor)'

    InconsistentLogXptProps         = '(monitor)'

    LogXptStatus                    = '(monitor)'

    SendQEntries                    = '(monitor)'

    RecvQEntries                    = '(monitor)'

    HostName                        = 'EGC-MUN-STBY-PH'

    StaticConnectIdentifier         = '(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=SERVER1)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORCLDR_DGMGRL)(INSTANCE_NAME=orcl)(SERVER=DEDICATED)))'

    TopWaitEvents                   = '(monitor)'

    SidName                         = '(monitor)'

 

  Log file locations:

    Alert log               : D:\ORACLE\diag\rdbms\orcldr\orcl\trace\alert_orcl.log

    Data Guard Broker log   : D:\ORACLE\diag\rdbms\orcldr\orcl\trace\drcorcl.log

 

Database Status:

SUCCESS

 

List of Oracle 19c specific parameters

 

 Following are Oracle 19c specific parameter  which can be added in a pfile for a database running 19.x.x


#########
#
# Compatibility parameter.
#
# Compatibility should be set to the current release.
#
#########

compatible = 19.0.0 #MP

#########
#
# Optimizer parameters.
#
# In Oracle Database 12.2 or higher, the Parameter optimizer_adaptive_features has been obsoleted,
# replaced and controlled by two new parameters, optimizer_adaptive_plans, which defaults to TRUE and
# optimizer_adaptive_statistics, which defaults to FALSE. For more details Refer MOS DOC ID 2031605.1.
#
##########

optimizer_adaptive_plans = TRUE #MP
optimizer_adaptive_statistics = FALSE #MP

#########
#
# PGA Aggregate Limit parameter.
#
# PGA_AGGREGATE_LIMIT feature in 19c limits PGA memory usage
#
# The default value of PGA_AGGREGATE_LIMIT is set to the greater of 2 GB,
# 200% of PGA_AGGREGATE_TARGET, and 3 MB times the PROCESSES parameter.
# It will not exceed 120% of the physical memory size minus the total SGA size.
#
# PGA_AGGREGATE_LIMIT cannot be set below its default value. If a value of 0 is specified,
# it means there is no limit to the aggregate PGA memory consumed by the instance.
# If total PGA memory usage is over PGA_AGGREGATE_LIMIT value. The sessions or processes
# that are consuming the most untunable PGA memory will be terminated.
#
# Recommended value for PGA_AGGREGATE_LIMIT is 0.
#
##########

pga_aggregate_limit = 0 #MP

#########
#
# Temp Undo Enabled parameter.
#
# TEMP_UNDO_ENABLED helps to reduce the amount of redo caused by DML on global temporary tables.
# Setting to TRUE may cause serious issues, such as ORA-55526, for distributed transactions (Ref. Bug 20712819).
# The recommended value for systems using distributed transactions is currently FALSE (Pending ER 24286334).
# If not using distributed transactions, TRUE will improve performance by eliminating REDO on permanent UNDO.
#
##########

temp_undo_enabled = FALSE

#########
#
# Multitenant Architecture parameter.
#
# This parameter is required if the non-cdb name in lower case or mixed case, then
# plugin database will be created with the same case. Otherwise default is Upper case.
# This parameter needs to be set at the CDB level before plugging in the PDB
#
##########

_pdb_name_case_sensitive = TRUE #MP

#########
#
# Event parameter.
#
# Ensure the following event is set for Oracle E-Business Suite to work with Database Release 19c.
# This parameter needs to be set at the CDB level. When this event is set,
# it will allow utl_file functions to accept a directory path as input and
# enable backward compatibility of user/all/dba_arguments behavior on 19c.
#
##########

event='10946 trace name context forever, level 8454144' #MP

#########
#
# Real Time Statistics for On-Premise Exadata and Exadata Cloud Service environments.
#
# If you are using Oracle Database Release 19c (19.1.x-19.9.x) on Engineered Systems such as
# Exadata or ExaCS, ensure the following parameters are set to FALSE. This will disable Real
# Time Statistics, and stop gathering optimizer real-time statistics for conventional DMLs.

_optimizer_gather_stats_on_conventional_dml = FALSE #MP
_optimizer_use_stats_on_conventional_dml = FALSE #MP

# The parameter optimizer_real_time_statistics is an Oracle Database 21c parameter that has
# been backported to Oracle Database 19c RU 10 (19.10.x). If you are using Oracle Database
# Release 19.10.x or higher on an Engineered System such as Exadata or ExaCS, ensure the
# parameter is disabled (the default) by setting it to FALSE.

optimizer_real_time_statistics = FALSE #MP

###############################################################################
#
# End of Release-Specific Database Initialization Parameters Section for 19c
#
###############################################################################