ManualiOracle.it
  
 
> Quizzes > Quizzes 2010-2014 - Oracle Best Pratices
 
 
 
 
 


In the page Prices and Donations, you can find how to have the solutions of the quizzes.

Nella pagina Prezzi Quiz potete vedere come avere le soluzioni dei quiz level 3.


If it is not specified, the commands must be executed connected as SYS.
About the solutions:
- could be more than one. Here is one solution that often takes into account of the performance tuning
- they could change because of the Oracle version (eg. Oracle 8.0 is quite different than Oracle 11g!)
- it is not warranted to be error-free in all the Oracle environments


December 2014 - Db Objects

Level (*) : 1
Topic (*) : DBA



You have to find a query useful to find the objects created in the last 3 hours.
Result example:
 OWNER   OBJECT_NAME  SUBOBJECT_NAME  OBJECT_TYPE  CREATED
 ------- ------------ --------------- ------------ --------------
 LASSI   DIM_CIN      VIEW                         20141216 14:36
 LASSI   FACT_IDX     INDEX                        20141216 14:09
 LASSI2  FACT         INDEX                        20141216 14:08
Solution

You should use the DBA_OBJECTS view:
 SELECT owner, object_name, subobject_name, object_type, created 
 FROM  dba_objects 
 WHERE created>sysdate-3/24;




November 2014 - Invalid indexes

Level (*) : 2
Topic (*) : DBA/Progr



You have to find 3 queries that write the SQL commands to rebuild the invalid indexes contained in LASSI schema.
Query 1: it is about the not-partitioned indexes. Result example:
 COMMAND
 ------------------------------------
 alter index LASSI.DIMIC_PK rebuild;
 alter index LASSI.LOGMSG_IDX rebuild;
Query 2: it is about the partitioned indexes. Result example:
 COMMAND
 -------------------------------------------------------
 alter index LASSI.FSE_IDX rebuild partition P_20141029;
 alter index LASSI.FTR_IDX rebuild partition P_20141030;
Query 3: it is about the subpartitioned indexes. Result example:
 COMMAND
 -----------------------------------------------------------
 alter index LASSI.FS_IDX rebuild subpartition P_20141111_1;
 alter index LASSI.FT_IDX rebuild subpartition P_20141111_2;
Solution

You can use these 3 queries:
 SELECT  'alter index ' || owner || '.' || index_name || ' rebuild;'
 FROM dba_indexes
 WHERE owner = 'LASSI' and status = 'UNUSABLE';

 SELECT 'alter index ' || index_owner || '.' || index_name || ' rebuild partition ' ||
        partition_name || ';'
 FROM dba_ind_partitions
 WHERE index_owner = 'LASSI'  and status = 'UNUSABLE';

 SELECT 'alter index ' || index_owner || '.' || index_name || ' rebuild subpartition ' ||
        subpartition_name || ' parallel 4;'  -- It doesn't change the index degree!
 FROM dba_ind_subpartitions
 WHERE index_owner = 'LASSI' AND STATUS = 'UNUSABLE';




October 2014 - Oracle dictionary

Level (*) : 3
Topic (*) : DBA/Progr



You have to find 2 queries that, using a TABLE_NAME, find out which indexes it has and in which columns they are.

Example:
In the db, you have 2 tables called FMAP: one in the schema LA and one in the schema XXX.
The result of the queries must be something like this:
 TABLENAME INDEXNAME   INDEX_TYPE  UNIQUENES  BLEVEL DistinctKeys LAST_ANAL PARTITIONED
 --------- ----------- ----------- --------- ------- ------------ --------- -----------
 LA.FMAP   LA.FMAP_IDX  NORMAL     NONUNIQUE       2     12589039 14-OTT-14  NO
 XXX.FMAP  XXX.FMAP_PK  NORMAL     UNIQUE          2     65640917 13-OTT-14  NO

 TABLENAME INDEXNAME    Column_name   C_Position
 --------- ------------ ------------- ----------
 LA.FMAP   LA.FMAP_IDX  AOD                   1
 LA.FMAP   LA.FMAP_IDX   LE                   2
 LA.FMAP   LA.FMAP_IDX    RIC                 3
 XXX.FMAP  XXX.FMAP_PK  AOD                   1
 XXX.FMAP  XXX.FMAP_PK   LE                   2
 XXX.FMAP  XXX.FMAP_PK    VAR_SCEN            3
 XXX.FMAP  XXX.FMAP_PK     NAME               4




September 2014 - Materialized views

Level (*) : 3
Topic (*) : DBA/Progr



You work in an Oracle 11.2 database and looking at an AWR report, you see that some of the "Top SQL Statements" are DELETE commands on materialized views.
After an investigation, you get that this happens during their refresh.

Using the DBMS_MVIEW package, how can you transform these DELETEs in TRUNCATE commands?
And tell one MOS (metalink) note that explains it.




August 2014 - Crontab

Level (*) : 2
Topic (*) : DBA



You see an Oracle db in a Linux machine. In the crontab, you have this row:
 00 1 * * * /app/ora11/data/STAT/analyze.ksh > /app/ora11/data/STAT/stat.nohup 2>&1
So, when this script is launched?

Solution

The script will be launched every day at 1 am.
This is the meaning of the crontab format :
  * * * * * *
  | | | | | | 
  | | | | | +-- Year              (range: 1900-3000)
  | | | | +---- Day of the Week   (range: 1-7, 1 standing for Monday)
  | | | +------ Month of the Year (range: 1-12)
  | | +-------- Day of the Month  (range: 1-31)
  | +---------- Hour              (range: 0-23)
  +------------ Minute            (range: 0-59)



July 2014 - Global Indexes

Level (*) : 3
Topic (*) : DBA



You have to find a query useful to find the global indexes (and their size) contained in the LASSI schema inside your database.




June 2014 - Partitioned Table

Level (*) : 2
Topic (*) : DBA



You are in Oracle 11.2 and you want to create an interval-partitioned table.
The table, called T1, has these columns:
 AOD integer,
 cod varchar2(10),
 cvalue number
In the AOD column there are integer values instead of date values.
For example in this column, you have values such as 20131201, 20140101, 20140102, 20140201, etc.

You want the partitioning key is the column AOD and you want a partition every year from 2013.
So you'll have the value 20131201 in the p2013 partition, the values 20140101, 20140102 and 20140201 in p2014 partition, etc...
Write the T1 table (interval-partitioned by AOD column) creation script.

Solution

The T1 creation script could be:
  CREATE TABLE t1
  ( aod INTEGER NOT NULL,
    cod VARCHAR2(10) NOT NULL,
    cvalue NUMBER
   )
  PARTITION BY RANGE (aod) 
  INTERVAL(10000) 
  (  
    PARTITION p2013 VALUES LESS THAN (20140101)
   );



May 2014 - Sql_id and explain access plan

Level (*) : 3
Topic (*) : DBA



