Oracle passwords

Resetting

sql> ALTER USER [username] IDENTIFIED BY [password]

To Reset sys Password

(all actions from a local command line)

Prior to starting sqlplus, first set the oracle sid (shown here as xxxx) – where the oracle_sid is the name of the database you wish to amend.

Linux

TIP : If on linux, first execute “. oraenv ” which will set this sid and other necessary environment variables.

[oracle@DBNODE3 ~]$ . oraenv
ORACLE_SID = [oracle] ? PRESTIGE
The Oracle base for ORACLE_HOME=/opt/mnt1/app/oracle/product/11.2.0/dbhome_1 is /opt/mnt1

[oracle@DBNODE3 ~]$ sqlplus / as sysdba
sql> alter user [username] identified by [password]

Windows

start > run > cmd

SET ORACLE_SID=xxxx
sqlplus / AS sysdba

sql> ALTER USER sys IDENTIFIED BY [password]

Oracle Licensing

Processor licensing

You pay per Processor you run the Oracle software on; however Oracle has a special definition of “processor” which may or may not match that of your hardware vendor.
Intel Hyperthreading technology that makes one core look like two counts as 1 processor for this purpose.

Other soft partitioning technologies are treated differently; for example, the Solaris OS has a concept of Containers, this is similar to hard partitioning on an HP machine; however Oracle does not recognise software partitioning with Solaris Containers prior to Solaris 10; and even then there are stipulations.

Hard partitioning methods such as Sun’s Domains, IBM’s Logical partitioning are recognised as legitimate methods to limit the amount of resources that can run the Oracle software. If you are a MS or VMWare virtual machine user, the following document is a must read; Oracle Partitioning Policy document
Oracle Standard Edition uses a per-socket licensing scheme v Enterprise Edition uses a per-core licensing scheme.

Oracle Standard Edition

If you use Standard Edition or Standard Edition One on a 2 processor system you simply need 2 licenses. However, if you use Enterprise Edition you need to take the number of cores into account as well.

Enterprise Edition Per-core licensing
Multi-core processors are priced as (number of cores)*(multi-core factor) processors, where the multi-core factor is:
This link describes this best: http://www.oracle.com/us/corporate/contracts/processor-core-factor-table-070634.pdf

Oracle Software Download

Sql Tools
Sql Developer is a free cross-platform cross-database SQL tool (Oracle, Mysql & MS-SQL) that is recommended. there are many others!

To see which Oracle Sessions are Blocking

ELECT DISTINCT
s1.username ||'@'|| s1.machine ||'(INST=' || s1.inst_id ||' SID_SERIAL#= '|| s1.sid ||'_'||s1.serial#||')' AS Blocker
,s2.username||'@'||s2.machine||' (INST='||s1.inst_id||' SID_SERIAL# = '||s2.sid ||'_'||s2.serial#||' Event='|| s2.event ||')' AS Blockee
, s2.program ||'@'|| s1.machine AS Program
,SUBSTR(ob.object_name,1,40) ||' SQL -> ' || s3.sql_text AS Blocked_OBJ_SQL, s4.sql_text AS Blocker_SQL
FROM gv$lock l1, gv$session s1, gv$lock l2
, gv$session s2, v$sql s3
, gv$active_session_history ash, v$sql s4, dba_objects ob, gv$locked_object lo
    WHERE s1.sid=l1.sid
    AND s2.sid=l2.sid
    AND l1.block=1
    AND l2.request >0
    AND l1.id1=l2.id1
    AND l2.id2=l2.id2
    AND s2.sql_id = s3.sql_id
    AND s1.prev_sql_id = s4.sql_id
    AND lo.object_id = ob.object_id
    AND lo.SESSION_ID = s2.sid
    AND s2.seconds_in_wait > 10;

Note
1. this is using global view of GV$SESSION_WAIT – and reports back on any session which has waited > 10 seconds. So if your case scenario is looking for sessions which are blocked for less period of time then change the final line in the above script as required.

  AND s2.seconds_in_wait > 10;

Be cautious when amending this time period, as some applications may have by design, plenty of transactions which do cause row lock transactions eg scheduling applications. Normally, the purpose of this script is to look for anomalies.

2. seconds_in_wait has been deprecated from oracle 11g+. Currently is still works in 11gR2. Future releases may not include this column
if this bothers you, then change script line :

 AND s2.seconds_in_wait > 10;
 

