Passion for technology

Challenging the challenges over a decade. Place for Oracle DBAs, Oracle Apps DBAs, Unix Administrators and Developers

Archive for the ‘Scripts’ Category

Posted by Sanjay on January 5, 2012

===========
Small script: It will delete the audit files older than 90 days.
===========

[oracle@LONDT778W-D4 ~]$ cat test_aud_del.sh
#!/usr/bin/ksh

ORACLE_SID=SANJAY
export ORACLE_SID
ORACLE_HOME=/sanjay/sw/oracle/database/11.2.0.2
export ORACLE_HOME

LOGFILE=”/tmp/delete_old_aud.log”

echo `date` >>$LOGFILE
if [ $ORACLE_SID = "SANJAY" ] >>$LOGFILE
then

echo “Deleting the audit files older than 90 days for database `echo $ORACLE_SID`” >>$LOGFILE

echo “Audit files older than 90 days are: `find /sanjay/sw/oracle/database/admin/SANJAY/adump/*.aud -type f -mtime +90| wc -l`” >>$LOGFILE

find /sanjay/sw/oracle/database/admin/SANJAY/adump/*.aud -type f -mtime +90 -ls -exec rm {} \;

echo “Space usage at this moment is:
`df -h /sanjay/sw/oracle/`” >>$LOGFILE
else
echo “Environment is not set properly” >>$LOGFILE

fi
exit

Posted in Scripts, Unix | Leave a Comment »

Tablespace and datafiles

Posted by Sanjay on October 5, 2011

——————————————————-
To identify the filenames for a particular tablespace
——————————————————-
Note: change the tablespace name accordingly.
select file_name, bytes/1024/1024 MBytes, autoextensible, (increment_by*4096)/1024 NKBytes, maxbytes/1024/1024 MAX_MBytes
from dba_data_files
where tablespace_name=upper(‘UNDOTBS’);

—————————————————–
To identify the filenames for a particular tablespace
—————————————————–
Note: It will prompt to enter the tablespace name.
set lines 100
break on report
compute sum of mbytes on report
col file_name format a35
select file_id, file_name, bytes/1024/1024 MBytes, autoextensible, maxbytes/1024/1024 MaxMBytes
from dba_data_files
where tablespace_name=upper(‘&Tbs_Name’);

—————————————————————
To identify which datafiles are autoextend mode in the instance
—————————————————————

set linesize 130
select tablespace_name, file_name, bytes/1024/1024 MBytes, (increment_by*8192)/1024 NKBytes, maxbytes/1024/1024 MAX_MBytes
from dba_data_files
where autoextensible=’YES’;

————————————————————————————————-
To identify the datafiles characteristics for a particular tablespace, if the blocks size is 4096
————————————————————————————————-

select file_name, bytes/1024/1024 MBytes, autoextensible, (increment_by*4096)/1024 NKBytes, maxbytes/1024/1024 MAX_MBytes
from dba_data_files
where tablespace_name=upper(‘&Tbs_Name’);

————————————————————————————————-
To identify the datafiles characteristics for a particular tablespace, if the blocks size is 8192
————————————————————————————————-
select file_name, bytes/1024/1024 MBytes, autoextensible, (increment_by*8192)/1024 NKBytes, maxbytes/1024/1024 MAX_MBytes
from dba_data_files
where tablespace_name=upper(‘&Tbs_Name’);

————————————————————————————————–
To identify the datafiles characteristics for a particular tablespace, if the blocks size is 16384
————————————————————————————————–
select file_name, bytes/1024/1024 MBytes, autoextensible, (increment_by*16384)/1024 NKBytes, maxbytes/1024/1024 MAX_MBytes
from dba_data_files
where tablespace_name=upper(‘&Tbs_Name’);

———————————————————–
To identify the total free space available in a tablespace
———————————————————-
select max(bytes)/1024/1024 MBytes
from dba_free_space
where tablespace_name=upper(‘&Tbs_Name’);
———————————————————————
To identify the free space available in a tablespace in each datafile
———————————————————————
break on report
compute sum of bytes on report
select file_id, sum(bytes/1024/1024) mBytes
from dba_free_space
where tablespace_name=upper(‘&Tbs_Name’)
group by file_id; —————————————————-
To identify the particular segment’s characteristics
—————————————————-
select owner, tablespace_name, segment_type, extents, initial_extent/1024 KB_Ini_Ext, next_extent/1024 KB_Nxt_Ext, pct_increase, max_extents
from dba_segments
where segment_name=upper(‘&seg_name’);
———————————————————-
To identify the extents for a particular table in a schema
———————————————————-
select extents, next_extent/1024 KB_Nxt_Ext, pct_increase, max_extents
from dba_segments
where owner=upper(‘&schma_owner’) and segment_type=upper(‘&seg_type’) and max_extents=2147483645;

Posted in Scripts | Leave a Comment »

Tablespace management part-1

Posted by Sanjay on July 12, 2011

=========
How to create a tablespace.
========
CREATE [TEMPORARY / UNDO] TABLESPACE
DATAFILE / TEMPFILE ” SIZE [,
'' SIZE [,
'' SIZE [,...]]]
BLOCKSIZE
AUTOEXTEND { [OFF/ON (NEXT MAXSIZE) / UNLIMITED] }
LOGGING/NOLOGGING (Logging default)
ONLINE/OFFLINE (Online default)
EXTENT MANAGEMENT { [DICTIONARY] /
[LOCAL Default (AUTOALLOCATE / UNIFORM )] }
PERMANENT / TEMPORARY (Permanent default)
MINIMUM EXTENT
DEFAULT STORAGE { [INITIAL ]
[NEXT ]
[PCTINCREASE ]
[MINEXTENTS ]
[MAXEXTENTS / UNLIMITED]
[FREELISTS ]
[FREELIST GROUPS ]
[OPTIMAL /NULL]
[BUFFER_POOL ] }
CHUNK
NOCACHE;

BLOCKSIZE – By Default blocksize define in the parameter DB_BLOCK_SIZE. In Oracle9i, multiple blocksize that is different block size for different tablespaces, can be defined; all datafiles of a same tablespace have the same block size.
DEFAULT STORAGE :
INITIAL – To specifies the size of the object’s first extent.3 k minmum for Locally and 2 k minimum Dictionary.
NEXT – To specifies the size of the object’s sucessive extent.
PCTINCREASE – To specifies the ratio of the third or the preceding extent of the object. The default value for PCTINCREASE is 50 % and
the minimum value is 0%.
MINEXTENTS – Total number of extent allocated to the segment at the time of creation.
MAXEXTENTS – Maximum number of extent that can be allocated to the segment.
MININUM EXTENT – Extent are multiple of the size specified in this clause .NEXT and INITIAL extent size specified should be multiple of minmum extent.
PERMANENT / TEMPORARY – Permannent is default, use to store the table,index etc,Temporary is for temporay segments(sorts in Sql) can not store
table,index in temporary tablespace.
LOGGING / NOLOGGING – Logging is default. DDL operation & direct insert load are recorded in the redo log file.
ONLINE / OFFLINE – Online is default. Tablespace is available to use as soon as created.
===========
How to check the tablespace total size and usage.
===========
set pages 1000
set linesize 160
SELECT TabSpaceName,
SUM(TotBytes) “TOTAL MB”,
SUM(BytesUsed) “USED MB”,
SUM(BytesFree) “FREE MB”,
AVG(PCUSED) “% USED”,
AVG(PCFREE) “% FREE”
FROM (
SELECT SUBSTR (df.file_id, 1, 3) “ID#”,
df.tablespace_name TabSpaceName,
df.BYTES/1024/1024 TotBytes,
round (NVL(df.BYTES/1024/1024 – SUM (fs.BYTES/1024/1024),df.BYTES/1024/1024)) BytesUsed,
round (NVL(SUM (fs.BYTES/1024/1024),0)) BytesFree,
round (NVL((100 * ((SUM (fs.BYTES)) / df.BYTES)),0)) PCFREE,
round (NVL((100 * ((df.BYTES – SUM (fs.BYTES)) / df.BYTES)),100)) PCUSED
FROM SYS.dba_data_files df,
SYS.dba_free_space fs
WHERE df.file_id = fs.file_id (+)
GROUP BY df.tablespace_name, df.file_id,
df.tablespace_name,
df.BYTES,
df.blocks)
GROUP BY TabSpaceName
ORDER BY 6  ;

Tablespace Size (MB) Free (MB) % Free % Used
—————————— ———- ———- ———- ———-
Sanjay_DATA 5000 4989.75 100 0
Sanjay_INDEX 5000 4961.6875 99 1
USERS 100 97.4375 97 3
TEMP 20 15 75 25

==========
Oracle 11g.
==========
How to see the default permanent tablespace.
========
SELECT * FROM database_properties
WHERE property_name = ‘DEFAULT_PERMANENT_TABLESPACE’;

===========
How to check the tablespace extent and segment space management.
==========
Select tablespace_name ,extent_management ,segment_space_management
from dba_tablespaces;

============
How to change default permanent tablespace
============
SQL> alter database default tablespace sanjay;

==========
How to check default temporary tablespace.
=========
SELECT * FROM database_properties
WHERE property_name = ‘DEFAULT_TEMP_TABLESPACE’;
==========
How to change temporary tablespace.
==========
SQL> alter database default temporary tablespace temp;

Posted in Administration, Scripts | Leave a Comment »

Scripts to check the size.

Posted by Sanjay on January 10, 2011

Scripts for space usage.

Query to check databse size in MB.

———————————-

SET SERVEROUTPUT ON

declare

total_size_Mb number;

tfree_size_Mb number;

tused_size_Mb number;

begin

dbms_output.enable(100000);

select  Sum(bytes) into total_size_b  from dba_data_files;

select  Sum(bytes) into tfree_size_b   from  dba_free_space;

select  Sum(bytes) into tused_size_b  from  dba_segments;

dbms_output.put_line(‘Total:’ || TO_CHAR(Round(total_size_b/1048576, 2), ’999,999.00′) || ‘ MB’);

dbms_output.put_line(‘Free: ‘ || TO_CHAR(Round(tfree_size_b/1048576, 2), ’999,999.00′) || ‘ MB’);

dbms_output.put_line(‘Used: ‘ || TO_CHAR(Round(tused_size_b/1048576, 2), ’999,999.00′) || ‘ MB’);

end;

/

SET SERVEROUTPUT OFF

Query to check databse size in GB.

———————————-

SET SERVEROUTPUT ON

declare

total_size_Gb number;

tfree_size_Gb number;

tused_size_Gb number;

begin

dbms_output.enable(100000);

select  Sum(bytes) into total_size_b from dba_data_files;

select  Sum(bytes) into tfree_size_b  from  dba_free_space;

select Sum(bytes) into tused_size_b  from  dba_segments;

dbms_output.put_line(‘Total:’ || TO_CHAR(Round(total_size_b/1024/1024/1024, 2), ’999,999.00′) || ‘ GB’);

dbms_output.put_line(‘Free: ‘ || TO_CHAR(Round(tfree_size_b/1024/1024/1024, 2), ’999,999.00′) || ‘ GB’);

dbms_output.put_line(‘Used: ‘ || TO_CHAR(Round(tused_size_b/1024/1024/1024, 2), ’999,999.00′) || ‘ GB’);

end;

/

SET SERVEROUTPUT OFF

Posted in Scripts | Leave a Comment »

 
Follow

Get every new post delivered to your Inbox.