You are working in an Oracle RAC db.
You have the query identified by sql_id = 3s0kd398u2pxx.
Using the AWR tables, you have to find a query in order to know if in the last 2 days this sql_id has changed explain access plan.
For example, you want a result like this:
 SNAP_ID NODE BEGIN_INTERVAL END_INTERVAL   PlanHashVal EXECUTS  AvgBufGets Avg_DiskRds
 ------- ---- -------------- -------------- ----------- ------- ----------- -----------
 Sql_id       3s0kd398u2pxj
 845        2 20140522 12.00 20140522 12.26  3847028022       1     811,955           0
 851        2 20140522 16.04 20140522 17.00  2247069225       1     515,732      21,028
 852        1 20140522 17.00 20140522 18.00  2247069225       1     525,600           2
 852        2 20140522 17.00 20140522 18.00   617702193       1   1,257,942           0
 852        2 20140522 17.00 20140522 18.00  2247069225       1     523,476           0
 872        1 20140523 13.00 20140523 14.00   530248343       0  93,634,900     195,400




April 2014 - Instances in a RAC

Level (*) : 1
Topic (*) : DBA



You are working in an Oracle RAC with 2 instances.
You want to know some simple info about them.
So you have to find out the query in order to know this info:
 INSTANCE_NAME  HOST_NAME   STARTUP_TIME
 -------------- ----------- ------------------
 expo_i1        lorsvil61   17-APR-14 18:07:45 
 expo_i2        lorsvil62   30-MAR-14 19:53:48
Solution

You should use the global view GV$INSTANCE:
 SELECT instance_name, host_name, startup_time
 FROM gv$instance;



March 2014 - Partitioned Tables

Level (*) : 3
Topic (*) : Progr



In your db, you have many partitioned tables with RANGE partitions: one partition a day.
Example:
 TABLE_NAME     PARTITION_NAME
 -------------- ----------------
 U1.TAB_LOR     TAB_LOR_20131201
 U1.TAB_LOR     TAB_LOR_20131202
 ...
 U1.TAB_LOR     TAB_LOR_20140331
 U1.TAB_LOR     TAB_LOR_20140401
 ...
 U1.TAB_LOR     TAB_LOR_PMAX
 U2.TA_PIPPO    PART_20131201
 U2.TA_PIPPO    PART_20131202
 ...
 U2.TA_PIPPO    PART_20140331
 U2.TA_PIPPO    PART_PMAX
The rules about the partition names are:
- at the end of the name is the date (partition key)
- every table have a partition, with high_value MAXVALUE, named %PMAX.

You have to write a query to check if all the tables have all the partitions from this month until Aug-2013.
You must check it for all the partitioned (and/or subpartitioned) tables on U1 and U2 schemas.
For example, you result must be something like this:
 TABLENAME    201308    09    10    11    12   201401    02    03    04
 ---------- -------- ----- ----- ----- ----- -------- ----- ----- -----
 U1.TAB_LOR       31    30    31    30    31       31    28    31    19
 U1.TAB_TEST      31    30    31    30    31       31    28    31    30
 U2.TA_PIPPO       0     0    12    30    31       31    28    31     0
 U2.EXPO           0    30    31    30    31       31    28    31    30




February 2014 - O.S. files visible from db

Level (*) : 3
Topic (*) : Progr



From the database, you want to see which O.S. files are in a directory, their size and the time of the last update of them.
You have decided to do it using Java.
You want to write these information inside a table like this:
 FILENAME               SIZE    FILE_TIME
 ---------------------- ------- ------------------
 LASSI_VAR_ERR.csv	39	20-FEB-14 15:47:03
 MANUALIORACLE_26.log	8136	04-FEB-14 10:37:28
 LORIS_26932.log	20523	06-FEB-14 16:38:14
Explain all the steps you have to do in order to obtain it. And write the Oracle grants you need.




January 2014 - Space Allocation

Level (*) : 2
Topic (*) : DBA



Ten minutes ago you have created the empty table TAB1.
You check inside the dictionary views, so you find the TAB1 inside the DBA_TABLES and the DBA_OBJECTS.
But you don't find it inside the DBA_SEGMENTS.

Questions:
- which Oracle feature do it?
- from which Oracle version can it happen?
- which Oracle parameter you should modify in order to change this behaviour (as the older Oracle version)?
- if a single row is inserted into TAB1 and after you do a "truncate" of it, do you find TAB1 in the DBA_SEGMENTS?

Solution

Answers:
- deferred segment creation feature
- from 11g release 2
- deferred_segment_creation parameter
- yes, the table will be inside the DBA_SEGMENTS



December 2013 - Platform

Level (*) : 1
Topic (*) : DBA



Which query can you do in order to see the Operating System in your Oracle server?
For example, you must have a result like this:
  PLATFORM_NAME
  ----------------------------
  Microsoft Windows x86 64-bit
Solution

You should use the V$DATABASE view:
 SELECT platform_name 
 FROM v$database;



November 2013 - Pmon in Solaris

Level (*) : 3
Topic (*) : DBA



You work in some Unix-like machines.
In all of them, you have a db called DBLOR. The owner of the db files is called osdblor but you start the dbs with a user called ordblor.
If you want to see who has started the dbs, usually you correctly see this:
  lormachine > ps -ef | grep pmon
  ordblor   3095     1  0 Oct31 ?        00:30:57 ora_pmon_DBLOR
But in the Solaris machine, you see this "wrong" information:
  lormachine > ps -ef | grep pmon
  osdblor   3095     1  0 Oct31 ?        00:30:57 ora_pmon_DBLOR
If you check the listener process doing "ps -ef | grep tns", you don't have this problem.
Why this happens with the pmon process and not with the listener process?
Instead using "ps -ef", how can you see the correct information in Solaris?



October 2013 - NLS_INSTANCE_PARAMETERS

Level (*) : 3
Topic (*) : DBA



Your database is in Oracle 11.2 and you want to change the parameters contained in the view NLS_INSTANCE_PARAMETERS.
How can you do it?
Show all steps useful to do it.



September 2013 - AWR

Level (*) : 2
Topic (*) : DBA



These questions are about the AWR and its management through SQL*Plus :
- in which dictionary view can you see the frequence of the snapshots?
- how can you change this frequence? for example, if you want to have one snapshot every 30 minutes
- how can you do a "manual" snapshot?
- you want to launch the script awrrpt.sql about old information (10 days old). How can you do it?

Solution
 1) You see it in the DBA_HIST_WR_CONTROL view

 2) To change the frequence:

   exec dbms_workload_repository.modify_snapshot_settings (interval => 30)

 3) Manual snapshot (you can use it also on the RAC)

   exec DBMS_WORKLOAD_REPOSITORY.create_snapshot;   

 4) If you want AWR going back 10 days, before launching the script awrrpt.sql, you can
    do this:

   define num_days =10





August 2013 - Index Information

Level (*) : 3
Topic (*) : DBA



You have to write a query in order to find the indexes created during the last month.
About these indexes (partitioned and not), you have to find the following information:
 INDEXNAME               OBJECT_TYPE       TABLENAME            MB START_CREATION
 ----------------------- ----------------- ----------------- ----- --------------
 CRP_OWN.IDX_CA_IDX      INDEX             CRP_OWN.CA_IMPORT    25 20130826 11.36
 SYS.WRH$_SQLSTAT_INDEX  INDEX PARTITION   SYS.WRH$_SQLSTAT      0 20130826 23.20
 SYS.WRH$_WAITSTAT_PK    INDEX PARTITION   SYS.WRH$_WAITSTAT     0 20130826 23.20




July 2013 - Meta Script for RMAN