to read

 AND s2.WAIT_TIME_MICRO/1000000 > 10;

Test case

We can easily simulate a a blocking lock situation using a test table. We will open two sqlplus sessions to the database and then issue the following commands to demonstrate this

1. using sqlplus connect to the database, eg

C:\sqlplus [username]/[password]@database_name
SQL*Plus: RELEASE 11.2.0.1.0 Production ON Wed Oct 5 13:33:26 2011
Copyright (c) 1982, 2010, Oracle.  ALL rights reserved.
 
Connected TO:
Oracle DATABASE 11g Enterprise Edition RELEASE 11.2.0.1.0 - 64bit Production
WITH the Partitioning, OLAP, Data Mining AND REAL Application Testing options
 
SQL>

Session A.
here, we create a dummy table and insert some test data into it. Check the data via a select, and then lock all rows in the table :

  1. create table test(colA varchar2(1), colB varchar2(1));
  2. insert into test values (1,’a’);
  3. insert into test values (2,’b’);
  4. select * from test ;
  5. commit;
  6. select * from test for update;

 

SQL> CREATE TABLE test(colA VARCHAR2(1), colB VARCHAR2(1));
TABLE created.
SQL> INSERT INTO test VALUES (1,'a');
1 ROW created.
SQL> INSERT INTO test VALUES (1,'b');
1 ROW created.
SQL> SELECT * FROM test ;
C C
- -
1 a
1 b
SQL> COMMIT;
COMMIT complete.
sql> SELECT * FROM test FOR UPDATE;

now we have locked all rows in the table.

so switching to another sqlplus session, using the same connection string as before
eg

C:\sqlplus [username]/[password]@database_name
SQL>

lets first try and see if we can select any row data :

SQL> SELECT * FROM test ;
C C
- -
1 a
1 b

good – expected behaviour as a row or table lock does not normally prevent us from seeing the before image. Now lets try updating a row :

SQL> UPDATE test SET colA='Z' WHERE colA='1';

now you should see the session hangs. And you can prove this from running the script as above giving us the example result of :
example_blocked_oracle_session.JPG

so back to Session A – lets close the lock

SQL> COMMIT;
COMMIT complete.

and then checking session B, you should see that the update has now completed :

SQL> UPDATE test SET colA='Z' WHERE colA='1';
1 ROW updated.

Oracle object wait statistics

common waits are ITL, Buffer and Row Lock contention. knowing the frequency of these is critical to understanding the root cause of any contention. When these occur, the most common remedies for high buffer busy waits include database writer (DBWR) contention tuning, adding freelists (or ASSM), and adding missing indexes. 

When reviewing objects for possible tuning issues, it is handy to have statistics such as the number of internal transaction list (ITL) waits, buffer busy waits and row lock waits that the object has experienced. Combined with the number of logical and physical reads the object has experienced, the above statistics give a complete picture of the usage of the object in question.

To see a list of these per object recorded since the database/instance was last restarted, run the following sql
SELECT * FROM
(
SELECT
DECODE
(GROUPING(a.object_name), 1, 'All Objects', a.object_name)
AS "Object",
SUM(CASE WHEN
a.statistic_name = 'ITL waits'
THEN
a.VALUE ELSE NULL END) "ITL Waits",
SUM(CASE WHEN
a.statistic_name = 'buffer busy waits'
THEN
a.VALUE ELSE NULL END) "Buffer Busy Waits",
SUM(CASE WHEN
a.statistic_name = 'row lock waits'
THEN
a.VALUE ELSE NULL END) "Row Lock Waits",
SUM(CASE WHEN
a.statistic_name = 'physical reads'
THEN
a.VALUE ELSE NULL END) "Physical Reads",
SUM(CASE WHEN
a.statistic_name = 'logical reads'
THEN
a.VALUE ELSE NULL END) "Logical Reads"
FROM
gv$segment_statistics a
WHERE
a.owner LIKE UPPER('&owner')
GROUP BY
rollup(a.object_name)) b
WHERE (b."ITL Waits">0 OR b."Buffer Busy Waits">0)

Oracle Hanging System

When there is an issue with an instance or session hang run this sql

sqlplus ‘/ as sysdba’
oradebug setmypid
oradebug unlimit
oradebug setinst all
oradebug -g all hanganalyze 4 <=== Issue command 3 times one minute apart
oradebug -g all dump systemstate 267 <=== Issue command 3 times one minute apart
quit

help is available :

