Script to check free space and used space in Oracle Database tablespaces

select a.tablespace_name,
       a.bytes_alloc/(1024*1024) “TOTAL ALLOC (MB)”,
 a.physical_bytes/(1024*1024) “TOTAL PHYS ALLOC (MB)”,
       nvl(b.tot_used,0)/(1024*1024) “USED (MB)”,
       (nvl(b.tot_used,0)/a.bytes_alloc)*100 “% USED”
from ( select tablespace_name,
       sum(bytes) physical_bytes,
sum(decode(autoextensible,’NO’,bytes,’YES’,maxbytes)) bytes_alloc
       from dba_data_files
       group by tablespace_name ) a,
     ( select tablespace_name, sum(bytes) tot_used
       from dba_segments
group by tablespace_name ) b
where a.tablespace_name = b.tablespace_name (+)
–and   (nvl(b.tot_used,0)/a.bytes_alloc)*100 > 10
and   a.tablespace_name not in (select distinct tablespace_name from dba_temp_files)
and   a.tablespace_name not like ‘UNDO%’
order by 1
 –order by 5

RMAN-03009: failure of allocate command on ORA_AUX_SBT_TAPE_1 channel



This is an error during Database Clone using RMAN. I was trying to restore database using RMAN Backup 


RMAN-00571: ===========================================================


RMAN-00569: ===============
ERROR MESSAGE STACK FOLLOWS ===============


RMAN-00571: ===========================================================


RMAN-03002: failure of Duplicate Db command
RMAN-05501: aborting duplication of target database


RMAN-03009: failure of allocate command on ORA_AUX_SBT_TAPE_1 channel 
ORA-19554: error allocating device, device type: SBT_TAPE, device name:


ORA-27211: Failed to load Media Management Library


Additional information: 


Cause: Backup Configuration was modified.


Solution:
Use the below command to Resolve the error and continue with Database Restore


rman auxiliary / 
run
{
allocate auxiliary channel c1 type disk;
allocate auxiliary channel c2 type disk;
duplicate database to ‘DEV’ backup location ‘/Daily_Backup/Backup_16042018’;
}
exit;
EOF

How to add space in ACFS filesystem?

The below post explains the step-by-step process to add storage to a mountpoint in ACFS filesystem


1.Before extending the mountpoint storage we need to add an LVM of required Storage Capacity on the server.


For checking the LUN’s available on the server, click here


For now, assume the LUN added is /dev/sdf1


2. As root User, check the available disks by running the below command


$ /usr/sbin/oracleasm listdisks
DATA01
OCR_VOTE01
OCR_VOTE02
OCR_VOTE03


3. Create a new disk using the below command


/usr/sbin/oracleasm createdisk DATA02 /dev/sdf1 


Where DATA02 is the name of new disk added
/dev/sdf1 is the LUN added for storage extension.


4. Verify the disk is added by running the below command.


 $/etc/init.d/oracleasm  listdisks
DATA01
DATA02
OCR_VOTE01
OCR_VOTE02
OCR_VOTE03


5. Navigate to the other cluster nodes and run the scandisks command to reflect the newly added disk on all the nodes of cluster.


$/etc/init.d/oracleasm  scandisks
Scanning the system for Oracle ASMLib disks:               [  OK  ]


 $/etc/init.d/oracleasm  listdisks
DATA01
DATA02
OCR_VOTE01
OCR_VOTE02
OCR_VOTE03


6. Now login to the database server as GRID user (Where ASM instance is running) to add space to ACFS.


Set the environment as required




export ORACLE_HOME=/u01/app/12.1.0/grid
export PATH=$PATH:$ORACLE_HOME/bin
export ORACLE_SID=+ASM1


$sqlplus / as sysasm


SQL> alter diskgroup DATA add disk ‘/dev/oracleasm/disks/DATA02’;


Diskgroup altered.




7. Increase the space on filesystem


As root user,


$acfsutil size +1G /oradata
acfsutil size: new file system size: 591833071616 (564416MB)

How to Enable Database Vault in Oracle database Version 11gR1?



Steps to enable Database Vault in Oracle Database 11gR1:


1. In the command prompt, use DVCA utility to enable Oracle Database Vault.


e.g.


dvca -action enable 
  -oh /u01/app/oracle/product/11.1.0/db_1
  -service conn_alias 
  -instance orcl 
  -dbname orcl 
  -owner_account lbrown_dvowner 
  -logfile dvcalog.txt 


Enter SYS password: sys_password
Enter owner password: owner_password


Parameter Description:
======================


-service is the name of the database specifier. The specifier can be a connect descriptor or net service name. 


-instance is the name of the database instance.


-dbname is the database name.


-sys_passwd is the SYS password. If you use a cleartext password on the command line, you must include the nodecrypt option. If you omit the password, DVCA prompts you for it. Preferably, omit the password and then enter it interactively when prompted.


-owner_account is the Oracle Database Vault Owner account name.


-owner_passwd is the Oracle Database Vault Owner account password. If you use a cleartext password on the command line, you must include the nodecrypt option. If you omit the password, DVCA prompts you for it. Preferably, omit the password and then enter it interactively when prompted.


-logfile is an optional flag to specify a log file name and location. You can enter an absolute path, or enter a path that is relative to the location of the $ORACLE_HOME/bin directory.


-silent is the option to run in command line mode. This option is required if you are not running DVCA in an xterm window.


-nodecrypt is the option to read plaintext passwords.


-lockout is the flag to use to disable SYSDBA operating system authentication.