Level (*) : 3
Topic (*) : DBA/Progr



You have the RMAN recovery catalog database called REP1 in Oracle 10g.
In REP1, you have a lot of Oracle users and usually each user contain information about a backed up database.
You want to know which Oracle users contain recent information of the backed up databases.

E.g. when you launch that query, you have to receive something like:
 ENVIRONMENT   MAX_START_BCK_PIECE
 ------------- -------------------
 RMAN_DB1
 RMAN_DB2      2006-02-10 06.53
 RMAN_DB3      2006-12-06 14.14
 ...
 RMAN_DB8      2013-07-30 06.10
 RMAN_DB9      2013-07-30 07.00




June 2013 - Meta Script for ROLES

Level (*) : 3
Topic (*) : DBA/Progr



You have to find a query useful to give object privileges to the roles SELECT_ROLE and ALL_ROLE.
On all the tables of the LASSI schema, this script must give:
- grant SELECT to SELECT_ROLE
- grant ALL to ALL_ROLE

This query must be written to be executed from LASSI or from SYS:
E.g. when you launch that query connected as LASSI, you have to receive something like:
 GRANT_ON_OBJECT
 ---------------------------------------------------------
 grant SELECT on PESO_CLIENTI to SELECT_ROLE;
 grant ALL on PESO_CLIENTI to ALL_ROLE;

 grant SELECT on VENDITE to SELECT_ROLE;
 grant ALL on VENDITE to ALL_ROLE;

 grant SELECT on ATTIVAZIONI to SELECT_ROLE;
 grant ALL on ATTIVAZIONI to ALL_ROLE;
 ...
And when you launch the same query connected as SYS, you have to receive something like:
 GRANT_ON_OBJECT
 ---------------------------------------------------------------
 grant SELECT on LASSI.PESO_CLIENTI to SELECT_ROLE;
 grant ALL on LASSI.PESO_CLIENTI to ALL_ROLE;

 grant SELECT on LASSI.VENDITE to SELECT_ROLE;
 grant ALL on LASSI.VENDITE to ALL_ROLE;

 grant SELECT on LASSI.ATTIVAZIONI to SELECT_ROLE;
 grant ALL on LASSI.ATTIVAZIONI to ALL_ROLE;
 ...




May 2013 - Role problem

Level (*) : 2
Topic (*) : DBA/Progr



You have to find a query useful to discover when the roles have been created on the db.
E.g.
When you launch that query, you have to receive something like:
 ROLE          CREATION_TIME
 ------------- -------------------
 CONNECT       18/09/2012 11:36:12
 RESOURCE      18/09/2012 11:36:12
 DBA           18/09/2012 11:36:12
 ...

 UPDATE_ECOS   23/04/2013 10:41:16
 SELECT_EFF    23/04/2013 11:44:44
Solution

You can use this query:
  SELECT  r.role
         ,to_char(ctime,'dd/mm/yyyy hh24:mi:ss') creation_time
  FROM	dba_roles r,
	user$ u
  WHERE  r.ROLE = u.name
  ORDER BY ctime;




April 2013 - EM cloud control

Level (*) : 3
Topic (*) : DBA



You have an EM cloud control 12.1.0.2.
In the interface, you see an error like this:
  EMGC_GCDomain/instance1/ohs1 Target Down 
How can you see if that target is really down?
If this alert is false, how can you avoid that EM shows it again?
Which metalink note show this problem?



March 2013 - Data Guard

Level (*) : 2
Topic (*) : DBA



You have a dataguard environment in Oracle 11.2.
You have to find a query that has a result like this:

In the primary db ORCL:

Instance: ORCL             Status: OPEN         Startup: 20120912 22.24

 NAME                       DATABASE_ROLE        OPEN_MODE               PROTECTION_MODE      
 -------------------------- -------------------- ----------------------- -------------------- 
 SWITCHOVER_STATUS  STANDBY_BECAME_PRIMARY_SCN FS_FAILOVER_STATUS     FS_FAILOVER_OBSERVER_HOST
 ------------------ -------------------------- ---------------------- -------------------------
 Database: ORCL             PRIMARY              READ WRITE              MAXIMUM PERFORMANCE  
 TO STANDBY                           10468375 TARGET UNDER LAG LIMIT HOST_075

 Instance: ORCL             Status: OPEN         Startup: 20120912 22.24
In the physical standby STDBY:

 NAME                       DATABASE_ROLE        OPEN_MODE               PROTECTION_MODE      
 -------------------------- -------------------- ----------------------- -------------------- 
 SWITCHOVER_STATUS  STANDBY_BECAME_PRIMARY_SCN FS_FAILOVER_STATUS     FS_FAILOVER_OBSERVER_HOST
 ------------------ -------------------------- ---------------------- -------------------------
 Database: ORCL             PHYSICAL STANDBY     MOUNTED                 MAXIMUM PERFORMANCE  
 SWITCHOVER PENDING                          0 TARGET UNDER LAG LIMIT HOST_075

 Instance: STDBY            Status: MOUNTED      Startup: 20120912 22.42
In order to have a result like this, you should use the UNION operator.

Solution

You have to read v$database and v$instance.
Then the query is :
 SELECT  'Database: ' || name name, database_role, 
   open_mode, protection_mode, switchover_over, standby_became_primary_scn, 
   fs_failover_status, fs_failover_observer_host
 FROM v$database
   union all
 SELECT 
  'Instance: ' || instance_name, 'Status: ' || status, 
  'Startup: ' || to_char(STARTUP_TIME,'yyyymmdd hh24.mi'), null, null, null, 
  null, null
 FROM v$instance;





February 2013 - Hidden Parameters

Level (*) : 2
Topic (*) : DBA



You have to find a query in order to see some information about the Oracle hidden parameters that have the string 'shared_p' in their name.
The result must be something like this:
 NAME                            VALUE        DEFAULT   TYPE
 ------------------------------- ------------ --------- --------
 __shared_pool_size              1241513984   FALSE     6
 _dm_max_shared_pool_pct         1            TRUE      number
 _enable_shared_pool_durations   TRUE         TRUE      boolean
 _io_shared_pool_size            4194304      TRUE      6
 _shared_pool_max_size           0            TRUE      6
 _shared_pool_minsize_on         FALSE        TRUE      boolean
 _shared_pool_reserved_min_alloc 4400         TRUE      6
 _shared_pool_reserved_pct       5            TRUE      number
And, if you want to see all the hidden parameters?

Solution

The query is :
 select 	a.ksppinm name,
   b.ksppstvl value,
   b.ksppstdf default,
   decode
   (a.ksppity, 1,
   'boolean', 2,
   'string', 3,
   'number', 4,
   'file', a.ksppity) type
 from
  sys.x$ksppi a,
  sys.x$ksppcv b
 where
   a.indx = b.indx 
   and a.ksppinm like '\_%' escape '\'
   and lower(a.ksppinm) like '%shared_p%'
 order by 1;
If you want to see all the parameters, use the same query removing the row
   and lower(a.ksppinm) like '%shared_p%'





January 2013 - ORA-600 error

Level (*) : 3
Topic (*) : DBA/Progr



