Showing posts with label Oracle database administration. Show all posts
Showing posts with label Oracle database administration. Show all posts

Monday, November 10, 2014

Oracle Tablespace Administration

User needs to have sysdba permission to perform the following.
e.g
sqlplus "/as sysdba"

 Investigate current tablespace state:

column "Total MB"   format 99,999,999
select fs.tablespace_name "Tablespace",(df.totalspace - fs.freespace) "Used MB",fs.freespace "Free MB",
df.totalspace  "Total MB",round(100 * (fs.freespace / df.totalspace)) "Pct. Free"
from (select tablespace_name, round(sum(bytes) / 1048576) TotalSpace from
dba_data_files group by tablespace_name) df,(select tablespace_name,
round(sum(bytes) / 1048576) FreeSpace from dba_free_space
group by tablespace_name) fs where df.tablespace_name = fs.tablespace_name;


Tablespace            Used MB     Free MB    Total MB  Pct. Free
------------------- ----------- ----------- ----------- ----------
CENTERDS                 1       1,023       1,024        100
TRD                  2,712          52      32,764          0
SYSAUX                 981         109       1,090         10
UNDOTBS1               183      23,689      23,872         99
TRD_INDX             1,729          95       1,824          5
VC50                     1       1,023       1,024        100
CVCDDB                 214         810       1,024         79
TRXADMIN55              86         938       1,024         92
USERS                    4           1           5         20
SYSTEM                 967           3         970          0
11 rows selected.

Notes:

TRD tablespspace is running 0% free. That was the root cause for "ORA-1653: unable to extend table".

32gig is a standard maximum logical size an Oracle DBA could allocate for a tablespace. That is an indication that, this tablespace can no longer be extended/expanded but need to add a brand new datafile to it.

Every tablespace contains one or more datafiles. User should find out where they are and if they are autoextend.



select file_id, file_name, round(bytes/1024/1024, 2) MB, status, autoextensible, round(maxbytes/1024/1024,2)  max_mb from dba_data_files where tablespace_name like upper('TRD') order by file_id;

FILE_ID   FILE_NAME                                       MB    STATUS    AUT   MAX_MB
-------   --------------------------------------          ---   -------   ----- -----------
7         /home/oracle/app/oracle/oradata/orcl/TRD.dbf    32764 AVAILABLE YES   32767.98


Once finding out what is the situation for the tablespace. User should choose the right options below and implement it. User should not overallocate the tablespace extend. Gradually increasing would be ideal if the user is not familiar with the application growth rate.

Option 1: Add new datafile to existing tablespace TRD. Set maximum size to 5G and autoextend. It will grow as it needs up to 5 gig.

SYS>  alter tablespace TRD add datafile '/home/oracle/app/oracle/oradata/orcl/TRD3.dbf' size 200M autoextend on maxsize 5G;
Tablespace altered.

Option 2: Add a new TRD tablespace datafile as TRD4.dbf without autoextend. This is likely the most commonly used option. This will pre-allocate all the space from the physical storage for 5 gig regardless it is used or not.

SYS> alter tablespace TRD add datafile '/home/oracle/app/oracle/oradata/orcl/TRD4.dbf' size 5G;
Tablespace altered.

Option 3: If user realized later on that 5 gig isn't sufficient, s/he can use "resize" to grow it further the datafile has not reaching its max of 32G as yet.

SYS> alter database datafile '/home/oracle/app/oracle/oradata/orcl/TRD4.dbf' resize 6G;
Database altered.

Option 4: similar to option 3 except this is to grow the maxsize and flipping it to AUTOEXTEND mode.

SYS> alter database datafile '/home/oracle/app/oracle/oradata/orcl/TRD4.dbf' autoextend on maxsize 7G;
Database altered.

User should check an overall space allocation for the tablespace and physical storage consumption. Use this query to check how the tablespace or datafiles allocation looks like after the changes.

select file_id, file_name, round(bytes/1024/1024, 2) MB, status, autoextensible, round(maxbytes/1024/1024,2)  max_mb from dba_data_files where tablespace_name like upper('TRD') order by file_id;

User should also monitor the grow of the physical filesystem that housing the datafiles.

SYS> !df -h
Filesystem             Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00   156G  133G  15G   90% /
/dev/sda2             9.5G  6.4G  2.7G  71% /stage
/dev/sda1               99M   13M   82M   14% /boot
tmpfs                   16G   4.0G  12G   26% /dev/shm
/dev/mapper/VolGroup02-backup 59G   36G   21G   63% /backup
/dev/mapper/VolGroup02-u01

Monday, July 28, 2014

Oracle v$sql_monitor showing ORA-10173 .. coincidentally the same time my server crashed.

Reason for the v$sql_monitor status "DONE (ERROR)" is because the server has an power outage? First time looking into this .....


SYS> select distinct status from v$sql_monitor;

STATUS
-------------------
DONE (ERROR)
DONE (ALL ROWS)
DONE

