Sunday, July 30, 2023
Backup oracle home through tar command
Wednesday, July 19, 2023
Dba daily weekly monthly tasks
A Database Administrator (DBA) plays a critical role in managing and maintaining an organization's databases, ensuring their availability, security, and optimal performance. The tasks of a DBA can be categorized into daily, weekly, and monthly responsibilities. Here's an overview of each:
Schedule some of the below jobs for an easy and peaceful Dba job.
1. Schedule a cronjob for every hour to Check the Database Availability.
2. Schedule a cronjob for every hour to clean the trace files like .trc,.trm,.xml,.aud files.
3. Schedule a cronjob for every hour to check file system alerts
4. Schedule a cronjob for every hour to check free space in tablespaces
5. Schedule a cronjob for every hour to clean the trace files like .trc,.trm,.xml,.aud
6. Schedule a cronjob after business hours to take Rman incremental backup
7. Schedule a cronjob after business hours to gather the specific schema stats
8. Schedule a cronjob to check space on all the mount points
9. Schedule a cronjob on weekends to take full export
10.Schedule a cronjob on weekend to take rman full backup
11.Schedule a cronjob to gather the dictionary stats, system stats
12.Schedule a cronjob for schema refresh as per the client requirement
13.Schedue a cronjob to check the Goldendale extract, manager,replicat process
14.Configure alerts on your business mail and monitor them
15.Configure OEM if you are managing, supporting multiple Linux, Aix, Solarix and Sql servers
16.Configure ServiceNow, Jira, Remedy or SolarWinds or any ticketing tool if you are working on a big MNC client.
1.https://www.servicenow.com/ 2.https://www.bmc.com/it-solutions/remedy-itsm.html# 3.https://www.solarwinds.com/company/contact-us.
Saturday, July 8, 2023
Script to extract the Metadata
How to Extract the DDL for oracle user,Profiles,Roles,Tables,Index,Tablespace,Package,Trigger and Db links.
SET HEADING OFF
SET ECHO OFF
SET LONG 20000 LONGCHUNKSIZE 20000 PAGESIZE 0 LINESIZE 1000 FEEDBACK OFF VERIFY OFF TRIMSPOOL ON
SPOOL DDL_INFO.LOG
SELECT DBMS_METADATA.GET_DDL('USER','TIGER') FROM DUAL;
SELECT DBMS_METADATA.GET_DDL('PROFILE','DEFAULT') FROM DUAL;
SELECT DBMS_METADATA.GET_GRANTED_DDL('ROLE_GRANT','TIGER') FROM DUAL;
SELECT DBMS_METADATA.GET_GRANTED_DDL('OBJECT_GRANT','SCOT') FROM DUAL;
SELECT DBMS_METADATA.GET_GRANTED_DDL('SYSTEM_GRANT','SCOT') FROM DUAL;
SELECT DBMS_METADATA.GET_DDL('ROLE','SUB') FROM DUAL;
SELECT DBMS_METADATA.GET_GRANTED_DDL('SYSTEM_GRANT','RESOURCE') FROM DUAL;
SELECT DBMS_METADATA.GET_DDL('PACKAGE_BODY','PKG_HADOOP','IDC6AMASK')FROM DUAL;
SELECT DBMS_METADATA.GET_DDL('INDEX', 'IX2_MARS_MASTER', 'MARS') FROM DUAL;
SELECT DBMS_METADATA.GET_DDL('INDEX', 'IDX1_TXN1', 'MARS') FROM DUAL;
SELECT DBMS_METADATA.GET_DDL('TABLE', 'EMPLOYEE','SCOT') FROM DUAL;
SELECT DBMS_METADATA.GET_DDL('TABLESPACE','&TABLESPACE_NAME') FROM dual;
Wednesday, July 5, 2023
SQL Tuning Advisor report
What is SQL Tuning Advisor:
The SQL Tuning Advisor is a feature in Oracle Database that analyzes SQL statements and provides recommendations to improve their performance. When you run the SQL Tuning Advisor on a SQL statement or a SQL tuning set, it generates a report known as the SQL Tuning Advisor Report.
The SQL Tuning Advisor Report provides information about the analysis performed by the advisor and presents recommendations for optimizing the SQL statement. The report typically includes the following sections:
Summary: Provides an overview of the analysis and recommendations.
SQL Statement Information: Displays details about the SQL statement, such as its text, execution statistics, and object dependencies.
Access Path Analysis: Evaluates the current execution plan and suggests alternative access paths that may improve performance.
SQL Profile: Suggests creating a SQL profile, which is a set of optimizer statistics and hints that guide the optimizer in generating an efficient execution plan for the SQL statement.
Index Analysis: Examines the existing indexes and proposes new indexes or modifications to existing ones that can enhance query performance.
SQL Restructure: Recommends rephrasing or rewriting the SQL statement to improve performance.
Materialized Views: Suggests creating materialized views that can be used to speed up query execution.
Partitioning Analysis: Recommends partitioning strategies that can improve performance for large tables.
SQL Plan Management: Proposes using SQL Plan Management to maintain stable and efficient execution plans for the SQL statement.
Undo Advisor: Provides recommendations on undo retention settings based on the SQL statement's needs.
The SQL Tuning Advisor Report aims to assist database administrators and developers in optimizing SQL statements and improving overall database performance. It provides specific recommendations tailored to the analyzed SQL statement, allowing users to implement the suggested changes and monitor the performance improvements.
How to generate/run SQL Tuning Advisor report from snap id's 57787 to 59230
1st Method:
This is the problematic sql id:g13kaky245z75
Steps to generate sql-tuning advisor report
sql>spool manual_g13kaky245z75.out
sql>set serveroutput on
DECLARE
l_sql_tune_task_id VARCHAR2(100);
sta_task_count number;
BEGIN
select count(task_name) into sta_task_count from dba_advisor_tasks where task_name='g13kaky245z75_tuning_task';
if sta_task_count > 0 then DBMS_SQLTUNE.drop_TUNING_TASK(task_name=>'g13kaky245z75_tuning_task');
end if;
l_sql_tune_task_id := DBMS_SQLTUNE.CREATE_TUNING_TASK(
begin_snap=>57787,
end_snap=>59230,
sql_id=>'g13kaky245z75',
scope=>'COMPREHENSIVE',
time_limit=>1200,
task_name=>'g13kaky245z75_tuning_task',
description=>'Tuning task for statement ' || 'g13kaky245z75');
DBMS_OUTPUT.put_line('Tuning Task ' || l_sql_tune_task_id||' created.');
EXCEPTION
WHEN OTHERS THEN
if sqlcode <> 0 then dbms_output.put_line(SQLERRM);
raise;
end if;
END;
/
Declare
sta_task_count number;
BEGIN
select count(task_name) into sta_task_count from dba_advisor_tasks where task_name='g13kaky245z75_tuning_task';
if sta_task_count > 0
then DBMS_SQLTUNE.EXECUTE_TUNING_TASK( task_name => 'g13kaky245z75_tuning_task');
end if;
END;
/
sql>SET LONG 90000
sql>SET LONGCHUNKSIZE 90000
sql>SET LINESIZE 125
sql>SET PAGESIZE 500
sql>SELECT DBMS_SQLTUNE.REPORT_TUNING_TASK( 'g13kaky245z75_tuning_task') from DUAL;
spool off
Once spool file generates you can upload to oracle support for further investigation
note: SQL Tuning Advisor can take up to 20 minutes to run. Please don't interrupt it with ctrl-C
2nd Method:
sql>connect to sqlplus "/as sysdba"
sql>@?/rdbms/admin/sqltrpt.sql
Specify the Sql id
~~~~~~~~~~~~~~~~~~
Enter value for sqlid: g13kaky245z75
It will take 20mins time to generate report
Things to check in sql tuning report
1- Statistics Finding
Recommendation: Here you can see the recommendation from sql tuning advisor for ex: to gather the stats or to create index or to modify the sql query
2- Statistics Finding
Recommendation: Here you can see the recommendation from sql tuning advisor for ex: to gather the stats or to create index or to modify the sql query
3- SQL Profile Finding (see explain plans section below)
A potentially better execution plan was found for this statement.
Recommendation (estimated benefit: 99.99%)
------------------------------------------
- Consider accepting the recommended SQL profile. A SQL plan baseline
corresponding to the plan with the SQL profile will also be created.
execute dbms_sqltune.accept_sql_profile(task_name => 'TASK_10833',task_owner => 'SYS', replace => TRUE);
Note:Here if you see if the estimated benefit is more that 70% or 80% or 90% you can plug or execute the above sql profile.
Validation results
------------------
The SQL profile was tested by executing both its plan and the original plan
and measuring their respective execution statistics. A plan may have been
only partially executed if the other could be run to completion in less time.
Original Plan With SQL Profile % Improved
------------- ---------------- ----------
Completion Status: COMPLETE COMPLETE
Elapsed Time (s): 7.165564 .001346 99.98 %
CPU Time (s): 7.115895 .001354 99.98 %
User I/O Time (s): 0 0
Buffer Gets: 1296489 90 99.99 %
Physical Read Requests: 0 0
Physical Write Requests: 0 0
Physical Read Bytes: 0 0
Physical Write Bytes: 0 0
Rows Processed: 7 7
Fetches: 7 7
Executions: 1 1
4- Restructure SQL finding (see plan 1 in explain plans section)
----------------------------------------------------------------
An expensive "UNION" operation was found at line ID 7 of the execution plan.
Recommendation
--------------
- Consider using "UNION ALL" instead of "UNION", if duplicates are allowed
or uniqueness is guaranteed.
EXPLAIN PLANS SECTION
-------------------------------------------------------------------------------
1- Original With Adjusted Cost
------------------------------
Plan hash value: 4268187734
-------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |
-------------------------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 7 | 504 | 352K (1)| 00:00:14 | | |
| 1 | SORT ORDER BY | | 7 | 504 | 352K (1)| 00:00:14 | | |
| 2 | NESTED LOOPS | | 7 | 504 | 352K (1)| 00:00:14 | | |
| 3 | NESTED LOOPS | | 7 | 504 | 352K (1)| 00:00:14 | | |
2- Using SQL Profile
--------------------
Plan hash value: 864480126
-------------------------------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |
-------------------------------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 7 | 504 | 74 (11)| 00:00:01 | | |
| 1 | SORT ORDER BY | | 7 | 504 | 74 (11)| 00:00:01 | | |
| 2 | NESTED LOOPS | | 7 | 504 | 73 (10)| 00:00:01 | | |
| 3 | NESTED LOOPS | | 7 | 504 | 73 (10)| 00:00:01 | | |
ENF OF THE REPORT.........
3rd Method:
Problematic sql id is – g13kaky245z75
1. Create Tuning Task
DECLARE
l_sql_tune_task_id VARCHAR2(100);
BEGIN
l_sql_tune_task_id := DBMS_SQLTUNE.create_tuning_task (
sql_id => 'g13kaky245z75',
scope => DBMS_SQLTUNE.scope_comprehensive,
time_limit => 500,
task_name => 'g13kaky245z75_tuning_task11',
description => 'Tuning task1 for statement g13kaky245z75');
DBMS_OUTPUT.put_line('l_sql_tune_task_id: ' || l_sql_tune_task_id);
END;
/
2. Execute Tuning task:
EXEC DBMS_SQLTUNE.execute_tuning_task(task_name => 'g13kaky245z75_tuning_task11');
3. Get the Tuning advisor report.
set long 65536
set longchunksize 65536
set linesize 100
select dbms_sqltune.report_tuning_task('g13kaky245z75_tuning_task11') from dual;
4. Get list of tuning task present in database:
SELECT TASK_NAME, STATUS FROM DBA_ADVISOR_LOG WHERE TASK_NAME ;
5. Drop a tuning task:
execute dbms_sqltune.drop_tuning_task('g13kaky245z75_tuning_task11');
select dbms_sqltune.report_tuning_task(:task_name) as recommendations from dual;
spool off
Check new profile status.
column name format a30;
column category format a15;
column status format a15;
select name, category, status from dba_sql_profiles where name='SYS_SQLPROF_0384724bddc80002';
NAME CATEGORY STATUS
------------------------------ --------------- ---------------
sql_profile_for_22zq47mj49f7w DEFAULT ENABLED
SQL> select name, category, status,sql_text from dba_sql_profiles where sql_text like '%SELECT /*+ parallel_index(A,4)%';
Creating New SQL Baseline
If you found specific plan is good enough to set the baseline, you can accept the tuning result by this:
SQL> exec dbms_sqltune.create_sql_plan_baseline(task_name => 'SQLTUNE_44zq47mj49f7w_0105_01', owner_name => 'SYS', plan_hash_value => 1283456102);
Enjoy the work and do like me if you like this article!!!
SQL Tuning Health-Check Script
What is SQL Tuning Health-Check Script?
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 checks Cost-based Optimizer (CBO) statistics, schema object metadata, configuration parameters and other elements that may influence the performance of the one SQL being analyzed.
The intention of SQLHC is to allow users to avoid SQL Performance from being affected by avoidable problems by ensuring that the environment that an individual SQL runs in is sound.
It does this while leaving "no database footprint" ensuring it can be run on all systems.
What is the history of SQLHC?
SQLHC is a subset of the SQL used by the SQLTXPLAIN script:
but unlike that tool, has no database footprint.
It is a relatively short SQL script that generates a HTML output. It extracts database statistic information using selects or standard APIs (such as DBMS_XPLAN) from the database and combines that with Automatic Workload Repository (AWR) output if the correct licenses are available.
Download the Download the SQL Tuning Health-Check Script
https://support.oracle.com/epmos/main/downloadattachmentprocessor?parent=DOCUMENT&sourceId=1366133.1&attachid=1366133.1:SQLHC_LATEST_12108&clickstream=yes
SQLHC does not require installation and will not add/modify any objects in database.
2. 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.
Please Note: SQL Tuning Advisor can take up to 20 minutes to run. Please don't interrupt it with ctrl-C
For example:
sqlplus / as sysdba
SQL> START sqlhc.sql "T" (sql_id)
When executed for one SQL_ID, this script generates an HTML report with the results of a set of health-checks around the one SQL statement provided. You can find the SQL_ID of a statement from an AWR or ASH report or you can select it from the database using the V$SQL view.
Tuesday, July 4, 2023
Oracle enterprise manager OEM 13c
Introduction to Oracle enterprise manager OEM 13c and its history
Oracle Enterprise Manager (OEM) has built-in management capabilities that enable DBAs and Apps DBAs to monitor and manage the complete Oracle IT infrastructure including the Databases and Applications on Cloud as well as On-Premise from a single console.
The Management Agent on each monitored host monitors the status, health, and
performance of all managed components (targets) on that host. If a target goes down, or if a performance metric crosses a warning or critical threshold, an event is triggered and sent to Enterprise Manager. Administrators or any interested party can be notified of the triggered event through the Enterprise Manager notification system.
Sunday, July 2, 2023
How to Convert Physical Standby To Snapshot Standby
What is snapshot standby:
Snapshot standby is a feature in Oracle 11g that allows doing a read-write operation on the standby database.
i. e we can convert the physical standby database to snapshot standby. On that, we can do all types of testing or can be used as a development database
(which is an exact replication of production ). Once the testing is over we can again convert the snapshot database to physical standby.
Once it is converted physical standby database, whatever changes were done to the snapshot standby will be reverted.
Step:1 Check both primary and standby role.
primary: SQL> select name, open_mode, database_role from v$database;
standby: SQL> select name, open_mode, database_role from v$database;
Step 2:- Check the archived sequence in standby,
select thread#,max(sequence#) from v$archived_log group by thread#;
Step 3:- Check the flashback status and db_recovery_file_set location,
SQL> select flashback_on from v$database;
FLASHBACK_ON
--------------
YES
SQL> show parameter db_recovery_file_dest
NAME TYPE VALUE
-------------------------- ----------- ------------------------------
db_recovery_file_dest string /u01/app/oracle/fast_recovery_area/
db_recovery_file_dest_size big integer 8016M
Step 4: In standby side,stop the mrp process.
SQL> alter database recover managed standby database cancel;
Database altered.
Step:5 Bounce the database and keep in mount stage,
SQL> shut immediate
ORA-01109: database not open
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.
Total System Global Area 838860800 bytes
Fixed Size 8626240 bytes
Variable Size 645926848 bytes
Database Buffers 180355072 bytes
Redo Buffers 3952640 bytes
Database mounted.
Step:5 Convert to snapshot standby database
SQL> alter database convert to snapshot standby;
Database altered.
Step:6 Open the standby database in READ/WRITE mode
SQL> alter database open;
Database altered.
Step:7 Check the DATABASE_ROLE and OPEN_MODE,
SQL> select status, instance_name, database_role,open_mode from v$database, v$instance;
Step:8 Testing on the snapshot standby database,
----Testing on the snapshot standby database--------------
Step:9 Both side verify the archived sequence
Standby:
SQL> select thread#,max(sequence#) from v$archived_log group by thread#;
SQL> select process,status,sequence# from v$managed_standby;
Step:10 In Standby Side,bounce and mount the database
SQL> shut immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.
Total System Global Area 838860800 bytes
Fixed Size 8626240 bytes
Variable Size 645926848 bytes
Database Buffers 180355072 bytes
Redo Buffers 3952640 bytes
Database mounted.
Step:11 Convert the snapshot standby database to physical standby database,
SQL> alter database convert to physical standby;
Database altered.
Step:12 Bounce the database,
SQL> shut immediate
ORA-01109: database not open
Database dismounted.
ORACLE instance shut down.
SQL> startup
ORACLE instance started.
Total System Global Area 838860800 bytes
Fixed Size 8626240 bytes
Variable Size 645926848 bytes
Database Buffers 180355072 bytes
Redo Buffers 3952640 bytes
Database mounted.
Database opened.
Step:13 Check the standby database_role and mode.
SQL> select status,instance_name,database_role,open_mode from v$database,v$Instance;
Step:14 Enable the MRP process
SQL> alter database recover managed standby database disconnect from session;
Database altered.
Note: After convert back to Physical standby database once again restart the MRP process
***************************************
Convert Physical Standby To Snapshot Standby Using Dgmgrl
***************************************
oracsdb01:
oracle@hostname1:/home/oracle>srvctl status database -d oracsdb01
Instance oracsdb01 is running on node hostname1
Instance oracsdb02 is running on node hostname2
SQL> select name,open_mode,database_role,log_mode from v$database;
NAME OPEN_MODE DATABASE_ROLE LOG_MODE
--------- -------------------- ---------------- ------------
oracpdb01 MOUNTED PHYSICAL STANDBY ARCHIVELOG
SQL> set pagesize 300 linesize 300
SELECT ARCH.THREAD# "Thread", ARCH.SEQUENCE# "Last Sequence Received", APPL.SEQUENCE# "Last Sequence Applied", (ARCH.SEQUENCE# - APPL.SEQUENCE#) "Difference"
FROM
SQL> 2 3 (SELECT THREAD# ,SEQUENCE# FROM V$ARCHIVED_LOG WHERE (THREAD#,FIRST_TIME ) IN (SELECT THREAD#,MAX(FIRST_TIME) FROM V$ARCHIVED_LOG GROUP BY THREAD#)) ARCH,
(SELECT THREAD# ,SEQUENCE# FROM V$LOG_HISTORY WHERE (THREAD#,FIRST_TIME ) IN (SELECT THREAD#,MAX(FIRST_TIME) FROM V$LOG_HISTORY GROUP BY THREAD#)) APPL
4 5 WHERE
ARCH.THREAD# = APPL.THREAD#
6 7 ORDER BY 1;
Thread Last Sequence Received Last Sequence Applied Difference
---------- ---------------------- --------------------- ----------
1 93980 93980 0
2 118561 118561 0
SQL> show parameter db_recovery
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_recovery_file_dest string +RECO
db_recovery_file_dest_size big integer 2500G
SQL> select flashback_on from v$database;
FLASHBACK_ON
------------------
NO
SQL> alter database flashback on;
alter database flashback on
*
ERROR at line 1:
ORA-01153: an incompatible media recovery is active
SQL> recover managed standby database cancel;
Media recovery complete.
SQL> alter database flashback on;
Database altered.
SQL>select flashback_on from v$database;
FLASHBACK_ON
------------------
YES
SQL> alter database recover managed standby database using current logfile disconnect from session;
Database altered.
Step2: connect to the
DGMGRL> show configuration;
Configuration - oracpdb01_DG_CONFIG
Protection Mode: MaxPerformance
Members:
oracpdb01- Primary database
oracsdb01- Physical standby database
Fast-Start Failover: DISABLED
Configuration Status:
SUCCESS (status updated 55 seconds ago)
DGMGRL> validate database oracsdb01
Database Role: Physical standby database
Primary Database: oracpdb01
Ready for Switchover: Yes
Ready for Failover: Yes (Primary Running)
Flashback Database Status:
oracpdb01: Off
oracsdb01: Off
Managed by Clusterware:
oracpdb01: YES
oracsdb01: YES
Temporary Tablespace File Information:
oracpdb01 TEMP Files: 10
oracsdb01 TEMP Files: 5
Current Log File Groups Configuration:
Thread # Online Redo Log Groups Standby Redo Log Groups Status
(oracpdb01 ) (oracsdb01 )
2 5 3 Insufficient SRLs
Future Log File Groups Configuration:
Thread # Online Redo Log Groups Standby Redo Log Groups Status
(oracsdb01 ) (oracpdb01 )
1 5 5 Insufficient SRLs
2 3 0 Insufficient SRLs
Warning: standby redo logs not configured for thread 2 on oracpdb01
Step3) Convert physical to snapshot standby.
DGMGRL> convert database oracsdb01 to snapshot standby;
Converting database "oracsdb01 " to a Snapshot Standby database,
please wait...
Database "oracsdb01 " converted successfully
DGMGRL> show configuration
SQL> select open_mode,database_role from v$database;
Now the database is open in read write mode.
So you can do any changes or testing on the database.
Once your activity is done, you can revert it back to physical standby using below command.
step4)
DGMGRL> convert database oracsdb01 to physical standby;
DGMGRL> show configuration;
Enjoy the work and do like me if you like this article!!!
Latest Posts
Number of failed login attempts exceeds threshold value
Number of failed login attempts exceeds threshold value alert message comes from OEM. How to check what and which user is causing this? how ...
Popular Posts
-
Resolving Archived Redo Log Gaps Using Incremental Backups Imagine that due to the network failure, some archived redo log fileswere not sh...
-
Why Is My Query Sometimes Slower Than Other Times with Higher Consistent Gets Although No Change in Execution Plan? (Doc ID 1558349.1) SYM...
-
To check instance-wise total allocated, total used TEMP for both rac and non-rac set lines 152 col FreeSpaceGB format 999.999 col UsedSp...