Your db is in Oracle 11.2.0.3.
You have a SQL statement like this:
  MERGE INTO table_1
	USING ( SELECT  a.col_1, 
			b.col_2
		  FROM  tab_2 a,
			tab_3 b,
			tab_4 c
....
....
Until few days ago, the result was fine but now you receive:
 ERROR at line 2:
 ORA-00600: internal error code, arguments: [kkmupsViewDestFro_4], [0], [85883], [], []
Why now you have the error and before not?
Which metalink note explain this error?
What is a simple workaround to avoid it?




December 2012 - Fast Copy

Level (*) : 3
Topic (*) : DBA



Your db is in ARCHIVELOG mode.
You want to copy the table T1 (table with 100 million rows) in a new table T2 that you have to create (these tables must have the same structure).
How can you do this in a very fast way?
In the meantime, you want that nobody do changes in the T1, the users can use it just for SELECTs.
How can you do this?



November 2012 - ASM

Level (*) : 3
Topic (*) : DBA



Your db uses ASM.
You want to get bigger the tablespace TBS_1. Then, you have to check if you have enough free space on the data diskgroup.
How can you check this information?
And after that, how can you add 8 Gigabytes to the tablespace TBS_1?



October 2012 - Snapshot too old

Level (*) : 2
Topic (*) : DBA



The developers' group ask you to investigate this problem: they launch the procedure pr_problem and they receive the error "ORA-01555: snapshot too old".
Which could be the problem?
How can you find which is the problem? And which solutions can you apply?

Solution

You should check in the alert log file: there, you can find where exactly they receive the error.

Usually the possible cases are:
- The UNDO tablespace or the undo retention are small: in these cases, the DBA have to get
  bigger the UNDO tablespace or the undo retention.
  If, using the db, they receive often the ORA-01555 probably this is the problem.

- They have a big transaction: in this case, the developers should use more “commit” or
  “rollback” in the code

- In the pr_problem there is a big query so you should check its explain plan and if you
  think the explain plan is not good, the developers (or you) should do the performance
  tuning of the query




September 2012 - Index Details

Level (*) : 3
Topic (*) : DBA



In the db, you have a table called ORDERS.
You have to find the queries that shows its index details. Example:
The summary of its indexes:

 TABLENAME        INDEXNAME          STATUS  INDEX_TYPE            TABLESP_NAME UNIQUENES
 ---------------- ------------------ ------- --------------------- ------------ ---------
 BLEVEL DistinctKeys LAST_ANAL SAMPLE_SIZE  INI_TRANS PARTITIONED
 ------ ------------ --------- ----------- ---------- -----------
 LASSI.ORDERS     LASSI.IDX_OR       N/A     NORMAL                             NONUNIQUE
      0	1782052	19-SET-12      136113            YES

 LASSI.ORDERS     LASSI.IDX_PROVA    VALID   NORMAL                TBS_INDEX    NONUNIQUE
      2 1863974 19-SET-12       41188         30 NO

 LASSI.ORDERS     LASSI.PK_ORDER     VALID   NORMAL                TBS_INDEX    UNIQUE
      2 1778278 19-SET-12      134368         12 NO

 LASSI.ORDERS     LASSI.CLIENT_NAME  VALID   FUNCTION-BASED NORMAL TBS_INDEX    NONUNIQUE
      2 423444 19-SET-12      264726         12 NO


Its indexed columns:

 TABLENAME                INDEXNAME              Column_name        C_Position   C_length
 ------------------------ ---------------------- ------------------ ---------- ----------
 LASSI.ORDERS             LASSI.IDX_OR           OM_SITE_ID                1         22
 LASSI.ORDERS             LASSI.IDX_PROVA        ORDER_ID                  1         22
 LASSI.ORDERS             LASSI.IDX_PROVA         ACCOUNT_NUMBER           2         60
 LASSI.ORDERS             LASSI.IDX_PROVA          TECHNOLOGY              3         22
 LASSI.ORDERS             LASSI.IDX_PROVA           STATUS                 4         22
 LASSI.ORDERS             LASSI.PK_ORDER         ORDER_B                   1         22
 LASSI.ORDERS             LASSI.CLIENT_NAME      SYS_NC00036$              1         60


The expression of its "function-based" indexes:

 TABLENAME          INDEXNAME              COLUMN_EXPRESSION            COLUMN_POSITION
 ------------------ ---------------------- ---------------------------- ---------------
 LASSI.ORDERS       LASSI.CLIENT_NAME      UPPER("CLIENT_LAST_NAME")                  1


The details of its partitioned indexes:

 INDEXNAME    PARTITION_NAM HIGH_VALUE         PARTITION_POSIT TABLESP_NAM STATUS IniTrans
 ------------ ------------- ------------------ --------------- ----------- ------ --------
 LASSI.IDX_OR P136419656_0  13641965, MAXVALUE               1 TBS_INDEX   USABLE        2
 LASSI.IDX_OR P370794502_0  37079450, MAXVALUE               2 TBS_INDEX   USABLE        2
 LASSI.IDX_OR P_MX          MAXVALUE, MAXVALUE               3 TBS_INDEX   USABLE        2


The metadata of its indexes: here is one of them:

 CREATE UNIQUE INDEX "LASSI"."PK_ORDER" ON "LASSI"."ORDERS" ("ORDER_B")
 PCTFREE 10 INITRANS 12 MAXTRANS 255 COMPUTE STATISTICS
 STORAGE(INITIAL 9437184 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
 TABLESPACE "TBS_INDEX"




August 2012 - Expdp Problem

Level (*) : 2
Topic (*) : DBA



Your db is in Oracle 11.2.0.3. You launch expdp and you immediately receive:
UDI-31623: operation generated ORACLE error 31623
 ORA-31623: a job is not attached to this session via the specified handle
 ORA-06512: at “SYS.DBMS_DATAPUMP”, line 3263
 ORA-06512: at “SYS.DBMS_DATAPUMP”, line 4488
 ORA-06512: at line 1
What can you do in order to avoid it?
Which metalink note explain it?

Solution

You must set the stream pool. Example:
alter system set streams_pool_size=40M;
You find it on the metalink note 1080775.1 and 457724.1.



July 2012 - Sequence problem

Level (*) : 1
Topic (*) : DBA/Prog



You have the sequence LASSI_SEQ and now it is like this:
  select LASSI_SEQ.nextval 
  from dual;

  NEXTVAL
  -------
    10089
In this moment, nobody is using this sequence and you want that its nextval value will be 0.
You must do it without dropping the sequence.
How?

Solution

You have to do these steps:
- Do an ALTER on the sequence:

   alter sequence LASSI_SEQ 
   increment by -10089 minvalue 0;

- Check the nextval value:

   select LASSI_SEQ.nextval 
   from dual;

    NEXTVAL
   --------
          0

- Do another ALTER on the sequence:

   alter sequence LASSI_SEQ 
   increment by 1;




June 2012 - Statistic problem

Level (*) : 2
Topic (*) : DBA



You are in Oracle 10g and you have the partitioned table LASSI.PT.
Usually, you don't want that Oracle analyze that table.

Now you want to analyze it:
 exec DBMS_STATS.GATHER_TABLE_STATS ('LASSI', 'PT'); 
 *
 ERROR at line 1:
 ORA-20005: object statistics are locked (stattype = ALL)
 ORA-06512: at "SYS.DBMS_STATS", line 10640
 ORA-06512: at "SYS.DBMS_STATS", line 10664
 ORA-06512: at line 1
So, what you can do to analyzed it?
And how can you avoid again that Oracle automatically could analyzed it?

Solution

Suppose that the table has 2 partitions:
 SELECT stattype_locked FROM dba_tab_statistics WHERE table_name = 'PT';

 STATT
 -----
 ALL
 ALL

 2 rows.
Then you do the unlock of the stats on PT table launching this:
 exec DBMS_STATS.unlock_table_STATS ('LASSI', 'PT')
Check again in dba_tab_statistics:
 STATT
 -----


 2 rows.
So, now you can do the analyze of the PT table:
 exec DBMS_STATS.gather_table_stats ('LASSI', 'PT')
Now, to lock again the statistics gathering:
 exec DBMS_STATS.lock_table_STATS ('LASSI', 'PT');
Check:
 SELECT stattype_locked FROM dba_tab_statistics WHERE table_name = 'PT';

 STATT
 -----
 ALL
 ALL



May 2012 - Profile problem

Level (*) : 2
Topic (*) : DBA



You are in Oracle 10g and you have the Oracle user LASSI with the profile PROF_1.
To the user LASSI, you want to give the password lassi1 but you receive the error
  ORA-28007: the password cannot be reused
You want to use only that password and you don't want to change the properties of PROF_1.
How can you do it?

Solution

Temporarily you could give LASSI another profile that doesn’t cause that problem.
E.g. :
 alter user LASSI profile DEFAULT;
 alter user LASSI identified by lassi1; 
 alter user LASSI profile PROF_1;




April 2012 - Table describe

Level (*) : 3
Topic (*) : DBA



You have the tables T1 and T2. Those tables have many columns.
You have to find a query that checks their structures in order to see if these are identical:
COLUMN_NAME, DATA_TYPE, DATA_LENGTH, COLUMN_ID.

E.g.:
 create table LASSI.t1
  (c1 char,
  c2 number,
  c3 date);

 create table LASSI.t2
  (c1 varchar2(10),
  c2 number);

 create table LASSI.t3
  (c1 char,
  c2 number,
  c3 date);
If you launch that query between t1 and t2, you receive:
 COLUMN_NAME        DATA_TYPE       DATA_LENGTH  COLUMN_ID     CNT_T1     CNT_T2
 ------------------ --------------- ----------- ---------- ---------- ----------
 C1                 CHAR                      1          1          1          0
 C1                 VARCHAR2                 10          1          0          1
 C3                 DATE                      7          3          1          0
and if you launch the query between t1 and t3, you receive:
 no rows selected





March 2012 - Oracle Password

Level (*) : 2
Topic (*) : DBA



You are in Oracle 11g, you want to know the hashed password (someone call it "encrypted password") of the user LASSI.
In the previous Oracle versions, you could check the column PASSWORD on the DBA_USERS. But in 11g, this value is always null.
So, what you can do in order to see that information?

Solution

In Oracle 11g, you can find this information on SYS.USER$:
  SELECT name, password, ctime created
  FROM sys.user$;




February 2012 - Moving Segments

Level (*) : 3
Topic (*) : DBA/Progr



You want to move all segments contained in the tablespace TBS_SOURCE to the tablespaces TBS_TARGET_IDX and TBS_TARGET_DT.
You don't want to use exp/imp, expdp/impdp or online table Redefinition.

In TBS_SOURCE there are these objects types:
- INDEX --> you want them to TBS_TARGET_IDX
- LOBINDEX --> you want them to TBS_TARGET_DT
- LOBSEGMENT --> you want them to TBS_TARGET_DT
- TABLE --> you want them to TBS_TARGET_DT

You have to find a query (from dictionary) that create the correct DDL to move those objects.
For example, when you launch it, you have to see a result like this:

 SEGMENT_TYPE   DDL
 -------------- -------------------------------------------------------------------------
 INDEX          alter index LA.SYS_C0015774 rebuild tablespace TBS_TARGET_IDX;
 INDEX          alter index LA.IDX_LOG_ID_FOUR rebuild tablespace TBS_TARGET_IDX;
 LOBINDEX
 LOBINDEX
 LOBSEGMENT     alter table CT.LOG_B move lob (XML) store as (tablespace TBS_TARGET_DT);
 LOBSEGMENT     alter table LA.LOG_M move lob (XML) store as (tablespace TBS_TARGET_DT);
 TABLE          alter table LA.LOG_EVENTS_BK move tablespace TBS_TARGET_DT;
 TABLE          alter table LA.LOG_POLICY move tablespace TBS_TARGET_DT
And you have to explain why you don't need a DDL to move the LOBINDEXes?



January 2012 - resource busy error

Level (*) : 3
Topic (*) : DBA



You are in Oracle 10g and you launch this command:
 alter table EMP initrans 5; 

 ERROR at line 1:
 ORA-00054: resource busy and acquire with NOWAIT specified
 ORA-06512: at line 3
You have to write an anonymous block that tries to do this operation 10 times (waiting for 0,2 seconds between every attempt).
For example, you launch it and, at the third attempt, the command was successful, so on the screen you see:
 Success: No
 Success: No
 Success: YES
Otherwise, which Oracle feature can you use if you are in Oracle 11g?




December 2011 - Db Analysis

Level (*) : 3
Topic (*) : DBA/Progr



You have to write a PL/SQL program that do a short "db analysis".
When you launch it, you must receive a result like this:
************************************************************************
************************************************************************
   Analysis Date: 07/12/2011 16:33:42
************************************************************************
************************************************************************
 
Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
 
Database: 
 Dbid: 324368697       Name: DBLOR
 Created: 18-AGO-11    Log_mode: ARCHIVELOG

Instance: 
 Instance Number: 1     Name: DBLOR
 Parallel: NO           Host name: mi088lor
 Archiver: STARTED      Startup Time: 05/10/2011 16:08
 
SGA Statistics:
 Buffer Cache Hit Ratio:   97.384 %
 Library Cache Miss Ratio:   0.912 %
 Dictionary Cache Miss Ratio:   0.984 %




November 2011 - Contention and "Metadata query"

Level (*) : 3
Topic (*) : DBA


One your colleague, says that the EMP table and its indexes have contention.
Of course this is an "application issue" but, as a DBA, you could reduce this problem (for the "future rows") by changing the INITRANS setting.
So you have to find a "metadata query" that:
- return the commands you could launch in order to apply this changing
- return the current INITRANS

Result Example:
  COMMAND                                 INI_TRANS
  -------------------------------------- ----------
  alter index SCOTT.EMP_IDX2 initrans 6; 	2
  alter index SCOTT.EMP_IDX1 initrans 6; 	2
  alter table SCOTT.EMP initrans 5;		1
You have to find it without knowing the indexes names.




October 2011 - Initialization Parameters

Level (*) : 2
Topic (*) : DBA



You are in Oracle 10.2. and you want to avoid errors like :
 ORA-00018: maximum number of sessions exceed
 ORA-00020: maximum number of processes (%s) exceeded
To avoid them, you want to set correctly the parameters "processes" and "sessions".
To do this analyze, you have to find a query that has result like this:
 RESOURCE_NAME  CURRENT_UTILIZATION MAX_UTILIZATION LIMIT_VALUE
 -------------- ------------------- --------------- -----------
 processes                      130             133         150
 sessions                       135             159         170

Solution
You should use the view v$resource_limit : it displays information regarding some of the system resources:
  SELECT
    resource_name, 
    current_utilization, 
    max_utilization, 
    limit_value
  FROM
    v$resource_limit
  WHERE
    resource_name in ('sessions', 'processes');




September 2011 - DDL generation problem

Level (*) : 2
Topic (*) : DBA



You are in Oracle 10.2.
You have an existing DBMS_SCHEDULER job called FIND_JOB inside the schema SCOTT.
You are using SQL*Plus and you want to generate the DDL of this job.
How can you do it?

Solution
You can use the function dbms_metadata.get_ddl.
Its output is a CLOB so in order to see the result in SQL*Plus, you have to launch:
  set long 2000
After this, you can use this query (the type of this object is PROCOBJ):
  SELECT dbms_metadata.get_ddl('PROCOBJ', 'FIND_JOB', 'SCOTT') 
  FROM dual;




August 2011 - Export Problem

Level (*) : 3
Topic (*) : DBA


You are in Oracle 11.2.0.1.
You use the "original" export (no datapump) in order to export the schema called LASSI and you receive this error:
  EXP-11 Table Does Not Exist or Table is Ignored
Why?
Which query can you launch before the export in order to see if you could receive this error?
How can you avoid it?
Which metalink note is useful to read?




July 2011 - Invalid Views

Level (*) : 2
Topic (*) : DBA


You have to find a query that shows the invalid views in your db.
This query must be executed in SQL*Plus and you want a result like this:
 INVALID_OBJECT		TEXT
 ----------------------- ---------------------------------------
 LASSI.VW_S_ORDER_ITEM   select row_id,
                         PAR_ROW_ID,
                         S_ORDER_ITEM_X.ATTRIB_26,
                         S_ORDER_ITEM_X.ATTRIB_27
                         from pippo.S_ORDER_ITEM_X

 LASSI.S_EXTRACT_NODE    SELECT
                         T1.RULE_ID     RULE_ID,
                         T1.NODE_ID     NODE_ID,
                         T1.GROUP_CD    GROUP_CD,
                         T2.NAME        RULE_NAME
                         FROM S_EXTDATA_N T1, S_EXTDATA_R T2
                         WHERE T1.RULE_ID = T2.ROW_ID

Solution
You have to set up the SQL*Plus environment. Example:
  set lines 155 pages 66
  col invalid_object for a33
  set long 2000
And, after this, you can launch the query:
  select o.owner || '.' || o.object_name invalid_object, v.text
  from dba_objects o,
       dba_views v
  where status != 'VALID'
        AND object_type = 'VIEW'
        AND o.owner = v.owner
        AND o.object_name = v.view_name;



June 2011 - Table Access

Level (*) : 3
Topic (*) : DBA


In the database, you have many "physical reads" on a small table called TAB_1.
Then you can try to improve the queries that read it and you can do others 2 things in order to improve the access to it.
Find these 2 other solutions.



May 2011 - SQL and Files

Level (*) : 3
Topic (*) : DBA/Progr


You have to find a query that shows the datafiles and tempfiles created in the last X days, where X is a dynamic variable defined like this: &days.
For example, I want to know the files created in the last 90 days then my result is:
 TYPE   TABLESPACE_NAME    FILE_NAME                                   MB   CREATION
 ------ ------------------ ------------------------------------- -------- ----------
 DATAF  TS_TSOLC_TAB       /oracle/dblor/data0/TS_TAB_d02.dbf       10240  22-FEB-11
 DATAF  TS_TSOLC_TAB       /oracle/dblor/data0/TS_TAB_d03.dbf       10240  22-APR-11
 DATAF  USERS              /oracle/dblor/data0/users02.dbf          16384  14-FEB-11
 TEMPF. TS_ACN_UNB_TEMP    /oracle/dblor/temp0/TS_ACN_TEMP.dbf       5120  14-FEB-11



April 2011 - Archiving

Level (*) : 2
Topic (*) : DBA


You have to find a query that shows the amount of redo logs generated every 10 minutes in the last 2 hours.
Then you want a result like this:
  DATE                   N.Archive     Tot.MB
  ------------------- ------------ ----------
  From 2011-01-25 17.20          3        708
  From 2011-01-25 17.30          3        702
  From 2011-01-25 17.40          1        234
  From 2011-01-25 17.50          2        469
  From 2011-01-25 18.00          1        234
  From 2011-01-25 18.10          2        471
  From 2011-01-25 18.20          2        469
  From 2011-01-25 18.30          2        468
  From 2011-01-25 18.40          1        234
  From 2011-01-25 18.50          2        468
  From 2011-01-25 19.00          2        480
  From 2011-01-25 19.10          1        144
  From 2011-01-25 19.20          1          0

Solution
You can see the view v$archived_log:
 select 'From '|| substr(to_char(al.completion_time,'YYYY-MM-DD hh24.mi'),1,15) || 0 date,
      count(al.recid) "N.Archive",
      round(sum ((al.blocks+1)*al.block_size)/1048576) "Tot.MB" 
 from v$archived_log al 
 where al.completion_time >=sysdate-1/12
 group by substr(to_char(al.completion_time,'YYYY-MM-DD hh24.mi'),1,15) 
 order by 1;



March 2011 - Auditing

Level (*) : 2
Topic (*) : DBA


You have the auditing activated in Oracle9i.
You upgrade the db to the 10.2.0.5 Oracle version.
After that, you see that Oracle writes in the sys.aud$ but the result of one query is strange:
 SELECT count(1)
 FROM sys.aud$
 WHERE TIMESTAMP# IS NOT NULL;

 COUNT(1)
 --------
       0
You used this query in Oracle9i and now you expected to receive a result different than 0.
What is the reason?
Which metalink notes can you refer to?

Solution
In the Oracle db version 10gR1 and above, the TIMESTAMP# column is obsoleted in favour of the new NTIMESTAMP# column.

Since datatype of TIMESTAMP# (date) is coarse and can not capture fractional seconds and timezone, NTIMESTAMP# column is introduced of datatype timestamp(6).
The old column is deprecated.

Metalink ID 427296.1



February 2011 - Alert.log

Level (*) : 3
Topic (*) : DBA


Your Oracle server is crashed.
After it works again, you check the db.
It seems to work fine but some people say that they can't connect to the db and in the alert.log you found this:
 Tue Jan 11 12:10:28 2011
 Errors in file /oracle/db_lor/admin/bdump/db_lor_qmn0_5525654.trc:
 ORA-00600: internal error code, arguments: [4194], [73], [77], [], [], [], [], []
 Doing block recovery for fno: 2 blk: 43
   block recovery range from rba 17687.5432.0 to scn 1972.2718780554 
Which metalink notes can you refer to?
How can you fix the problem?





January (2) 2011 - Listener Problem

Level (*) : 2
Topic (*) : DBA


You want to see the status of a listener and you receive this error:

  ordblor # lsnrctl status LS_DBLOR_1521

  LSNRCTL for IBM/AIX RISC System/6000: Version 9.2.0.8.0 - Production on 9-JAN-11 11:17

  Copyright (c) 1991, 2006, Oracle Corporation.  All rights reserved.

  Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=mi011)(PORT=1521)))
  TNS-01169: The listener has not recognized the password