SYS> select * from v$sql_monitor where status='DONE (ERROR)';

       KEY STATUS                   USER# USERNAME                       MODULE                                           ACTION                           SERVICE_NAME                             CLIENT_IDENTIFIER                                                 CLIENT_INFO                                                      PROGRAM                                          PLSQL_ENTRY_OBJECT_ID PLSQL_ENTRY_SUBPROGRAM_ID PLSQL_OBJECT_ID PLSQL_SUBPROGRAM_ID FIRST_REF
---------- ------------------- ---------- ------------------------------ ------------------------------------------------ -------------------------------- ---------------------------------------------------------------- ---------------------------------------------------------------- ---------------------------------------------------------------- ------------------------------------------------ --------------------- ------------------------- --------------- ------------------- ---------
LAST_REFR REFRESH_COUNT        SID PROCE SQL_ID
--------- ------------- ---------- ----- -------------
SQL_TEXT
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
I SQL_EXEC_ SQL_EXEC_ID SQL_PLAN_HASH_VALUE EXACT_MATCHING_SIGNATURE FORCE_MATCHING_SIGNATURE SQL_CHILD_ADDRES SESSION_SERIAL# P  PX_MAXDOP PX_MAXDOP_INSTANCES PX_SERVERS_REQUESTED PX_SERVERS_ALLOCATED PX_SERVER# PX_SERVER_GROUP PX_SERVER_SET PX_QCINST_ID   PX_QCSID ERROR_NUMBER                      ERRO
- --------- ----------- ------------------- ------------------------ ------------------------ ---------------- --------------- - ---------- ------------------- -------------------- -------------------- ---------- --------------- ------------- ------------ ---------- ---------------------------------------- ----
ERROR_MESSAGE                                                                                                                                                                                    BINDS_XML                                                                         OTHER_XML                                                                        ELAPSED_TIME QUEUING_TIME   CPU_TIME    FETCHES BUFFER_GETS DISK_READS
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- ------------ ------------ ---------- ---------- ----------- ----------
DIRECT_WRITES IO_INTERCONNECT_BYTES PHYSICAL_READ_REQUESTS PHYSICAL_READ_BYTES PHYSICAL_WRITE_REQUESTS PHYSICAL_WRITE_BYTES APPLICATION_WAIT_TIME CONCURRENCY_WAIT_TIME CLUSTER_WAIT_TIME USER_IO_WAIT_TIME PLSQL_EXEC_TIME JAVA_EXEC_TIME
------------- --------------------- ---------------------- ------------------- ----------------------- -------------------- --------------------- --------------------- ----------------- ----------------- --------------- --------------
6.6572E+11 DONE (ERROR)                 0 SYS                            DBMS_SCHEDULER                                   ORA$AT_SQ_SQL_SW_2771            SYS$USERS                                  oracle@privCloud (J000)                                                                                                                  25-JUL-14
25-JUL-14            18        302 j000  1u7skbm9tvwvk
SELECT /* DS_SVC */ /*+ cursor_sharing_exact dynamic_sampling(0) no_sql_tune no_monitoring optimizer_features_enable(default) */ SUM(C1) FROM (SELECT /*+ qb_name("innerQuery") NO_INDEX_FFS( "RB#3")  */ 1 AS C1 FROM "SYS"."X$KTFBUE" "U#1", "SYS"."RECYCLEBIN$" "RB#3" WHERE ("U#1"."KTFBUESEGTSN"="RB#3"."TS#") AND ("U#1"."KTFBUESEGFNO"="RB#3"."FILE#") AND ("U#1"."KTFBUESEGBNO"="RB#3"."BLOCK#")) innerQuery
Y 25-JUL-14    16777216          2108298085               9.6089E+18               9.7014E+18 00000001DB549520             164 N                                                                   10173                             ORA
ORA-10173: Dynamic Sampling time-out error                                                                                                                                                             33995036     0    2270654          1       40324       9145
            0              74915840                   9145            74915840                       0                    0                     0                     0                 0          33262831                0              0

The last shown that the server was rebooted by SOMEONE.


oracle   pts/1        10.16.185.21     Tue Jul 29 10:56 - 15:41  (04:44)
oracle   pts/1        10.16.185.21     Mon Jul 28 10:27 - 13:16  (02:48)
oracle   pts/1        10.113.231.204   Fri Jul 25 15:36 - 15:50  (00:13)
reboot   system boot  2.6.18-238.el5   Fri Jul 25 15:35         (9+23:01)
oracle   pts/1        10.113.231.204   Fri Jul 25 08:54 - 11:08  (02:13)
oracle   pts/2        10.113.224.30    Thu Jul 24 16:21 - 20:03  (03:42)
oracle   pts/1        10.113.224.30    Thu Jul 24 14:52 - 18:13  (03:21)

Friday, November 11, 2011

Script to track Oracle DB locks.


-- db locks with session and serial
select b.inst_id, 'alter system kill session ''' || b.sid || ',' || b.serial# || ''';' 
from gv$locked_object a , gv$session b, dba_objects c where b.sid = a.session_id 
and a.object_id = c.object_id;


