Monday, May 16, 2022

Oracle Database -- Troubleshooting Listener connectivity and network issue

Listing down  handy troubleshooting  steps to check listener connection issues 


1)  Check if Listener is Up and Running 

ps –ef | grep lsnr




2) Check if  Listener is listening to Service and database service is up 

lsnrctl services LISTENER_NAME | grep -i  service_name 


If database is having service configured check  if database service is up 

srvctl config service -d  db_+name 
srvctl status service -d  db_name  -s service 




3) Check if port and host is reachable from client machine 

telnet database_host_name 1524




4)  Using netstat on database server to see if post is open and listening 

 netstat –a
 netstat -a | wc -l
 netstat -a | wc -l
 netstat -anp | pg
netstat -anp | more
netstat -a | more
netstat -a | more
netstat -a | grep ESTAB      See check established connection 
netstat -a| grep LISTEN
netstat -an | grep 6100 | grep LISTE
netstat -an | grep 6100   connections on each port 
netstat -an | grep ESTAB    to check number of connection coming from each port 
netstat -na |grep -i listen   
netstat -anp | grep 1521 
netstat -P tcp



   
Other tools  used 

tnsping  
ping  
telnet 
netstat 
traceroute 
tracepath  
tcpdump 
ifconfig, ifup, ifdown





5) Check if  process parameter threshold is reached in database . 


6)  Tracing lsnrctl commands 

truss -o /tmp//xx -aefx lsnrctl status LISTENER_CODP01
truss -o /tmp//xx -aef -v all -w all lsnrctl status LISTENER_CODP0



To enable listener tracing use  below 

LSNRCTL> set cur LISTENER_TEST
LSNRCTL> status
LSNRCTL> set trc_level ADMIN
LSNRCTL> status



7)  Check details of process 

pwdx 24637   -->  to check  location from where process started from 
pfiles 24637   -->  files opened by each process 


8) Check listener log for any errors reported 


9) Check allowed host on database server.

check what is inside /etc/hosts.allow /etc/hosts.deny


10)  Check database wait events and if database is hung . Check database alert log . 



11) Unix team to check network speed

 for en in `netstat -i | grep en | awk '{print $1}' | sort -u | cut -c3`
do
   adapter=`echo ent${en}`
   entstat -d ${adapter} | grep "Media Speed"
done



12) If  listener  log file  size is huge  try , rotating logfile . 

[oracle@server1 ~]$ lsnrctl.
LSNRCTL> show current_listener.
LSNRCTL> set current_listener
LSNRCTL> set log_status off.
[oracle@server1 trace]$ mv listener.log listener_backup.log.
LSNRCTL> set log_status on.



13) Do a continuous ping to check for packet Drops 


14)  TNS-12505 TNS-12514 :     local_listener parameter was removed after patching 

alter system set LOCAL_LISTENER='(ADDRESS=(PROTOCOL=TCP)(HOST=hostname)(PORT=1521))' scope=both;   à no ip or localhost

alter system register;



15)  To check  session tns information from database 

set lines 120
col NETWORK_SERVICE_BANNER format a75
select NETWORK_SERVICE_BANNER, count(*) 
from v$session_connect_info 
where NETWORK_SERVICE_BANNER like '%TCP/IP%' or NETWORK_SERVICE_BANNER like '%Bequeath%' 
group by NETWORK_SERVICE_BANNER;


select sid,program,
case when program not like 'ora___@% (P%)' then
(select max(case
when NETWORK_SERVICE_BANNER like '%TCP/IP%'
then 'TCP'
when NETWORK_SERVICE_BANNER like '%Bequeath%'
then 'BEQUEATH'
when NETWORK_SERVICE_BANNER like '%IPC%'
then 'IPC'
when NETWORK_SERVICE_BANNER like '%SDP%'
then 'SDP'
when NETWORK_SERVICE_BANNER like '%NAMED P%'
then 'Named pipe'
when NETWORK_SERVICE_BANNER is null
then 'TCPS' end)
from
v$session_connect_info i
where
i.sid=s.sid) end protocol
from
v$session s;




16) Use tcpdump   for analysis 

Use tcpdump to view Packet Flows (Doc ID 2259297.1)


