Oracle Spin

Day-to-Day Experiences

Archive for July, 2008

How to grant view all DDL in an Oracle database to unprivilege user

Posted by Alex Lima on July 29, 2008

SQL>grant select on dba_objects to <username>;

SQL>conn <username>/<password>

SET PAGESIZE 0
SET LONG 100000
SET LONGCHUNKSIZE 10000
SET LINESIZE 1000
–SET TERMINATOR ON
EXECUTE DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,’SQLTERMINATOR’,TRUE)
SELECT DBMS_METADATA.GET_DDL(OBJECT_TYPE,OBJECT_NAME,OWNER)
FROM DBA_OBJECTS
WHERE OBJECT_TYPE = ‘PACKAGE’ AND OWNER = ‘POSITION_OWNER’
–SAME FOR OTHER OBJECTS E.G. TABLE, PROCEDURE, ETC
;

Posted in General DBA, Scripts | Tagged: , , , | Leave a Comment »

How to find the tapes needed for restore if you are using RMAN catalog to write directly to tape?

Posted by Amin Jaffer on July 23, 2008

If you are using the RMAN and using the RMAN catalog to write directly to tape you can use the following query to find the tapes needed to restore or the tapes that were used.

# The following example find the tapes used to backup b/w 10-Jun-2008 4:00 AM and 11-Jun-2008 4:00 AM by specifying the database name or DB ID

$ sqlplus rmancatalog/rmancatalog
SQL> select distinct p.MEDIA
from rc_backup_piece p, rc_database d
where d.NAME = ‘TEMP’
– OR d.dbid = 3903930932
and p.COMPLETION_TIME >= TO_DATE(‘10-JUN-2008 04:00′, ‘DD-MON-YYYY HH24:MI’)
and p.COMPLETION_TIME <= TO_DATE(‘11-JUN-2008 04:00′, ‘DD-MON-YYYY HH24:MI’)
and p.db_id = d.dbid;

MEDIA
———
A00635
A00999

Posted in RMAN | Tagged: , , , | Leave a Comment »

How to change SYSMAN password in OEM (OMS)

Posted by Alex Lima on July 18, 2008

To change the Sysman password:
1. Stop the OMS instances that are associated with the repository
a. opmnctl stopall

2. Change the sysman password in the database:
a. Logon to sqlplus as a dba user
b. Issue the command: alter user sysman identified by newpassword;
c. Exit Sqlplus

3. On each management server host, cd to the OMS $ORACLE_HOME/sysman/config directory
a. backup the emoms.properties file
b. edit the emoms.properties file and modify the parameters;
eml.mntr.emdRepPwd=new_password
oracle.sysman.eml.mntr.emdRepPwdEncrypted=FALSE

NOTE: When you restart the OMS, the FALSE setting will change to TRUE and the password will become encrypted in the file

4. Still on Management Repository host, cd to the AGENT_HOME/bin and stop the agent:
./emctl stop agent
5. Next, cd to the AGENT_HOME/sysman/emd directory
a. Edit the targets.xml file and modify the oracle_emrep target definition with the following in bold:
<Target TYPE=”oracle_emrep” NAME=”Management Services and Repository” VERSION=”1.0″>
<Property NAME=”MachineName” VALUE=”host.us.oracle.com”/>
<Property NAME=”Port” VALUE=”1521″/>
<Property NAME=”SID” VALUE=”sid”/>
<Property NAME=”UserName” VALUE=”552f2080d6d8c3c6″ ENCRYPTED=”TRUE”/>
<Property NAME=”password” “newpassword” ENCRYPTED”FALSE”/>
..
..
b. Save the file. The TRUE value will change to FALSE and the newpassword will become encrypted when you restart the Agent.

6. Issue the command (from the Agent O_H/bin):
./emctl start agent

7. Restart each of the OMS’s
emctl start oms

8.Start the OMS instances that are associated with the repository
opmnctl startall

Note that after change all the config files shown in the document, the OEM still had issues to connect to the repository due to the sysman user been locked. After unlock the sysman account everything was back to normal.

Entries found in the $OMS_HOME/sysman/log/emoms.log

2008-07-17 10:40:54,685 [AJPRequestHandler-ApplicationServerThread-7] ERROR conn.ConnectionService verifyRepositoryEx.818 – Invalid Connection Pool. ERROR = ORA-28000: the account is locked

Posted in OEM - Grid Control | Tagged: , , , | 1 Comment »

How does one trace a session based on user

Posted by Alex Lima on July 18, 2008

CREATE OR REPLACE TRIGGER sys.session_trace_on
– to be created by sys user
AFTER LOGON ON database
DECLARE
machinename VARCHAR2(64);
osuserid VARCHAR2(30);
ora_username VARCHAR2(30) DEFAULT NULL;
os_username VARCHAR2(30);
v_sid NUMBER;
v_serial NUMBER;
v_program VARCHAR2(48);
v_numuser NUMBER;
CURSOR c1 IS
SELECT sid, serial#, osuser, machine, program
FROM v$session
WHERE audsid = userenv(’sessionid’)
– and upper(machine) like ‘ABC123′
and username = ‘EPCBATCH’;
BEGIN
OPEN c1;
FETCH c1 INTO v_sid, v_serial, osuserid, machinename,v_program;
IF c1%FOUND THEN
DBMS_SESSION.set_sql_trace (TRUE);
END IF;
CLOSE c1;
END;
/

Posted in General DBA, Scripts, trace | Tagged: , | Leave a Comment »

How to modify SQL*Plus prompt

Posted by Amin Jaffer on July 14, 2008

undefine usr db
col usr new_value usr
col db new_value db
set termout off
select lower(user) usr, instance_name db
from v$instance
/
set termout on
set sqlprompt ‘&&usr.@&&db.> ‘

Posted in General DBA, SQL*Plus | Tagged: , , , | Leave a Comment »