-- for node1 
select b.inst_id, 'alter system kill session ''' || b.sid || ',' || b.serial# || ''';' 
from gv$locked_object a , gv$session b, dba_objects c where b.sid = a.session_id 
and a.object_id = c.object_id and b.inst_id=1;

-- transaction 2PC problem
select 'execute DBMS_TRANSACTION.PURGE_LOST_DB_ENTRY(' || LOCAL_TRAN_ID || ')' from dba_2pc_pending;

-- getting sql from the db locks
select inst_id, sql_text from gv$sql where sql_id in (select sql_id from gv$locked_object a , gv$session b, 
dba_objects c where b.sid = a.session_id and a.object_id = c.object_id);


--- revised 
--- tracking sid, serial and OS pid.
select p.spid,  b.username, a.sql_text from gv$sql a, gv$session b, gv$process p
where b.sql_address = a.address AND b.paddr = p.addr
  and b.sql_hash_value= a.hash_value and b.sid = &sid and b.serial# = '&serial';


-- revised- use when necessar - results can be cluttered. 
-- getting sid and serial and sql. compare with db locks sql and analyze if killing is necessary.

set lines 190
select b.sid, b.serial#,d.sql_text
from gv$locked_object a , gv$session b, dba_objects c, 
gv$sql d where b.sid = a.session_id 
and a.object_id = c.object_id and d.sql_id=b.sql_id;


-- objects that locked up.
set lines 220
col object_name format a30
col username format a8
col machine format a9
col spid format a6
col instance format 999
col object_owner format a11
col locked_mode format a10
col logon_time format a25
SELECT b.inst_id as instance,
       b.session_id AS sid,
       s.serial#,
       NVL(b.oracle_username, '(oracle)') AS username,
       a.owner AS object_owner,
       a.object_name,
       Decode(b.locked_mode, 0, 'None',
                             1, 'Null (NULL)',
                             2, 'Row-S (SS)',
                             3, 'Row-X (SX)',
                             4, 'Share (S)',
                             5, 'S/Row-X (SSX)',
                             6, 'Exclusive (X)',
                             b.locked_mode) locked_mode,
       b.os_user_name, s.machine, s.program, p.spid, s.logon_time
FROM   dba_objects a,
       gv$locked_object b, gv$session s, gv$process  p
WHERE  a.object_id = b.object_id
and    s.sid (+)= b.session_id
and    s.inst_id (+) = b.inst_id
and    s.paddr = p.addr
and    s.inst_id = p.inst_id
ORDER BY 1, 2, 3, 4;



-- tracking lock with OS PID
set long 500000
set lines 250
SET LINESIZE 80 HEADING OFF FEEDBACK OFF
SELECT
 RPAD('USERNAME : ' || s.username, 80) ||
 RPAD('OSUSER   : ' || s.osuser, 80) ||
 RPAD('PROGRAM  : ' || s.program, 80) ||
 RPAD('SPID     : ' || p.spid, 80) ||
 RPAD('SID      : ' || s.sid, 80) ||
 RPAD('SERIAL#  : ' || s.serial#, 80) ||
 RPAD('MACHINE  : ' || s.machine, 80) ||
 RPAD('TERMINAL : ' || s.terminal, 80)||
 RPAD ('STATUS  : ' || S.STATUS, 80) ||
 RPAD('SQL TXT  : ' || q.sql_text, 3000)  
 FROM gv$session s,
      gv$process p,
      gv$sql q
 WHERE s.paddr = p.addr
 AND   p.spid  = '&PID_FROM_OS'
 AND   s.sql_address        = q.address
 AND   s.sql_hash_value = q.hash_value;

-- a user causing lock ups
set lines 220
col object_name format a30
col username format a8
col machine format a9
col spid format a6
col instance format 999
col object_owner format a11
col locked_mode format a10
col logon_time format a25
SELECT b.inst_id as instance,
       b.session_id AS sid,
       s.serial#,
       NVL(b.oracle_username, '(oracle)') AS username,
       a.owner AS object_owner,
       a.object_name,
       Decode(b.locked_mode, 0, 'None',
                             1, 'Null (NULL)',
                             2, 'Row-S (SS)',
                             3, 'Row-X (SX)',
                             4, 'Share (S)',
                             5, 'S/Row-X (SSX)',
                             6, 'Exclusive (X)',
                             b.locked_mode) locked_mode,
       b.os_user_name, s.machine, s.program, p.spid, s.logon_time
FROM   dba_objects a,
       gv$locked_object b, gv$session s, gv$process  p
WHERE  a.object_id = b.object_id
and    s.sid (+)= b.session_id
and    s.inst_id (+) = b.inst_id
and    s.paddr = p.addr
and    s.inst_id = p.inst_id
and machine name like '&machinenamehere'
and wait_class != 'Idle' ;
ORDER BY 1, 2, 3, 4;