2. Stop the database, Database Control console process, and listener.


Enable the Oracle Database Vault option as follows:
 The make command enables both Oracle Database Vault (dv_on) and Oracle Label Security (lbac_on).
 You must enable Oracle Label Security before you can use Database Vault.


cd $ORACLE_HOME/rdbms/lib
make -f ins_rdbms.mk dv_on lbac_on


cd $ORACLE_HOME/bin
relink all


3.Restart the database, Database Control console process, and listener.


4. Verify Oracle Database Vault and Oracle Label Security are enabled.


SELECT * FROM V$OPTION WHERE PARAMETER = ‘Oracle Label Security’;


SELECT * FROM V$OPTION WHERE PARAMETER = ‘Oracle Database Vault’;

How to create directories in Oracle Database?

Database Directories are required to read/write to a filesystem location from plsql code.


Below is the syntax to create database directory


SQL> create directory PLSQL_DIR AS ‘/oratmp/code’;


Directory created.


Grant Read/write privileges to Required Schema (e.g . APPS)


SQL> GRANT READ,WRITE ON DIRECTORY PLSQL_DIR TO APPS;


Grant succeeded.

How to use coe_xfr_sql_profile.sql to Improve performance of a sql query?

Oracle SQL Performance tuning is one of the frequently reported issues in a Oracle Database administrator’s daily job.
Very often we notice that sql queries or concurrent Programs which were running within few minutes earlier are now taking hours to be completed.
Underlying reason is due to the plan_hash_value used by the query has been changed.
coe_xfr_sql_profile.sql is the script developed by Oracle Support which helps us to identify the plan_hash_value which will resolve the performance issue.


Steps to use the script coe_xfr_sql_profile.sql


1. Download the script to a temporary directory on the database server.
Script is also available in Oracle Metalink.


2. Before Running the coe_xfr_sql_profile.sql, we need to know the sql_id of the sql query which is taking longer time to complete than usual.


To find the sql_id use below query


2.1 If you know the database SID of the long running query.
select inst_id,sid,serial#,status,last_Call_et,sql_id from gv$session where sid= ‘&sessionid’;


2.2 If you know the query test, Use gv$sql and gv$sqlarea views to get the sql_id.


3. Login to sqlplus as sysdba and run coe_xfr_sql_profile.sql at the SQL prompt.


$ sqlplus “/as sysdba”
SQL> @coe_xfr_sql_profile.sql
Parameter 1:
SQL_ID (required)


Enter value for 1: 0a3f7vuks8d7y   (–this is the sql_id of long running sql)
PLAN_HASH_VALUE AVG_ET_SECS
————— ———–
1484137450 15.6
3622468234 4560.76


[Output shows the list of available plan hash values, which can be forced on to the sql query. We need to select the plan_hash_value with low ETA to resolve the performance issue]


Parameter 2:
PLAN_HASH_VALUE (required)


Enter value for 2: 1484137450 




++Based on the inputs provided, it generates a sql script with naming convention coe_xfr_sql_profile_0a3f7vuks8d7y_1484137450.sql as output


coe_xfr_sql_profile_<sql_id>_<plan_hash_value>.sql


4. Run the script as sysdba


SQL>coe_xfr_sql_profile_0a3f7vuks8d7y_1484137450.sql 


5. Verify that Performance issue is resolved by Re-running the sql.

How to Resolve ACFS-03008 : The volume expansion limit has been reached?

Issue: ACFS Filesystem resize operation fails with “ACFS-03008: The volume could not be resized.  The volume expansion limit has been reached.”


$acfsutil size +1G /oradata
acfsutil size: ACFS-03008: The volume could not be resized.  The volume expansion limit has been reached.
acfsutil size: ACFS-03216: The ADVM compatibility attribute for the diskgroup was below the required version (11.2.0.4.0) for unlimited volume expansions.


Analysis:


Compatible attribute for advm and rdbms is below the required version.


 SQL>  select group_number, name, value from v$asm_attribute where name like ‘compatible%’ ;


GROUP_NUMBER
————
NAME
——————————————————————————–
VALUE
——————————————————————————–
           1
compatible.asm
12.1.0.0.0


           1
compatible.rdbms
11.2.0.0.0


           1
compatible.advm
11.2.0.0.0


           2
compatible.asm


12.1.0.0.0


           2
compatible.rdbms
10.1.0.0.0








Solution:


SQL> ALTER DISKGROUP DATA SET ATTRIBUTE ‘compatible.advm’=’11.2.0.4.0’ ;


Diskgroup altered.


SQL>  ALTER DISKGROUP DATA SET ATTRIBUTE ‘compatible.rdbms’=’11.2.0.4.0’ ;


Diskgroup altered.


Now verify the issue is resolved.
$ acfsutil size +10G /oradata
acfsutil size: new file system size: 603644231680 (575680MB)

ACFS-03171: Insufficient contiguous free ASM Diskgroup space

Issue:  


ACFS file resize operation operation fails with ACFS-03171: Insufficient contiguous free ASM Diskgroup space




[root@erptestdb01 ~]# cd /sbin
[root@erptestdb01 sbin]# acfsutil size +100M /oradata
acfsutil size: ACFS-03171: Insufficient contiguous free ASM Diskgroup space.  Check the ASM alert log.


Solution:


Increase size in smaller chunks until the required size is reached
[root@erptestdb01 bin]# acfsutil size +10M /oradata
acfsutil size: new file system size: 590625112064 (563264MB)