Wednesday, January 3, 2018

how to get pluggable databases info from container database in oracle 12C using a common user.

This post helps you to query all pluggable databases info using common user in container database.. To do that we need to create a common user in the container database and provide neccesary grants.
As you all know we can create a common user with out "C##" in the container database by using "_" parameter..

alter session set "_ORACLE_SCRIPT"=true;

provide neccessary grants... connect/select_catalog_role/select any dictionary/ alter session/create session ... if neccesary tablespace limits too...

once the user is created you still need to run below command to read the pluggable databases information...

alter user COMMON_USER_CHECK set container_data=all;

Using this user and CDB* views now you can get all the info from container.  in one place..



Hope this helps..

Script to get Lun ids for Linux in VM for ASM disks.



Below information will be handy when you want to know the lun id'd for the raw devices you are using in the ASM environment ..this will eliminate the need for you to wait for Unix admins to give you the lun info. ....

> there are 2 scripts... one is .sql and another one is .sh(main shell)..

1)
 make a script to ger ASM info of the raw devices...

set heading off
set feedback off
set echo off
set pagesize 0
col NAME for a30
col PATH for a30
spool asm_info.log
select NAME,PATH,OS_MB from V$ASM_DISK order by NAME asc;

2)
then make a main shell.... and give execute permissions...

--------------------------------------------------------------------
ORACLE_SID=+ASM
ORACLE_HOME=/usr/app/oracle/db_1
PATH=$ORACLE_HOME/bin:$PATH
export ORACLE_SID
export ORACLE_HOME
export PATH
echo $ORACLE_SID
echo $ORACLE_HOME
cd /usr/job/scripts/lun_info

rm -f /usr/job/scripts/lun_info/asm_info.log
rm -f /usr/job/scripts/lun_info/asm_info_cut.log
rm -f /usr/job/scripts/lun_info/asm_info_final.log
rm -f /usr/job/scripts/lun_info/asm_disk_lun_info.log
rm -f /usr/job/scripts/lun_info/asm_raw-physical.log

sqlplus / as sysdba << EOF
set heading off
set feedback off
set echo off
set pagesize 0
@disk_info.sql
exit
EOF
#cat asm_info.log|cut -c7- > asm_info_cut.log
cat asm_info.log| awk '{print $2}' > asm_info_cut.log
cat asm_info_cut.log|while read disk
do
echo "`cat /etc/udev/rules.d/60-raw.rules | grep -v '^#' | grep $disk | awk '{print $2}' | grep -Po '".*?"' | grep -oP '"\K[^"]+' `" >> asm_disk_lun_info.log
done

cat asm_disk_lun_info.log |while read rawd
do
echo "$rawd  `lsscsi | grep $rawd'' | awk '{print $1}'` " >> asm_raw-physical.log
done

paste asm_info.log asm_disk_lun_info.log asm_raw-physical.log| awk  '
BEGIN {
format = "%-20s %-18s %-19s %-18s  %-19s %s\n"
printf format,  "ASM_groups", "ASM_RAW_DISK",  "OS_DISK_SIZE", "UNIX_MAP_Disk", "LINUX_id",  "LINUX_SCSI_id"
printf format,  "----------", "-------------", "------------", "-------------", "--------", "-------------"}
{for(i=1;i<=NF;i++)
printf("%-20s%c", $i, (i==NF) ? ORS : "")}' >> asm_info_final.log;
exit;

--------------------------------------------------------------------------------------------


look for asm_info_final.log...... for this column....

LINUX_SCSI_id  --- validate with your storage admins...

Hope this helps......................................


Monday, May 22, 2017

Temp Usage

Temp Usage by Temp Tablespace:-

SELECT A.tablespace_name TABLESPACE,
  D.mb_total,
  SUM (A.used_blocks * D.block_size) / 1024 / 1024 mb_used,
  D.mb_total         - SUM (A.used_blocks * D.block_size) / 1024 / 1024 mb_free
FROM v$sort_segment A,
  (SELECT B.name,
    C.block_size,
    SUM (C.bytes) / 1024 / 1024 mb_total
  FROM v$tablespace B,
    v$tempfile C
  WHERE B.ts#= C.ts#
  GROUP BY B.name,
    C.block_size
  ) D
WHERE A.tablespace_name = D.name
GROUP BY A.tablespace_name,
  D.mb_total;

Temp Usage by Users:-


SELECT b.tablespace,
       ROUND(((b.blocks*p.value)/1024/1024),2)||'M' AS temp_size,
       a.inst_id as Instance,
       a.sid||','||a.serial# AS sid_serial,
       NVL(a.username, '(oracle)') AS username,
       a.program,
       a.status,
       a.sql_id
FROM   gv$session a,
       gv$sort_usage b,
       gv$parameter p
WHERE  p.name  = 'db_block_size'
AND    a.saddr = b.session_addr
AND    a.inst_id=b.inst_id
AND    a.inst_id=p.inst_id
ORDER BY b.tablespace, b.blocks;

Hope this Helps..



Friday, February 3, 2017

ORA-39346: data loss in character set conversion for object DATABASE_EXPORT/SCHEMA/TABLE/COMMENT

Recently, we have seen this error while importing application schemas from one environment to another(which are of same Platforms). the import log had this below error.
we are on 12.1.0.2.4(both environments on same version). we see below error because we have soem undefined or some characters that not able to convert while importing.. check and see if you see any text with different characters in comments that look ODD.

ORA-39346: data loss in character set conversion for object DATABASE_EXPORT/SCHEMA/TABLE/COMMENT

Oracle has a patch for Bug# 21342624 ...
Note :- download the one that you need for ..because oracle has this patch for different versions..

once you aplly this patch.. 21342624. do the import again(only comments) and see what all columns with tables are reported. and try to alter those comments...

Hope this Helps.......




Monday, August 1, 2016

unrecoverable error ORA-29701 raised in ASM I/O path;

ERROR: unrecoverable error ORA-29701 raised in ASM I/O path; terminating process 9830432 
Thu Jul 28 17:02:07 2016 ERROR: unrecoverable error ORA-29701 raised in ASM I/O path; terminating process 

This error was recently noticed when one of our unix admin accidentally cleaned the files in /tmp folder on AIX server.. he had deleted/removed the .oracle  folder and its files(hidden files).
This should not be done when oracle is up and running....

Soln:-
when you see this error .. make sure you shutdown oracle and asm/agent as you can.... And ask the Unix admin to bounce the server/reboot....once it is up.. you can try to start the oracle resources.. it should start with no issues...


Hope this Helps....

Thursday, July 7, 2016

Unix Variable to sqlplus and sqplus to UNIX different scenarios

1) passing variable to sqlplus
Variable_IN="'ABC_VAR_1','ABC_VAR_2'"