tcpdump -i <ethX> -C 20 -s 10000 -S -w /tmplog.log  -ttt 'port 777' &
eth stands for network interface that carries traffic 


17) Use unix  time command  to determine  how much it is taking .


18)  Checking incoming connections from which  port 

select sid, username,status,osuser, machine, port, program from v$session where type='USER';

netstat -tn | grep 1522
netstat -anp |  grep 1522 



19) Check if any locks in database 




Saturday, May 14, 2022

Oracle SQL Tuning Health-Check Script (SQLHC)

 
The SQL Tuning Health-Check Script is a tool developed by the Oracle Server Technologies Center of Expertise.

The tool, also known as SQLHC, is used to check the environment in which a single SQL Statement runs, checking Cost-based Optimizer (CBO) statistics, schema object metadata, configuration parameters and other elements that may influence the performance of the one SQL being analyzed.

SQLHC does not require any special licensing, it is free and it is designed to run on all systems. If the Diagnostics and Tuning packs are installed, that data will be used by the script. If you are not licensed for Diagnostics and Tuning, answer “NO” to that question in the script to avoid licensing problems.



What all information can SQLHC provide:

Some of the key information that this tool can provide you is below:

Explain plan of the SQL ID and any changes
Validity of various statistics and parameters with a brief explanation
Tables and index details
Objects Statistics Details
SQL_TEXT and SQL profile, baseline details
Historical Plan details
Many other information pieces from dynamic performance views.

Good thing is that it saves you from running multiple scripts and collecting all the above data. Running single SQLHC accumulates all the data and present it in HTML easy-to-read format.




Parameters Required:

1) Login to the database server and set the environment used by the Database Instance.
2)  Download the “sqlhc.zip”  archive file and extract the contents to a suitable directory/folder.
3) Connect into SQL*Plus as SYS, a DBA account, or a user with access to Data Dictionary views and simply execute the “sqlhc.sql” script. It will request to enter two parameters:
Oracle Pack License (Tuning, Diagnostics or None) [T|D|N] (required)
If site has both Tuning and Diagnostics licenses then specify T (Oracle Tuning pack includes Oracle Diagnostics)
A valid SQL_ID for the SQL to be analyzed.


SQl> @sqlhc.sql T djkbyr8vkc64h
or 
SQL> START sqlhc.sql T djkbyr8vkc64h




IF in case sqlid is not present in database and we want to execute actual sql statement using sqlhcxec.sql 



REM EXAMPLE
REM # sqlplus / as sysdba
REM SQL> START [path]sqlhcxec.sql [T|D|N] [path]scriptname
REM SQL> START utl/sqlhcxec.sql T input/sample/script1.sql







Reference : 
SQL Tuning Health-Check Script (SQLHC) (Doc ID 1366133.1)
FAQ: SQL Health Check (SQLHC) Frequently Asked Questions (Doc ID 1417774.1)
Document 1455583.1 SQL Tuning Health-Check Script (SQLHC) Video
Document 1482811.1 Best Practices: Proactively Avoiding Database and Query Performance Issues  
Document 1477599.1 Best Practices Around Data Collection For Performance Issues
Primary Note: SQL Query Performance Overview (Doc ID 199083.1)


Sunday, May 8, 2022

Oracle Database 19c - SQL_DIAGNOSE_AND_REPAIR



In Oracle Database 19c, a new function SQL_DIAGNOSE_AND_REPAIR is introduced to diagnose a given SQL statement for a given SQL for the given problem type. This function creates an incident, populate incident metadata with required information like, SQL ID, SQL text, compilation environment, and so on. It also creates a diagnostic task, executes it and accepts recommendation for a given SQL.



For example:

SQL> select max(col3) from tbl1 where col1=10000 and col2=10000;

MAX(COL3)
------------------------------
A10000

SQL> column sql_id new_value sql_id
SQL> select prev_sql_id as sql_id from v$session where sid = userenv('sid');


 
SQL> var incident_id number;
SQL> exec :incident_id := dbms_sqldiag.sql_diagnose_and_repair(sql_id => '&sql_id',scope=>DBMS_SQLDIAG.SCOPE_COMPREHENSIVE,time_limit=>DBMS_SQLDIAG.TIME_LIMIT_DEFAULT,problem_type=>DBMS_SQLDIAG.PROBLEM_TYPE_PERFORMANCE,auto_apply_patch=>'NO');