Why have you received this error?
How can you avoid it?

Solution
You have received this error because you have implemented the password in the listener.
The password in the listener was useful especially in Oracle 9i for security reasons.

To avoid the error here described, you have to look at inside the file listener.ora .
At the end of this file, you find something this:
  PASSWORDS_ls_dblor_1521 = B5C1F55A82F9E241
Then you have to launch these commands:
  1. lsnrctl
  2. set current_listener LS_DBLOR_1521
  3. set password B5C1F55A82F9E241
  4. status




January 2011 - Oracle 11g Installation

Level (*) : 3
Topic (*) : DBA


Using OUI, you are installing Oracle 11.2.0.2 server on AIX machines (AIX 5.3 and AIX 6.1).
At Step 10 ("Perform Prerequisite Checks"), you receive errors like these:
 1. free space: server88:/tmp : Expected Value 1GB,  Actual Value 100MB
 2. Checking for rsct.basic.rte(0.0); Not found
 3. Checking for rsct.compat.clients.rte(0.0); Not found
 4. APARs IZ42940, IZ49516, IZ52331 are missing
 5. APARs IZ41855, IZ51456, IZ52319 are missing
Can you ignore them? In which metalink notes can you find these problems?




December 2010 - Statspack

Level (*) : 2
Topic (*) : DBA