sql> oradebug help

Trace files will be produced in the user_dump_dest directory. They are named according to the SPID of the process where the oradebug command is executed.

SQL> sho parameter user_dump_dest

NAME                                 TYPE                             VALUE
------------------------------------ -------------------------------- ------------------------------
user_dump_dest                       string                           C:\oracle\diag\rdbms\xxx\xxx1\trace
C:\Temp>set ORACLE_SID=xxxa1

C:\Temp>sqlplus / as sysdba

SQL*Plus: Release 11.1.0.7.0 - Production on Thu Aug 26 08:43:27 2010

Copyright (c) 1982, 2008, Oracle.  All rights reserved.

Connected to:
Oracle Database 11g Release 11.1.0.7.0 - 64bit Production
With the Real Application Clusters option

SQL> set timing on
SQL> set time on
08:43:38 SQL> spool oradebug_xxxx1
08:43:40 SQL> oradebug setmypid

Data Pump Error – ORA-39070: Unable to open the log file

 had a user today who really could not grasp the an error when trying to do an export with expdp
ORA-39002: invalid operation
ORA-39070: Unable to open the log file.
ORA-29283: invalid file operation
ORA-06512: at “SYS.UTL_FILE”, line 536
ORA-29283: invalid file operation
a quick check to see what the user had defined so far:
SQL> select directory_name, directory_path from dba_directories
DIRECTORY_NAME     DIRECTORY_PATH
——————————————————————————–
DBBACKUPS       e:\dbbackups
two things she hadn’t done:
  1. given correct permissions for that user to acccess the logical directory for DBACKUPS:
SQL> GRANT read, WRITE ON DIRECTORY DBACKUPS TO [username];

2. create the physical directory

cmd> mkdir e:\dbbackups

oracle Lob Reorganisation

The method below describes the steps to redefine the DDL of a table in whole or in part eg refine the lob definition only.

it works online, and performs an exact copy of the data from the source to the destination object, obeying the destination objects changed DDL where valid.
the only offline period, is a few seconds at the end of the task, where the tables are switched around, with the destination table name switching to the source and vice versa.

TIP: this time period can be reduced by running a synchronise process prior to running the “finish_redef” command.

Steps

1) if you wish to recover space from a datafile, you can only recover the space above the High Water Mark. For this reason, for a large LOB reorganisation, it may be best advised to move the lob and (optionally), it’s parent table into a different tablespace – perhaps a new one.

CREATE TABLESPACE PR_ARCHIVELOBDATA DATAFILE  SIZE 10G AUTOEXTEND ON NEXT 100M MAXSIZE 32767M
LOGGING
ONLINE
PERMANENT
EXTENT MANAGEMENT LOCAL UNIFORM SIZE 100M
BLOCKSIZE 8K
SEGMENT SPACE MANAGEMENT AUTO
FLASHBACK ON;

2) check the average size distribution of the lob – this will aid you in setting the chunk size. (note this is irrelevant when using Securefiles) and retained for posterity only. the code below will give an indication of how many rows will be stored inline (below 4k) and how many out of line – ie stored into a separate log segment)

eg
SELECT 'pritemdataversion' table_name, COUNT(*), size_cat FROM (
SELECT
  CASE
    WHEN dbms_lob.getLength(item_data) <= 4096 THEN 'inline'
    WHEN dbms_lob.getLength(item_data) >  4096 AND dbms_lob.getLength(item_data) <= 32768 THEN 'small'
    WHEN dbms_lob.getLength(item_data) > 32768 AND dbms_lob.getLength(item_data) <= 65536 THEN 'medium'
    ELSE 'large'
  END AS size_cat
    FROM aesuser.pritemdataversion
) GROUP BY rollup(size_cat)

3) create destination table containing new ddl.
4) check the redefinition is valid

EXEC DBMS_REDEFINITION.CAN_REDEF_TABLE('[schemaname]', '[objectname]');

TIP – no output will be given if the redefinition can go ahead – ie only error messages are displayed

4) run the following sql to start, synchronise and complete the redefinition.

EXEC DBMS_REDEFINITION.START_REDEF_TABLE('[schemaname]', '[source_objectname]', '[destination_objectname]' );
EXEC DBMS_REDEFINITION.SYNC_INTERIM_TABLE('[schemaname]', '[source_objectname]', '[destination_objectname]' );
EXEC DBMS_REDEFINITION.FINISH_REDEF_TABLE('[schemaname]', 'source_objectname]', '[destination_objectname]' );