PL/SQL procedure successfully completed.

SQL>
SQL> select DBMS_SQLDIAG.REPORT_DIAGNOSIS_TASK(:incident_id) from dual;


SQL> set autotrace off





Reference : 
1)  19c New Feature - New Automatic Diagnostics and Repair Function SQL_DIAGNOSE_AND_REPAIR (Doc ID 2644400.1)

Oracle 19c: Bug 27175987 — Partition Pruning Not Work For SQL With Predicate Of User Function After Upgrade To 19c

 
As we see 19c comes with lot of performance instability ,  recently  we been  facing issues with sql on partition tables . 
It was  observed that After upgrade to 19c, partition pruning  not work for the SQL with predicates of user defined function, while partition pruning works for the same SQL prior to 19c.

This is bug 27175987, also not published. Made as fix_control, can be seen in v$system_fix_control, can be disabled if desired.


Fix 1) 

Enable partition pruning disable the fix of Bug 27175987 by setting "_fix_control" = '27175987:off'

alter session set "_fix_control" = '27175987:off';

or

Add hint /*+ OPT_PARAM('_fix_control' '27175987:off') */:





Fix 2 ) 

Change user defined function to deterministic PL/SQL functions if it is non-deterministic, and add the DETERMINISTIC clause to the function if the function is truly deterministic

SQL> CREATE or REPLACE FUNCTION <USER_FUNCTION_NAME>(ARG VARCHAR2) RETURN VARCHAR2 deterministic IS -- Add "deterministic"
BEGIN
  RETURN ARG;
END;
/



Reference : 
1) Query Performance Issues after upgrade to 19C (Doc ID 2739411.1)
2) Partition Pruning Not Work For SQL With Predicate Of User Function After Upgrade To 19c (Doc ID 2717940.1)
3) Things to Consider to Avoid SQL Performance Problems on 19c (Doc ID 2773715.1)

Oracle Database -- NEW REPORTING SUBPROGRAMS IN DBMS_STATS PACKAGE

 
Knowing when and how to gather statistics in a timely manner is critical to maintain acceptable performance on any system.

Determining what statistics gathering operations are currently executing in an environment and how changes to the statistics methodology will impact the system can be difficult and time consuming.

Reporting subprograms in DBMS_STATS package make it easier to monitor what statistics gathering activities are currently going on and what impact changes to the parameter settings of these operations will have. 

The DBMS_STATS subprograms are  REPORT_STATS_OPERATIONS, REPORT_SINGLE_STATS_OPERATION and REPORT_GATHER_*_STATS.

 The report shows detailed information about what statistics gathering operations have occurred, during a specified time window. It gives details on when each operation occurred, its status, and the number of objects covered and it can be displayed in either text or HTML format.


COLUMN REPORT FORMAT A300

VARIABLE my_report CLOB;
BEGIN
:my_report := DBMS_STATS.REPORT_STATS_OPERATIONS (
  since => SYSDATE-7
, until => SYSDATE
, detail_level => 'TYPICAL'
, format => 'TEXT'
, auto_only => TRUE
);
END;
/

print my_report;



 variable mystatrep2 clob;
  set long 1000000
   begin
   :mystatrep2 := dbms_stats.report_stats_operations(
    since=>SYSTIMESTAMP-16,
    until=>SYSTIMESTAMP-1,
   detail_level=>'TYPICAL',
    format=>'TEXT'); 
  end;
   /

  print mystatrep2


Saturday, May 7, 2022

Exacc -- Create database manually using dbaascli

 

1) Listing Available Software Images and Versions for Database

[oracle@host1 ~]$ sudo dbaascli cswlib showImages




2)  Creating Oracle Database Home with Unified Audit Enabled 

[oracle@host1 ~]$ sudo dbaascli dbhome create --version 19000 --bp JAN2021 --oracleHomeName UnifiedAuditenabled --enableUnifiedAuditing true



3) Creating Oracle Database In the Specified Oracle Database Home

[oracle@host1 ~]$ sudo dbaascli database create --dbName DBNAME --dbUniqueName DBNAME --dbSid DBNAME --oracleHomeName UnifiedAuditenabled --nodeList host1,host2 --createAsCDB true --waitForCompletion false