You want to delete all the data inside the tables in the STATSPACK schema that are older than 1 year.
What is a sample way to do it?

Solution
The stats$snapshot is the main table in the STATSPACK.
This table contains the snapshot ID for all of the subordinate tables and the SNAP_TIME indicates when the snapshot was taken.

The stats$snapshot table can be deleted in order to delete rows from all of the subordinate tables, so in this case you can launch:
 Delete stats$snapshot 
 where SNAP_TIME>sysdate-365;



November 2010 - Secret Code

Level (*) : 3
Topic (*) : DBA/Prog


You are in Oracle 10g and you have a PL/SQL procedure called pr_trunc.
This procedure can be used but you want that nobody (neither the schema owner) can see its source.
How can you do it?




October 2010 - Index Use

Level (*) : 3
Topic (*) : DBA


You have the index LASSI.idx_1.

You want to discover whether it is used, or not:
- how can you enable this check?
- which view you have to examine if you are connected as LASSI? and if you are connected as SYS?
- how can you stop this check?




September (2) 2010 - Package Compilation

Level (*) : 2
Topic (*) : DBA/Prog


You are trying to compile a package but you receive the error
  ORA-04021: timeout occurred while waiting to lock object 
You want to know who is using it. How can you do it?
You want a result like this:
  (103) - LASSI
  (211) - USER2