5) check the table is changed as required.

oracle Securefiles v Basicfiles

there is a lot of information readily available, but essentially Securefiles follows the rewriting in the Oracle RDMS of Lob handling. The net affect is they are quicker and depending on the Edition of Oracle installed, ie Enterprise, provide options to compress and deduplicate data. (some applications may already do this as part of the application logic).
to see what objects are set to use securefiles/basicfiles – inluding any securefile options, run the following sql:

 
SELECT
    table_name
   ,column_name
    ,cache
   ,in_row
   ,encrypt
   ,compression
   ,deduplication
   ,securefile
  FROM dba_lobs
 WHERE owner = 'xxxx'
 ORDER BY table_name, column_name

oracle lob usage

to bring back size of all lobs used in the defined schema :

SELECT   TABLE_NAME, SUM (tab_size) "Table(MB)", SUM(Blocks_Used) "Blocks Used",
         SUM(Unused_Blocks) "Unused Blocks",   SUM(num_rows) "Num Rows", SUM (index_size) "Index(MB)",
         SUM (lobindex_size) "LobIndex(MB)",
         SUM (lobseg_size) "LobSegment(MB)", SUM (CHUNK / 1024) "Chunk (k)",
         SUM (tab_size + lobindex_size + index_size + lobseg_size)
                                                                  "Total(MB)"
    FROM (SELECT TABLE_NAME, BYTES / 1024 / 1024 tab_size, t.blocks Blocks_Used, t.empty_blocks Unused_Blocks,
         t.num_rows num_rows, 0 index_size,
                 0 lobindex_size, 0 lobseg_size, 0 CHUNK
            FROM dba_segments s, dba_tables t
           WHERE s.owner = UPPER ('AESUSER')
             AND t.owner = UPPER ('AESUSER')
             AND s.segment_name = t.TABLE_NAME
             AND TABLE_NAME NOT LIKE 'DR$%'
          UNION
          SELECT   TABLE_NAME, 0 tab_size,0 Blocks_Used, 0 Unused_Blocks,0 num_rows,
                   SUM (BYTES) / 1024 / 1024 index_size, 0 lobindex_size,
                   0 lobseg_size, 0 CHUNK
              FROM dba_segments s, dba_indexes i
             WHERE s.owner = UPPER ('AESUSER')
               AND i.owner = UPPER ('AESUSER')
               AND s.segment_name = i.index_name
               AND segment_type = 'INDEX'
               AND TABLE_NAME NOT LIKE 'DR$%'
          GROUP BY TABLE_NAME
          UNION
          SELECT   TABLE_NAME, 0 tab_size, 0 Blocks_Used, 0 Unused_Blocks,0 num_rows,0 index_size,
                   SUM (BYTES) / 1024 / 1024 lobindex_size, 0 lobseg_size,
                   0 CHUNK
              FROM dba_segments s, dba_indexes i
             WHERE s.owner = UPPER ('AESUSER')
               AND i.owner = UPPER ('AESUSER')
               AND s.segment_name = i.index_name
               AND TABLE_NAME NOT LIKE 'DR$%'
               AND segment_type = 'LOBINDEX'
          GROUP BY TABLE_NAME
          UNION
          SELECT   TABLE_NAME, 0 tab_size,0 Blocks_Used, 0 Unused_Blocks, 0 num_rows,0 index_size,
                   0 lobindex_size,
                   SUM (BYTES) / 1024 / 1024 lobseg_size, CHUNK
                                  FROM dba_segments s, dba_lobs l
             WHERE s.owner = UPPER ('AESUSER')
               AND s.segment_name = l.segment_name
               AND TABLE_NAME NOT LIKE 'DR$%'
               AND segment_type = 'LOBSEGMENT'
          -- and l.table_name=upper('PRITEMDATA')
          GROUP BY TABLE_NAME, CHUNK )
          WHERE TABLE_NAME  IN (SELECT DISTINCT TABLE_NAME FROM all_tab_columns WHERE data_type LIKE'%LOB'
                                AND owner='AESUSER')
GROUP BY TABLE_NAME
ORDER BY TABLE_NAME

 

oracle AWR

since 10g we can now use use AWR(automatic workload repository) report to analyse the Oracle Database health.

to run this, use script awrrpt.sql – available from $ORACLE_HOME\rdbms\admin

the script will prompt for input, and is self explanatory in the questions