The command will prompt for the sys and TDE password.

Use the flag --waitForCompletion false
To run in the background.


To run prerequisites checks, use the --executePrereqs command option. This will perform only the prerequisite checks without performing the actual Oracle Database home creation.

sudo dbaascli dbhome create --version Oracle Home Version --imageTag image tag --executePrereqs
Where:
--version specifies the Oracle Database version
--imageTag specifies the Image Tag of the image to be used




4) Monitor the progress of the Job

[oracle@host1 ~]$ sudo dbaascli job getStatus --jobID 09309052-7700-44d5-83e2-f8e 





 5) 

Generate a cloud registration file (creg.ini)  under /var/opt/oracle/creg/ by running the following command as the root user on one of the database servers:

# dbaascli registerdb registry --action initialize --db dbname [ --udb dbuniquename ]


# dbaascli registerdb prereqs –dbname dbname [ –db_unique_name dbuniquename ]
# dbaascli registerdb begin --dbname dbname [ --db_unique_name dbuniquename ]





Sunday, May 1, 2022

Oracle Background Processes that can be restarted and How to prioritize an Oracle Database background process

 
Thought of  documenting  this as at times we come across situations where w have to kill certain background process to high load  or other issues . 
This is only for information purpose . Its advisable to  check with  Oracle Support for any actions 


Killable:
ARCn: Redo log archivers
CJQn: Job scheduler coordinator
Dnnn: Dispatchers
DIA0: Diagnosibility process 0
DIAG: Diagnosibility coordinator
FDBA: Flashback data archiver process
Jnnn: Job scheduler processes
MMNL: Manageability Monitor Process 2
MMON: Manageability Monitor Process
PING: Interconnect latency measurement
Qnnn: Queue cleanup processes
QMNC: Queue coordinator
RECO: Distributed recovery process
Snnn: Shared servers
SMCO: Space management coordinator
Wnnn: Space management processes

Instance-Critical:
ACMS: Atomic controlfile to memory server
CKPT: Checkpoint
DBRM: Resource manager process
DBWn: Database writer processes
LGWR: Redo log writer
LMDn: Global enqueue service daemons
LMON: Global enqueue service monitor
MMAN: Memory manager
PMON: Process monitor
PSPn: Process spawners
RMSn: RAC management server
RVWR: Recovery writer
SMON: System monitor process
VKTM: Virtual keeper of time process



Increasing Priority of Background process . 

In   Test case we  will be increasing priority of LGWR  proces to get rid of log file snc wait . 

Increasing the LGWR priority is putting the LGWR process in the Round-Robin (SCHED_RR) class. You can increase process’s priority both using OS (renice, nice commands) or Database methods, but this post is about setting the priority using ‘_high_priority_process’ an undocumented/hidden parameter that prioritizes your database managed processes

starting from 21.3.0.0.0 LGWR process is part of _high_priority_processes group along with VKTM & LMS* processes.
Note: This being a hidden/undocumented parameter I advise to consult with Oracle support before going and changing the parameter value. 


 select ksppstvl from x$ksppi join x$ksppcv using (indx) where ksppinm='_high_priority_processes';

alter system set "_high_priority_processes"='LMS*|VKTM|LGWR' scope=spfile;

Restart the database

srvctl stop database -d abdul1
srvctl start database -d abdul2 


 select ksppstvl from x$ksppi join x$ksppcv using (indx) where ksppinm='_high_priority_processes';



Tuesday, April 26, 2022

Oracle 19c Automatic SQL Plan Management Behaviors Change

 

What's New : 

Automatic SQL Plan Management is enabled by default in Oracle 19c
New SQL plan baselines will be created automatically


By default, the SPM Evolve Advisor runs daily in the maintenance window
• In 19c it can be configured to also run outside of the maintenance window
• To control it, the DBMS_SPM.CONFIGURE procedure supports a new parameter
• AUTO_SPM_EVOLVE_TASK (OFF, ON, AUTO)
• In 19c AUTO is equivalent to ON
• When enabled, it runs every hour for no longer than 30 minutes



How to check :

column parameter_value format a45
column parameter_name format a25
set pages 200

