Friday, July 4, 2014

Find TABLE and COLUMN PRIVILAGES

Find TABLE and COLUMN PRIVILAGES


TABLE PRIVILLAGES
******************************************************

SELECT 'GRANT ',
        PRIVILEGE,
      ' ON ',
        TABLE_NAME,
      ' TO ',
        GRANTEE,
       ';'
FROM DBA_TAB_PRIVS
WHERE OWNER = upper('&&owner')
AND   TABLE_NAME = upper('&&table');




COLUMN PRIVILLAGES
*********************************************************
SELECT 'GRANT ',
        PRIVILEGE,
      ' ( ',
        COLUMN_NAME,
      ' ) ',
      ' ON ',
        TABLE_NAME,
      ' TO ',
        GRANTEE,
       ';'
FROM DBA_COL_PRIVS
WHERE OWNER = upper('&&owner')
AND   TABLE_NAME = upper('&&table');




DBA basic LINUX commands


To see errors from Alert log file
cd alertlogdirectory; 
grep ORA- alertSID.log

To see the name of a user from his unix id (Provided your UNIX admin keeps them!)
grep userid /etc/passwd


To see if port number 1521 is reserved for Oracle
grep 1521 /etc/services


To see the latest 20 lines in the Alert log file:
tail -20 alertSID.log


To see the first 20 lines in the Alert log file:
head -20 alertSID.log


To find a file named "whereare.you" under all sub-directories of /usr/oracle
find /usr/oracle -name whereare.you -print


To remove all the files under /usr/oracle which end with .tmp
find /usr/oracle -name "*.tmp" -print -exec rm -f {} \;


To list all files under /usr/oracle which are older than a week.
find /usr/oracle -mtime +7 -print


To list all files under /usr/oracle which are modified within a week.
find /usr/oracle -mtime -7 -print


To compress all files which end with .dmp and are more than 1 MB.
find /usr/oracle -size +1048576c -name "*.dmp" -print -exec compress {} \;


To see the shared memory segment sizes
ipcs -mb


To see the space used and available on /oracle mount point
df -k /oracle


To see the users logged in to the server and their IP address
who -T


To change passwd of oracle user
passwd oracle


To convert the contents of a text file to UPPERCASE
tr "[a-z]" "[A-Z]" < filename > newfilename


To convert the contents of a text file to lowercase.
tr "[A-Z]" "[a-z]" < filename > newfilename


To kill a process from Unix.
kill unixid 
OR 
kill -9 unixid


To see the oracle processes
ps -ef | grep SIDNAME


To see the number of lines in a text file (can be used to find the number of records while loading data from text file).
wc -l filename


To change all occurrences of SCOTT with TIGER in a file
sed 's/SCOTT/TIGER/g' filename > newfilename


To see lines 100 to 120 of a file
head -120 filename | tail -20


To truncate a file (for example listener.log file)
rm filename; touch filename


To see if SQL*Net connection is OK.
tnsping SIDNAME


To see if the server is up.
ping servername 
OR 
ping IPADDRESS


To see the versions of all Oracle products installed on the server.
$ORACLE_HOME/orainst/inspdver




REDUCE the REDOLOG FILES SIZE

REDUCE the REDOLOG FILES SIZE


Add a new logfile to to database
------------------------------------------------
ALTER DATABASE ADD LOGFILE GROUP 4 ('/oradata/xyz/redo04.log') SIZE 30M;
ALTER DATABASE ADD LOGFILE GROUP 1 '/oradata/xyz/redo04.log' SIZE 30M;



Switch logfile to newly created logfile
---------------------------------------------------
alter system switch logfile;


check the group name of logfile
-----------------------------------
select group#, status from v$log;

    GROUP# STATUS
---------- ----------------
         1 INACTIVE
         2 INACTIVE
         3 CURRENT



drop inactive log files
-------------------------------
alter database drop logfile group 1;
delete the logfile at OS LEVEL also



if u get the errors(ORA-01624 & ORA-00312) follow below and DROP again

ALTER SYSTEM CHECKPOINT GLOBAL;




if you get any error like this-------delete the logfile at OS level also

ORA-00301: error in adding log file 'C:\app\neerajs\oradata\orcl\redo01.log' - file cannot be created
ORA-27038: created file already exists
OSD-04010: <create> option specified, file already exists






ANALYZE HANGING SESSIONS USING HANGANALYZE3 utility/tool in ORACLE

ANALYZE HANGING SESSIONS USING HANGANALYZE 3 utility/tool in ORACLE

sqlplus / as sysdba

select a.sid, a.serial#, b.spid ospid, to_char(logon_time,’dd-Mon-rr hh24:mi’) Logintime
from v$session a, v$process b
where a.inst_id = b.inst_id and a.paddr = b.addr and status = ‘ACTIVE’;


SQL> oradebug setospid [spid]
SQL> oradebug unlimit;
SQL> oradebug hanganalyze 3

This will generate a trace file which will contain the detail why the oracle database session is hanging. Even though the trace file will contain loads of information still it is quite easy to find out the real culprit.



FIND TABLE NAME and COLUMN NAME based on RECORD/DATA

FIND TABLE NAME and COLUMN NAME based on RECORD/DATA



var val varchar2(10);
exec :val := 'RETURNED'

SELECT owner, table_name, substr (:val, 1, 11) "Searchword", SUBSTR(t.column_value.getstringval (),1, 50) "Column/Value" from all_tab_columns,
table(xmlsequence(dbms_xmlgen.getxmltype ('select ' || column_name || ' from ' ||owner||'.'||table_name|| ' where upper('|| column_name|| ') like upper(''%' || :val || '%'')'
 ).extract ('ROWSET/ROW/*'))) t where owner NOT IN ('USER_NAME/SCHEMA NAME') ;



SELECT owner, table_name, substr (:val, 1, 11) "Searchword", SUBSTR(t.column_value.getstringval (),1, 50) "Column/Value" from all_tab_columns,
table(xmlsequence(dbms_xmlgen.getxmltype ('select ' || column_name || ' from ' ||owner||'.'||table_name|| ' where upper('|| column_name|| ') like upper(''%' || :val || '%'')'
 ).extract ('ROWSET/ROW/*'))) t where owner='SCHEMA NAME' and table_name like 'TABLE_NAME' ;