SQL> @awrrpt
CURRENT Instance
[[USER:bignosekates|1289904198]][[USER:bignosekates|1289904198]][[USER:bignosekates|1289904198]][[USER:bignosekates|1289904198]]
   DB Id    DB Name      Inst Num Instance
----------- ------------ -------- ------------
  255075344 PRESTIGE            1 prestige

Specify the Report TYPE
[[USER:bignosekates|1289904198]][[USER:bignosekates|1289904198]][[USER:bignosekates|1289904198]][[USER:bignosekates|1289904198]][[USER:bignosekates|1289904198]][[USER:bignosekates]]
Would you LIKE an HTML report, OR a plain text report?
Enter 'html' FOR an HTML report, OR 'text' FOR plain text
Defaults TO 'html'
Enter VALUE FOR report_type:

TYPE Specified:                  html

EXT
--------------------------------
.html

Instances IN this Workload Repository SCHEMA
[[USER:bignosekates|1289904198]][[USER:bignosekates|1289904198]][[USER:bignosekates|1289904198]][[USER:bignosekates|1289904198]][[USER:bignosekates|1289904198]][[USER:bignosekates|1289904198]][[USER:bignosekates|1289904198]][[USER:bignosekates|1289904198]][[USER:bignosekates|1289904198]][[USER:bignosekates|1289904198]][[USER:bignosekates|1289904198]]

   DB Id     Inst Num DB Name      Instance     Host
------------ -------- ------------ ------------ ------------
* 255075344         1 PRESTIGE     prestige     Indy-Prestige-DB.inm-uk.net
* 255075344         1 PRESTIGE     prestige     Indy-Prestige-DB.dns1.co.uk
* 255075344         1 PRESTIGE     prestige     vIndy-Prestige

USING  255075344 FOR DATABASE Id
USING          1 FOR instance NUMBER

Specify the NUMBER OF days OF snapshots TO choose FROM
[[USER:bignosekates|1289904198]][[USER:bignosekates|1289904198]][[USER:bignosekates|1289904198]][[USER:bignosekates|1289904198]][[USER:bignosekates|1289904198]][[USER:bignosekates|1289904198]][[USER:bignosekates|1289904198]][[USER:bignosekates|1289904198]][[USER:bignosekates|1289904198]][[USER:bignosekates|1289904198]][[USER:bignosekates|1289904198]][[USER:bignosekates|1289904198]][[USER:bignosekates|1289904198]]~~
Entering the NUMBER OF days (n) will result IN the most recent (n) days OF snapshots being listed.  Pressing <return> without
specifying a NUMBER lists ALL completed snapshots.

Enter VALUE FOR num_days: 1
Listing the last DAY's Completed Snapshots
                                                       Snap
Instance     DB Name        Snap Id    Snap Started    Level
------------ ------------ --------- ------------------ -----
prestige     PRESTIGE         32245 16 Nov 2010 00:00      1
                              32246 16 Nov 2010 01:00      1
                              32247 16 Nov 2010 02:00      1
                              32248 16 Nov 2010 03:00      1
                              32249 16 Nov 2010 04:00      1
                              32250 16 Nov 2010 05:00      1
                              32251 16 Nov 2010 06:01      1
                              32252 16 Nov 2010 07:00      1
                              32253 16 Nov 2010 08:00      1
                              32254 16 Nov 2010 09:00      1
                              32255 16 Nov 2010 10:00      1

Specify the Begin and End Snapshot Ids
[[user:bignosekates|1289904198]][[user:bignosekates|1289904198]][[user:bignosekates|1289904198]][[user:bignosekates|1289904198]][[user:bignosekates|1289904198]][[user:bignosekates|1289904198]][[user:bignosekates|1289904198]][[user:bignosekates|1289904198]][[user:bignosekates|1289904198]]~~
Enter value for begin_snap: 32253
Begin Snapshot Id specified: 32253

Enter value for end_snap: 32255
End   Snapshot Id specified: 32255

Specify the Report Name
[[user:bignosekates|1289904198]][[user:bignosekates|1289904198]][[user:bignosekates|1289904198]][[user:bignosekates|1289904198]][[user:bignosekates|1289904198]][[user:bignosekates]]
The default report file name is awrrpt_1_32253_32255.html.  To use this name, press <return> to continue, otherwise enter an alternative.

Enter value for report_name:
Using the report name awrrpt_1_32253_32255.html