SELECT PARAMETER_NAME, PARAMETER_VALUE
  FROM   DBA_ADVISOR_PARAMETERS
  WHERE  TASK_NAME = 'SYS_AUTO_SPM_EVOLVE_TASK'
    AND PARAMETER_VALUE <> 'UNUSED'
  ORDER BY 1;


SELECT sql_handle, plan_name, enabled, accepted FROM dba_sql_plan_baselines;


The new default AUTO for ALTERNATE_PLAN_BASELINE and ALTERNATE_PLAN_SOURCE enables the Automatic SQL Plan Management in Oracle Database 19c. The attribute ALTERNATE_PLAN_SOURCE lets the advisor identify the sources for plans by itself. The ALTERNATE_PLAN_BASELINE parameter determines which SQL statements are eligible for plan capture. AUTO in this case means that any SQL statement in AWR will be a potential candidate.




How to  revert to the Oracle 12.2.0.1   Behavior : 

BEGIN 
   DBMS_SPM.SET_EVOLVE_TASK_PARAMETER( 
      task_name => 'SYS_AUTO_SPM_EVOLVE_TASK' ,
      parameter => 'ALTERNATE_PLAN_BASELINE', 
      value     => 'EXISTING'); 
END; 
/

BEGIN 
   DBMS_SPM.SET_EVOLVE_TASK_PARAMETER( 
      task_name => 'SYS_AUTO_SPM_EVOLVE_TASK',
      parameter => 'ALTERNATE_PLAN_SOURCE', 
      value     => 'CURSOR_CACHE+AUTOMATIC_WORKLOAD_REPOSITORY'); 
END; 
/

BEGIN
   DBMS_SPM.SET_EVOLVE_TASK_PARAMETER(
      task_name => 'SYS_AUTO_SPM_EVOLVE_TASK',
      parameter => 'ALTERNATE_PLAN_LIMIT',
      value => 10);
END;
/






Switching to the Oracle 19c  behaviour 

BEGIN 
   DBMS_SPM.SET_EVOLVE_TASK_PARAMETER( 
      task_name => 'SYS_AUTO_SPM_EVOLVE_TASK' ,
      parameter => 'ALTERNATE_PLAN_BASELINE', 
      value     => 'AUTO');  
END; 
/

BEGIN 
   DBMS_SPM.SET_EVOLVE_TASK_PARAMETER( 
      task_name => 'SYS_AUTO_SPM_EVOLVE_TASK',
      parameter => 'ALTERNATE_PLAN_SOURCE', 
      value     => 'AUTO');  
END; 
/

BEGIN
   DBMS_SPM.SET_EVOLVE_TASK_PARAMETER(
      task_name => 'SYS_AUTO_SPM_EVOLVE_TASK',
      parameter => 'ALTERNATE_PLAN_LIMIT',
      value => 'UNLIMITED');
END;
/




Reference : 
https://blogs.oracle.com/optimizer/post/what-is-automatic-sql-plan-management-and-why-should-you-care







Monday, April 25, 2022

Oracle Awr data dump -- Important while migration

 

 

Most of time after migration  of database to new server we observe performance degradation . Usually we dont have historical performance data before migration which land us is big mess.

To overcome this , its very important to  take awr dump from existing database before migration . 


Extract AWR data

For Extract the AWR data from source database run the awrextr.sql script which extracts AWR data for a range of snapshots from the database into a Data Pump export file.
 
1. Run the following script for extract AWR:
@?/rdbms/admin/awrextr.sql;


2. Script ask for select DBID
Enter value for dbid:

3. Enter the number of days backup export:
Enter value for num_days: 2

4. It will list the 2 days snapshot in AWR. Choose the begin and end snapshot for export:
Enter value for begin_snap: 76
Begin Snapshot Id specified: 76
Enter value for end_snap: 86
End Snapshot Id specified: 86

5. List the Directory present in Database, Choose the directory location and dump file name:
Enter value for directory_name: ORACLE_HOME

Enter value for file_name:awrdat_76_86.dmp

6. Now dump is generated.
The AWR extract dump file will be located
in the following directory/file:
 /usr/tmp/
awrdat_76_86.dmp



Load the AWR data to target