2) how to store sqlplus result to a variable back to unix variable.

v_count1=$(sqlplus -L -S sys/$passd@$PDB as sysdba <<EOF   ---(for 12c)
set feed off heading off echo off verify off termout off
select count(*) from dba_tab_statistics where stale_stats = 'YES';
exit
EOF
)

3) how to pass your own variables to use in the sqlplus...

Variable_IN="'ABC_VAR_1','ABC_VAR_2'"

declare
type_p_abc_dba integer;
begin
  select count(*) into type_p_abc_dba from dba_types where type_name='STORE_VAL_abc_DBA';
  if (type_p_abc_dba = 0) then
    execute immediate 'create type store_val_abc_dba  as table of varchar2(100);';
  end if;
end;
/

declare
    type pa_tablename is table of all_tables.table_name%type
        index by binary_integer;
    va_tablename pa_tablename;
cursor c_f is (select column_value from table(store_val_abc_dba($Variable_IN)));
BEGIN
FOR ind IN  c_f
LOOP

begin
     .............
     .............
end;
end loop;
end;

Hope this helps.......






Tuesday, June 21, 2016

script to find stale objects and run the stats

You can use below script to automate running stats when stale objects are found in the database...
here we are ignoring all the objects were their stats are locked.

In order to get updated  stale objects... it is better you flush the monitoring info... as this updates the changes occurred recently....and tells whether any objects got staled or not. we are doing this manually because oracle has it own way/time of updating... if you have hard hitting tables then they might be stale but the monitoring info will not capturing it...  by doing so we can have better stats for  the tables needed.

you can easily automate the below code with you environment set.

exec dbms_stats.FLUSH_DATABASE_MONITORING_INFO;

Script:-

CHANNELS=`cat /proc/cpuinfo | grep processor | wc -l`


===================
sqlplus  -S sys /change@ABCD_SID as sysdba <<EOF >> $LOG
set linesize 200
set serveroutput on size 1000000
set feedback on echo off verify off

Prompt Running stats for Stale Table objects

declare
sql_stmt varchar2(256);
va_tab dba_tab_statistics.table_name%type;

cursor c_f is (select owner,table_name,global_stats,stale_stats from dba_tab_statistics
where stale_stats = 'YES' and table_name not like 'BIN$%' and STATTYPE_LOCKED is null);

begin
    for i in c_f
    loop
        begin
           dbms_stats.gather_table_stats(''||i.owner||'',''||i.table_name||'',
                estimate_percent => 100,
                degree => $CHANNELS,
                method_opt => 'for all columns size auto', cascade => true);
                dbms_output.put_line(sysdate || ': stats done for ' || ''||i.owner||'' ||'.' || ''||i.table_name||'');
            exception
            when others then
            continue;
            dbms_output.put_line(sysdate || ': failed to gather stats for ' || ''||i.owner||'' ||'.' || ''||i.table_name||'' || chr(10) || sqlerrm);
         end;
    end loop;
           dbms_output.put_line(sysdate || ': #######################' || ': Stats done for Above Found Stale objects ' || ': #######################');
END;
/

Prompt Running stats for Stale index objects

declare
sql_stmt varchar2(256);
va_tab dba_ind_statistics.table_name%type;

cursor c_f is (select owner,index_name,global_stats,stale_stats from dba_ind_statistics
where stale_stats = 'YES' and table_name not like 'BIN$%' and STATTYPE_LOCKED is null);

begin
    for i in c_f
    loop
        begin
           dbms_stats.gather_index_stats(''||i.owner||'',''||i.index_name||'',
                estimate_percent => 100,
                degree => $CHANNELS,
                no_invalidate => false);
                dbms_output.put_line(sysdate || ': stats done for ' || ''||i.owner||'' ||'.' || ''||i.index_name||'');
            exception
            when others then
            continue;
            dbms_output.put_line(sysdate || ': failed to gather stats for ' || ''||i.owner||'' ||'.' || ''||i.index_name||'' || chr(10) || sqlerrm);
         end;
    end loop;
           dbms_output.put_line(sysdate || ': #######################' || ': Stats done for Above Found Stale objects ' || ': #######################');
END;
/


EOF
echo "Done" >> $LOG


Hope this Helps......

PostgreSql: Useful Commands-

 1)   ************************* Users ***************************  -- List of users with roles assigned: SELECT usename AS role_name,   CASE...