Oracle DBA Real Time Interview Questions
Oracle DBA Real Time Interview Questions
7- Check the latest Archivelog and Full Backup are done or not
Use the following script to check Backups.
SELECT TO_CHAR (start_time, 'DD-MM-YYYY HH24:MI:SS') start_time, input_type,
status, ROUND (elapsed_seconds / 3600, 1) time_hr,INPUT_BYTES/1024/1024/1024
IN_GB,OUTPUT_BYTES/1024/1024/1024 OUT_GB ,OUTPUT_DEVICE_TYPE FROM
v$rman_backup_job_details WHERE START_TIME > SYSDATE - 3 ORDER BY
start_time DESC;
8- Check any session blocking the other session ( blocking session and Lock control )
9- Check the DBMS jobs running or not and check the status of the Jobs
Use the following script to check Scheduler jobs state.
-- Failed Scheduled Jobs
SELECT owner, job_name,status,LOG_DATE, ERROR#, ( EXTRACT (SECOND FROM
run_duration) /60 + EXTRACT (MINUTE FROM run_duration) + EXTRACT (HOUR
FROM run_duration) * 60 + EXTRACT (DAY FROM run_duration) * 60 * 24)
MINUTES,ADDITIONAL_INFO
FROM dba_scheduler_job_run_details
WHERE LOG_DATE > SYSDATE - 1 AND status != 'SUCCEEDED' ORDER BY 1 ASC,
4 DESC;
11- Check the Performance Page of Enterprise Manager or Enterprise Manager Cloud
Control
Open Performance Page of Enterprise manager Cloud Control as follows to check
Performance.
12- Check the TOP session and TOP activity of database.
Open TOP Activity Page of Enterprise manager Cloud Control as follows to check TOP
Activity.
13- Detect lock objects
Use the following script to check Lock objects and tables.
SELECT B.Owner, B.Object_Name, A.Oracle_Username, A.OS_User_Name
FROM gv$Locked_Object A, All_Objects B
WHERE A.Object_ID = B.Object_ID;
14- Check the SQL query consuming lot of resources ( CPU and Disk Resources )
Use the following script to check TOP CPU and Disk SQL Statements.
15- Check the usage of physical RAM and SGA – Paging or Swapping exist or not.
[oracle@msddbadm01 ~]$ free -m
Daily Activity
Weekly Activity
Monthly Activity
1. Check the database size & compare it previous size to find the exact growth of the database
2. Find Tablespace Status, segment management, initial & Max Extents and Extent Management
3. Check location of data file also check auto extendable or not
4. Check default tablespace & temporary tablespace of each user
5. Check the Indexes which is not used yet
6. Check the Extents of each object and compare if any object extent are overridden which is define at
tablespace level
7. Tablespace need coalescing
8. Check the overall database statistics
9. Trend Analysis of objects with tablespace, last analyzed, no. of Rows, Growth in days & growth in KB
Nightly Activity
Once the Operating system starts and finish the boot scrap process it reads /etc/init.d file via
the initialisation daemon called init or init.d. The init tab file is the one it triggers oracle high
availability service daemon.
1. OLR – Is the first file to be read and opened. This file is local and this file contains
information regarding where the voting disk is stored
and information to startup the ASM. (e.g ASM DiscoveryString)
2. VOTING DISK – This is the second file to be opened and read, this is dependent on
only OLR being accessible.
ASM starts after CSSD or ASM does not start if CSSD is offline (i.e voting file missing)
Voting disks are placed directly on ASMDISK. Oracle Clusterware will store the votedisk on the
disk within a disk group that holds the Voting Files.
Oracle Clusterware does not rely on ASM to access the Voting Files, which means Oracle
Clusterware does not need of Diskgroup to read and write on ASMDISK. It is possible to check
for existence of voting files on a ASMDISK using the V$ASM_DISK column VOTING_FILE.
So, voting files not depend of Diskgroup to be accessed, does not mean that the diskgroup is not
needed, diskgroup and voting file are linked by their settings.
3. OCR – Finally the ASM Instance starts and mount all Diskgroups, then Clusterware Deamon
(CRSD) opens and reads the OCR which is stored on Diskgroup.
As Per Oracle doc below are the high level steps for clusterware initialization.
INIT spawns init.ohasd (with respawn) which in turn starts the OHASD process (Oracle High
Availability Services Daemon). This daemon spawns 4 processes.
What is OLR?
In Oracle Clusterware 11g Release 2 an additional component related to the OCR called the
Oracle Local Registry (OLR) is installed on each node in the cluster.
The OLR is a local registry for node specific resources. Location of OLR is
CRS_HOME/cdata/.olr and Location of olr is stored in /etc/oracle/olr.loc
This is the first file red to obtain the information to start the CRS stack
The Oracle RAC solution delivers 24/7 database availability, performance, and
scalability.
Cache Fusion is the key memory feature that enables Oracle RAC performance,
and the new Transparent Application Failover (TAF) is what applications use to
sync up with Oracle RAC availability.
To successfully re-master the cluster services, Oracle RAC keeps track of all
resources and resource states on each node and then uses this information to restart
these resources on a backup node.
These processes also manage the state of in-flight transactions and work with TAF
to either restart or resume the transactions on the new node.
Transparent Application Failover (TAF) is what applications use to sync up with Oracle RAC
availability.TAF in the database reroutes application clients to an available database node in
the cluster when the connected node fails. Application clients do not see error messages
describing loss of service.
In the above configuration, if the users connection to Node 1 dies, their transaction is rolled
back but they can continue work without having to manually reconnect.
For an application to use TAF, it must use failover-aware API calls from the
Oracle Call Interface (OCI). Inside OCI are TAF callback routines that can be used
to make any application failover-aware.
While the concept of failover is simple, providing an apparent instant failover can
be extremely complex, because there are many ways to restart in-flight
transactions. The TAF architecture offers the ability to restart transactions at either
the transaction (SELECT) or session level:
Oracle TAF also offers choices on how to restart a failed transaction. The Oracle
DBA may choose one of the following failover methods:
Currently, TAF will fail over standard SQL SELECT statements that have been
caught during a node crash in an in-flight transaction failure. In the current release
of TAF, however, TAF must restart some types of transactions from the beginning
of the transaction.
The following types of transactions do not automatically fail over and must be
restarted by TAF:
bubba.world =
(DESCRIPTION_LIST =
(FAILOVER = true)
(LOAD_BALANCE = true)
(DESCRIPTION =
(ADDRESS =
(PROTOCOL = TCP)
(HOST = redneck)(PORT = 1521))
(CONNECT_DATA =
(SERVICE_NAME = bubba)
(SERVER = dedicated)
(FAILOVER_MODE =
(BACKUP=cletus)
(TYPE=select)
(METHOD=preconnect)
(RETRIES=20)
(DELAY=3)
)
)
)
TYPE=select. This tells TAF to restart all in-flight transactions from the beginning of the transaction (and not to track
cursor states within each transaction).
METHOD=preconnect. This directs TAF to create two connections at transaction startup time: one to the primary
bubba database and a backup connection to the clients database. In case of instance failure, the clients database will
be ready to resume the failed transaction.
Performance Advantages
The main advantage -- and the purpose -- of partitioning is said to be to provide
performance advantages. It also enables better manageability for various
applications. The objective of partitioning is to divide database objects, such as
tables, indexes and other objects into smaller, manageable pieces.
COUNT(*)
----------
954598
Index created.
2. Alter table modify to partition the table.( partition key is column CREATED )
alter table BSSTDBA.ORDER_TAB modify
PARTITION BY RANGE (CREATED)
(partition created_2105_p8 VALUES LESS THAN (TO_DATE('01/09/2015', 'DD/MM/YYYY')),
partition created_2105_p9 VALUES LESS THAN (TO_DATE('01/10/2015', 'DD/MM/YYYY')),
partition created_2105_p10 VALUES LESS THAN (TO_DATE('01/11/2015', 'DD/MM/YYYY')),
partition created_2105_p11 VALUES LESS THAN (TO_DATE('01/12/2015', 'DD/MM/YYYY')),
partition created_2105_p12 VALUES LESS THAN (TO_DATE('01/01/2016', 'DD/MM/YYYY')),
PARTITION Created_MX VALUES LESS THAN (MAXVALUE)) ONLINE;
This activity will take some time depending upon amount of data table has.
While this alter statement is running, I have started running DML activities on the same
table, To check whether it is impacting the DML activities.
SESSION 2:
insert into BSSTDBA.ORDER_TAB select * from BSSTDBA.ORDER_TAB;
SID > 7
SQL_TEXT> insert into BSSTDBA.ORDER_TAB select * from BSSTDBA.ORDER_TAB;
We can see that the insert statement(SID 7), is blocking the alter table
command(SID 490), not the other way around. It means during this partition conversion
activity, if any DML requests are coming, then it will allow them to complete their
request. This may slow down the partition conversion time, But it won’t impact the
application. Once ALTER TABLE MODIFY is completed. Check the whether table was
partitioned properly or not.
SQL> select partition_name,high_value from dba_tab_partitions where
table_name='ORDER_TAB';
PARTITION_NAME HIGH_VALUE
-----------------------
--------------------------------------------------------------------------------
CREATED_2105_P10 TO_DATE(' 2015-11-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS',
'NLS_CALENDAR=GREGORIA
CREATED_2105_P11 TO_DATE(' 2015-12-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS',
'NLS_CALENDAR=GREGORIA
CREATED_2105_P12 TO_DATE(' 2016-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS',
'NLS_CALENDAR=GREGORIA
CREATED_2105_P8 TO_DATE(' 2015-09-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS',
'NLS_CALENDAR=GREGORIA
CREATED_2105_P9 TO_DATE(' 2015-10-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS',
'NLS_CALENDAR=GREGORIA
CREATED_MX MAXVALUE
20 rows selected.
INDEX_NAME PARTITIONED
------------------- ------------
ORDER_TAB_IND1 NO
ORDER_TAB_IND2 YES
ORDER_TAB_IND2 -
--------------------
20 rows selected.
Online Conversion of a Non-Partitioned Table to a
Partitioned Table in Oracle Database 12c Release 2
(12.2)
In previous releases you could partition a non-partitioned table using EXCHANGE
PARTITION or DBMS_REDEFINITION in an "almost online" manner, but both methods
required multiple steps. Oracle Database 12c Release 2 makes it easier than ever to
convert a non-partitioned table to a partitioned table, requiring only a single
command and no downtime.
Setup
Partition a Table
Composite Partition (Sub-Partition) a Table
Restrictions
Related articles.
Setup
Create and populate a test table. You will need to repeat this between each test.
CREATE TABLE t1 (
id NUMBER,
description VARCHAR2(50),
created_date DATE,
CONSTRAINT t1_pk PRIMARY KEY (id)
);
INSERT INTO t1
SELECT level,
'Description for ' || level,
ADD_MONTHS(TO_DATE('01-JAN-2017', 'DD-MON-YYYY'), -
TRUNC(DBMS_RANDOM.value(1,4)-1)*12)
FROM dual
CONNECT BY level <= 10000;
COMMIT;
CREATED_D COUNT(*)
--------- ----------
01-JAN-15 3340
01-JAN-16 3290
01-JAN-17 3370
SQL>
Partition a Table
We convert the table to a partitioned table using the ALTER TABLE ...
MODIFY command. Here are some basic examples of this operation. Adding
the ONLINE keyword allows the operation to be completed online, meaning most
DML operations can continue during the conversion.
-- Online operation.
ALTER TABLE t1 MODIFY
PARTITION BY RANGE (created_date) (
PARTITION t1_part_2015 VALUES LESS THAN (TO_DATE('01-JAN-2016','DD-MON-
YYYY')),
PARTITION t1_part_2016 VALUES LESS THAN (TO_DATE('01-JAN-2017','DD-MON-
YYYY')),
PARTITION t1_part_2017 VALUES LESS THAN (TO_DATE('01-JAN-2018','DD-MON-
YYYY'))
) ONLINE;
We gather statistics and check the table partitions. We can see the data has been
split between the partitions as expected.
-- Gather statistics.
EXEC DBMS_STATS.gather_table_stats(NULL, 'T1');
SQL>
When we check the indexes we see the index on the CREATED_DATE column has been
converted to a locally partitioned index. By default all prefixed indexes, an index with
the partition key in the column list, will be converted to locally partitioned indexes.
All indexes are left in a valid state at the end of the operation.
-- Check indexes.
SELECT index_name, partitioned, status
FROM user_indexes
ORDER BY 1;
SQL>
SQL>
The offline operation is similar, but we omit the ONLINE keyword. The outcome will be
the same as the online operation, but DML will not be available during the operation.
-- Offline operation.
ALTER TABLE t1 MODIFY
PARTITION BY RANGE (created_date) (
PARTITION t1_part_2015 VALUES LESS THAN (TO_DATE('01-JAN-2016','DD-MON-
YYYY')),
PARTITION t1_part_2016 VALUES LESS THAN (TO_DATE('01-JAN-2017','DD-MON-
YYYY')),
PARTITION t1_part_2017 VALUES LESS THAN (TO_DATE('01-JAN-2018','DD-MON-
YYYY'))
);
We can influence the index conversion using the UPDATE INDEXES clause. This can
indicate the type of index to be rebuilt as part of the operation, as well as some
storage parameters. In the following example we want the index on
the CREATED_DATE column to remain as a global index.
After running the last example we can see the indexes as both non-partitioned, and
as a result there are no index partitions.
-- Check indexes.
SELECT index_name, partitioned, status
FROM user_indexes
ORDER BY 1;
SQL>
no rows selected
SQL>
The sub-partitions of the table and partitioned index can be displayed using the
following queries.
SQL>