For loading the extracted AWR data with awrload.sql script. It will first create a staging schema where the snapshot data is transferred
from the Data Pump file into the database

1. Run the AWRload.sql script for start loading data.

@?/rdbms/admin/awrload.sql

2. Specify the directory name where export file exists.

Enter value for directory_name:

3. Put the prefix of name of dump file:

Enter value for file_name:

4. Specify the name of staging schema where data loaded i.e AWRSTAGE

Enter value for schema_name:

5. Specify the default or temporary tablespace.

Enter value for default_tablespace: SYSAUX
-----------
Enter value for temporary_tablespace: TEMP

6. Loading of data is successful.

AWR Load Started ..

This operation will take a few moments. The
progress of the AWR load operation can be
monitored in the following directory/file:
/usr/tmp/
AWRDAT_76_86.log



The process will then prompt for the staging schema name, the default is AWR_STAGE. If you accept the default, the script will create the AWR_STAGE user after asking you for default tablespaces. Once it has completed the awr load process, the script will drop the AWR_STAGE user.

After the process completes, the AWR tables now have new data in them! You can query DBA_HIST_SNAPSHOT or any of the other DBA_HIST views (including DBA_HIST_ACTIVE_SESS_HISTORY). 

Sunday, April 24, 2022

Estimating Size of Oracle Database Objects --seeing history of object/table size


Resource and performance capacity of the servers is one side of the puzzle. Equally important is to size/estimate the database for storage and the data growth. This would mean the database, the database objects, and the underlying storage subsystem would also have to be sized for today and tomorrow.

Oracle provides few packages and procedures that help determine the size of objects and indexes based on the   estimated growth size. Even further, using the DBMS_SPACE.OBJECT_GROWTH_TREND function, a growth pattern for existing tables can be obtained.

The following query will list the object growth trend for an object; the data for the trend listed is gathered from Automatic Workload Repository (AWR). The growth trends for two of the tables are listed following.

The OBJECT_GROWTH_TREND function returns four values:
TIMEPOINT—Is a time stamp value indicating the time of the recording/reporting.
SPACE_USAGE—Lists the amount of space used by the object at the given point in time.
SPACE_ALLOCATED—Lists the amount of space allocated to the object in the table space at the
given point in time.
QUALITY—Indicates the quality of data reported; there are three possible values:
INTERPOLATED—The value did not meet the criteria of GOOD. As noted in the outputs
following, the used and allocated are same. Basically, the values do not reflect any usage.
GOOD—The value whenever the value of TIME is based on recorded statistics. Value is
marked good if at least 80% of the value is derived from GOOD instance values.
PROJECTED—The value of time is in the future as of the time the table was produced.


In a RAC environment, the output reflects the aggregation of values recorded across all instances in the cluster.

SELECT *
FROM TABLE(dbms_space.object_growth_trend(object_owner => 'ABDUL',
 object_name => 'HISTORY', object_type => 'TABLE'));


TIMEPOINT SPACE_USAGE SPACE_ALLOC QUALITY
------------------------------- ----------- ----------- --------------------
28-MAY-14 11.12.43.052162 AM 111082969 111082969 INTERPOLATED
29-MAY-14 11.12.43.052162 AM 111082969 111082969 INTERPOLATED
30-MAY-14 11.12.43.052162 AM 111082969 111082969 INTERPOLATED
31-MAY-14 11.12.43.052162 AM 111082969 111082969 INTERPOLATED
01-JUN-14 11.12.43.052162 AM 111082969 111082969 INTERPOLATED
02-JUN-14 11.12.43.052162 AM 111082969 111082969 INTERPOLATED
03-JUN-14 11.12.43.052162 AM 111082969 111082969 INTERPOLATED
04-JUN-14 11.12.43.052162 AM 131877793 134217728 GOOD
05-JUN-14 11.12.43.052162 AM 132003569 134369941 PROJECTED
06-JUN-14 11.12.43.052162 AM 132129344 134522153 PROJECTED
07-JUN-14 11.12.43.052162 AM 132255119 134674366 PROJECTED
08-JUN-14 11.12.43.052162 AM 132380894 134826579 PROJECTED
09-JUN-14 11.12.43.052162 AM 132506669 134978791 PROJECTED