where 103 and 211 are the SIDs and LASSI and USER2 are the users that are using the package.

Solution
You have to create the procedure who_is_using in the SYS schema.
You find it in metalink.
Then you launch that procedure. Example where PKG_LASSI is the package that you want to compile:
 set serveroutput on

 exec who_is_using ('PKG_LASSI')
  (103) - LASSI
  (211) - USER2



September 2010 - Hidden Parameters

Level (*) : 2
Topic (*) : DBA


You have to write a query that find out your hidden parameters and some its characteristics.
Example of its result:
  NAME                                  VALUE        DEFLT     TYPE
  ------------------------------------- ------------ --------- ----------------
  _abort_recovery_on_join               FALSE        TRUE      boolean
  _active_standby_fast_reconfiguration  TRUE         TRUE      boolean
  _adaptive_direct_read                 TRUE         TRUE      boolean
  _adaptive_fetch_enabled               TRUE         TRUE      boolean
  _adjust_literal_replacement           FALSE        TRUE      boolean
  _affinity_on                          TRUE         TRUE      boolean
  _aiowait_timeouts                     100          TRUE      number
  ...
Solution
This is a good query :
 select a.ksppinm name,
	b.ksppstvl value,
	b.ksppstdf deflt,
	decode
	(a.ksppity, 1,
	'boolean', 2,
	'string', 3,
	'number', 4,
	'file', a.ksppity) type
	--,a.ksppdesc description
 from
	sys.x$ksppi a,
	sys.x$ksppcv b
 where
	a.indx = b.indx  AND
	a.ksppinm like '\_%' escape '\'
 order by 1;




August (2) 2010 - Move Files

Level (*) : 3
Topic (*) : DBA/Prog



You are in Unix and inside the directory /oracle/db_lor/dbms102/rdbms/audit
you have thousands of files having the name starting with "ora_1".

You want to move them inside the directory
/oracle/db_lor_audit_ora_1

You try it normally, but you receive one error:
  mv ora_1* /oracle/db_lor_audit_ora_1/
  bash: /bin/mv: Argument list too long
How can you do this?




August 2010 - SQL Query

Level (*) : 2
Topic (*) : DBA/Prog



You want to find the tablespaces that have the datafiles only in /oracled02.
Find out the query that do this.

Solution
Launch this:
 select distinct tablespace_name  
 from dba_data_files 
 where file_name  like '/oracled02%'
   minus
 select tablespace_name  
 from dba_data_files 
 where file_name not like  '/oracled02%';
As I wrote, after the “minus”, you don’t need the “distinct”.



July 2010 - Parameter Problem

Level (*) : 2
Topic (*) : DBA



You have created a single db instance in Oracle 10.2.
When you start the instance, you receive the error ORA-32004 :
 SQL> startup

 ORA-32004: obsolete and/or deprecated parameter(s) specified
 ORACLE instance started.

 Total System Global Area  981467136 bytes
 Fixed Size                  2088800 bytes
 Variable Size             436207776 bytes
 Database Buffers          536870912 bytes
 Redo Buffers                6299648 bytes

 Database mounted.
 Database opened.
How can you find which is the "wrong" parameter ?

You find that the "wrong" parameter is max_commit_propagation_delay.
You are using a modified SPFILE copied from a RAC db.
How can you adjust that parameter?

Solution
You will find that parameter inside the alert.log :
 ...
  pga_aggregate_target     = 536870912
  _optimizer_connect_by_cost_based= FALSE
  _right_outer_hash_enable = FALSE
 Deprecated system parameters with specified values:
  max_commit_propagation_delay
 End of deprecated system parameter listing
 Wed Apr  7 16:55:36 2010
 Oracle instance running with ODM: Veritas 5.0 ODM Library, Version 1.1
 PMON started with pid=2, OS id=1298548
 PSP0 started with pid=3, OS id=1290286
 ...
You can change that parameter using this command:
 alter system reset max_commit_propagation_delay
 scope=spfile
 sid='*';
After that, you have to do the bounce of the database.




June 2010 - Disable Db links

Level (*) : 2
Topic (*) : DBA



You are in Oracle 10g and you want to disable one database link without dropping it.
Actually, in Oracle the Database links cannot be altered.
But there is a workaround.
Which is it?

Solution
A simple workaround of this problem is: put comments inside the entry in tnsnames.ora.
For example:
the db link uses this TNS entry:
db_lor =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 10.16.122.144 )(PORT = 1521)))
    (CONNECT_DATA =
      (SERVICE_NAME = db_lor ))
  )
It should became like this:
# db_lor =
#   (DESCRIPTION =
#     (ADDRESS_LIST =
#       (ADDRESS = (PROTOCOL = TCP)(HOST = 10.16.122.144 )(PORT = 1521)))
#     (CONNECT_DATA =
#       (SERVICE_NAME = db_lor ))
#   )
Of course, you can do this only if this connection is used only by that database link!



May 2010 - Number of Sessions

Level (*) : 2
Topic (*) : DBA/Prog



You want to do a stored procedure in order to check every 30 seconds how many sessions (active and inactive) are on your db:
When you launch this check, the procedure must do 10 snapshots and you must see graphically the result.
Example of the result:

 Time                Active Ses    Inact Ses        Active | Inactive
 20091119 16.33.01       13           229             **** | ***************
 20091119 16.33.31       14           227             **** | ***************
 20091119 16.34.01       16           225             **** | ***************
 20091119 16.34.31       16           226             **** | ***************
 20091119 16.35.01       13           229             **** | ***************
 20091119 16.35.31       13           229             **** | ***************
 20091119 16.36.01       16           223             **** | ***************
 20091119 16.36.31       22           210            ***** | **************
 20091119 16.37.03       22           220            ***** | ***************
 20091119 16.37.33       15           245             **** | ****************

Solution
You have to use the view v$session and the functions LPAD, RPAD and dbms_lock.sleep:
set serveroutput on size 1000000;

declare

 v_sessions	varchar2(2000) := null; -- USEFUL FOR THE CURSOR RESULT
 v_snapshots	pls_integer := 10;	-- NUMBER OF SNAPSHOTS
 v_wait		pls_integer := 30;	-- NUMBER OF SECONDS BETWEEN THE SNAPSHOT

BEGIN

 dbms_output.put_line (' Time                Active Ses    Inact Ses        Active | Inactive');

 for i in 1..v_snapshots loop

	select  to_char(sysdate,'yyyymmdd hh24.mi.ss') || 
 		LPAD(sum(decode(status,'ACTIVE',count(1))),9,' ')  ||
 	 	LPAD(sum(decode(status,'INACTIVE',count(1))),14,' ') || '  ' ||
		LPAD(LPAD('*',round(sqrt(sum(decode(status,'ACTIVE',count(1))))) ,'*'),15,' ')
		|| ' | ' || 
		RPAD('*',round(sqrt(sum(decode(status,'INACTIVE',count(1))))),'*')
	into v_sessions
	from v$session
	group by to_char(sysdate,'yyyymmdd hh24.mi.ss'),
		 status;

	dbms_output.put_line (v_sessions);

	if i != v_snapshots then 
		dbms_lock.sleep(seconds => v_wait);
	end if;

 end loop;

end;




April 2010 - Tablespace Problem

Level (*) : 3
Topic (*) : DBA



Your db is in Oracle 9.2.0.6.0 in a Sun Microsystems machine.
The datafiles are in the File System (FS) /oracle/dblor/data.
The tempfile is in the FS /oracle/dblor/temp.

The FS /oracle/dblor/temp is totally full then you ask the UNIX group to extend it.
But they say that in order to do this the FS can't be totally full.

In it there is only one file and it's the file of the temporary tablespace TEMP.
Its size is 300 MB and it is in AUTOEXTEND till 400 MB.

Which is the 2 ways to check if the TEMP is offline?
How you can bring it again online?

After that you bring it online, you could make that file a little bit smaller (295M) but you want to be sure that, till the FS will not be larger, new sessions will not use it.
What are the last steps in order to solve your problem?
And why could be useful the view database_properties?




March 2010 - Tablespaces Changed

Level (*) : 2
Topic (*) : DBA



You want to know the names of the tablespaces where at least one datafile has been added today.
You don't have access to the file system then you have to find them using a SQL query.
Which is this query?

Solution
You could launch this join:
 select  distinct tbs.name
 from  v$datafile dbf,
       v$tablespace tbs
 where trunc(dbf.CREATION_TIME)=trunc(sysdate) and
       dbf.ts# = tbs.ts#;




February 2010 - DB Link

Level (*) : 2
Topic (*) : DBA



In the machine SERVER_1, you have the database DB1 and in the TNSNAMES.ORA you have this entry:
 db2.world =
   (DESCRIPTION =
    (ADDRESS_LIST =
     (ADDRESS = (PROTOCOL = TCP)(HOST = SERVER_2)(PORT = 1521))
    )
    (CONNECT_DATA =
     (SERVICE_NAME = DB2000)
    )
   )
Then you create a database link:
  CREATE DATABASE LINK DB2000
  CONNECT TO user1 IDENTIFIED BY pwd1
  USING 'db2.world';
From the SERVER_1, you try this database link and it works:
  select * from dual@DB2000;

  D
  -
  X
Then, you try the same query from a client connected to the DB1 and you receive this error:
  "ORA-12154: TNS:could not resolve the connect identifier specified"
How you could create the database link in order to avoid this error?

Solution
In the database link creation, you could use the TNSNAMES.ORA entry:
  CREATE DATABASE LINK DB2000
  CONNECT TO user1 IDENTIFIED BY pwd1
  USING '(DESCRIPTION =
    (ADDRESS_LIST =
     (ADDRESS = (PROTOCOL = TCP)(HOST = SERVER_2)(PORT = 1521))
    )
    (CONNECT_DATA =
     (SERVICE_NAME = DB2000)
    )
   )';




January 2010 - SQL tuning

Level (*) : 2
Topic (*) : Prog



You want to do a SQL tuning of this:
  SELECT COUNT(*) 
  FROM tab_1 , tab_2
  WHERE tab_1.IDDOC = tab_2.IDDOC 
	AND tab_1.LASTVERSION = tab_2.VERSION
	AND tab_2.DIR = :b1;
Then you decide to use an Oracle event:
Which undocumented Oracle event is useful in this situation?
And which level you have to use in this event if you want to have also the wait event (as the example below)?
 Elapsed times include waiting on following events:
   Event waited on                 Times   Max. Wait  Total Waited
   -----------------------------  Waited  ----------  ------------
   SQL*Net message to client           3        0.00          0.00
   SQL*Net message from client         3       16.10         16.14
   db file sequential read            32        0.00          0.02
And how you can stop the Oracle event?

Solution
You have to use the event 10046 and, after, use the TKPROF to interpret the trace file.
In order to activate this event :
  alter session set events '10046 trace name context forever, level num'; 
Where num is either 1,4,8 or 12, with:
- 1 being the same as a normal set sql_trace=true,
- 4 including values of bind variables,
- 8 including wait events,
- 12 including both bind variables and wait events.
Then in this example, you have to use the level 12:
  alter session set events '10046 trace name context forever, level 12'; 
In order to stop it:
  alter session set events '10046 trace name context off';




(*)
Level:
1: easy solution
2: medium solution
3: hard (or long) solution

Topic:
DBA:
quiz usually suitable for DBAs
Progr: quiz usually suitable for PL/SQL or SQL Programmers
DBA/Progr: quiz suitable for DBAs and for Programmers

   

This website is not connected with Oracle Corporation or the official Oracle website.
Some words used here are registered trade marks of their owners.