Nov 24, 2011
Missing DBMS_SCHEDULER Jobs via OEM
If you notice a job is running, even an os command, then query the dba_scheduler_jobs view. This will list all dbms_scheduler jobs, then use notmal dbms_scheduler options to work with this job, prefrebably drop the job.
Nov 17, 2011
Invisible Indexes
To make an index invisable then run:
sql> alter index <index name> INVISIBLE;
To make an index visible:
sql> alter index <index name> VISIBLE;
You can also make the optimizer use all invisible indexes by for the current session by:
sql> alter session set optimizer_use_invisible_indexes = true ;
Nov 12, 2011
TAR and Excluding Files
The syntax to do this is:
tar cvfX <
Nov 11, 2011
Packaging Oracle Incidents
"AUTOIMATIC DIAGNOSTIC REPOSITORY"
This tool, among other tasks does the following:
- Automatically purges trace files, alert log files etc
- Manages "incidents"
- Packages incidents.
This blog will talk about how to manage the logs and manage incidents. Although many features discussed in this blog can be completed via OEM, I will be discussing how to do this from the command interface.
To Log On, run:
unix> adrci
To show your current environment, run:
adrci> show homes
To set a HOME environment, run:
adrci> set home
To show current incidents, run:
adrci> show incidents
ADR Home = /opt/oracle/admin/diag/rdbms/xxx/XXX:
*************************************************************************
INCIDENT_ID PROBLEM_KEY CREATE_TIME
-------------------- ----------------------------------------------------------- ------------------
12426 ORA 3137 [12333] 2011-11-02 16:47:50.277000 +13:00
1 rows fetched
To purge a particular incident, run:
adrci> purge -i n nn nnn
To purge a type of data, run:
adrci> purge -age nn -type xxx
where age is defined in minutes and type can be "alert, incident, trace, dump etc"
Nov 8, 2011
11.2 Update Window Details
BEGIN
DBMS_SCHEDULER.DISABLE(
name=>'"SYS"."SATURDAY_WINDOW"',
force=>TRUE);
END;
BEGIN
DBMS_SCHEDULER.SET_ATTRIBUTE(
name=>'"SYS"."SATURDAY_WINDOW"',
attribute=>'DURATION',
value=>numtodsinterval(1080, 'minute'));
END;
BEGIN
DBMS_SCHEDULER.SET_ATTRIBUTE(
name=>'"SYS"."SATURDAY_WINDOW"',
attribute=>'REPEAT_INTERVAL',
value=>'FREQ=WEEKLY;BYDAY=SAT;BYHOUR=3;BYMINUTE=0;BYSECOND=0');
END;
BEGIN
DBMS_SCHEDULER.ENABLE(
name=>'"SYS"."SATURDAY_WINDOW"');
END;
Aug 11, 2011
tar / compress in one command
Aug 10, 2011
rman delete
Aug 3, 2011
vi search and replace
May 16, 2011
ksh Setting Variables only if the variable is not set
DATESTRING=${DATESTRING:-$(date)}
May 4, 2011
Xauth x11 forwarding on unix
1. Update putty X11 settings. Click the "ENABLE X11 FORWARDING", for each putty connection.
2. Login to unix server.
3. Run > xauth list
Output will be something like
Where nn is a number like 10, 11, 12, ...
4. Start exceed / similar server.
5. Run > export DISPLAY=localhost:nn
If sudoing to another unix account then run the following:
1. Sudo to unix account
2. Run > xauth add unix:nn ... Output from xauth list command ran in step 3 above.
3. Run > export DISPLAY=localhost:nn
Now run your x11 application.
Feb 22, 2011
Remove unwanted files from FLASH_RECOVERY_AREA
Note : Flashback logs cannot be backed up outside the recovery area and so are not backed up by BACKUP RECOVERY AREA.
NOTE: Removing these files with an operating system utility will physically remove these files, but the database will still think the files exist and the problem of archival error may still occur. Use the following commands to synchronize the files with the database and use rman to remove these files.
RMAN>CROSSCHECK ARCHIVELOG ALL;
RMAN>Delete expired backup;
RMAN>Delete expired archivelog all;
RMAN>Delete force obsolete;
4. Make sure that your guaranteed restore points are necessary. If not, delete them
5. If flashback logs are enabled then make sure you have enough space for all the flashback logs. If its not required then you can turn off flashback.
6. Review your backup retention policy and if required change the RMAN RETENTION POLICY
Exceptions :
- If RMAN is not part of backup strategy and archivelogs are going to FRA then manual intervention required for deletion of archivelogs. Periodically purse old archivelogs
for example
- By default RMAN backup goes to FRA. While taking RMAN backup if backup location explictly specified to flash recovery area location then those backup pieces are not considered as part of FRA for auto managment.
- For Archivelogs backup to FRA use USE_DB_RECOVERY_FILE_DEST rather than giving explict path of FRA
- Bug 4911954
Details:
V$RECOVERY_FILE_DEST SPACE_USED and NUMBER_OF_FILES values may be wrong.
eg: Number of files in V$FLASH_RECOVERY_AREA_USAGE and V$RECOVERY_FILE_DEST are different.
This problem can lead to recovery area files being deleted even though there is no space pressure.
Fixed in : 10.2.0.3 , 11.1.0.6
- Bug 5106952
Details:
Flashback logs are not reclaimed by flash recovery area when using guaranteed
restore point (after dropping guaranteed restore point) or when changing
db_flashback_retention_target to a lower value.
Feb 14, 2011
11.2 recovery - free up spaceon DB_RECOVERY_FILE_DEST*
Make more disk space available and increase DB_RECOVERY_FILE_DEST_SIZE
2. Move backups from the flash recovery area to tertiary storage such as tape.
Note : Flashback logs cannot be backed up outside the recovery area and so are not backed up by BACKUP RECOVERY AREA.
3. Run DELETE for any files that have been removed with an operating system utility. If you use host operating system commands to delete files, then the database will not be aware of the resulting free space.
RMAN>CROSSCHECK ARCHIVELOG ALL;
RMAN>Delete expired backup;
RMAN>Delete expired archivelog all;
RMAN>Delete force obsolete;
4. Make sure that your guaranteed restore points are necessary. If not, delete them
5. If flashback logs are enable then make sure you have enough space for all the flashback logs. If its not required then you can turn off flashback.
6. Review your backup retention policy and if required change the RMAN RETENTION POLICY
Exceptions :
- If RMAN is not part of backup strategy and archivelogs are going to FRA then manual intervention required for deletion of archivelogs. Periodically purse old archivelogs
for example
- By default RMAN backup goes to FRA. While taking RMAN backup if backup location explictly specified to flash recovery area location then those backup pieces are not considered as part of FRA for auto managment.
- For Archivelogs backup to FRA use USE_DB_RECOVERY_FILE_DEST rather than giving explict path of FRA
- Bug 4911954
Details:
V$RECOVERY_FILE_DEST SPACE_USED and NUMBER_OF_FILES values may be wrong.
eg: Number of files in V$FLASH_RECOVERY_AREA_USAGE and V$RECOVERY_FILE_DEST are different.
This problem can lead to recovery area files being deleted even though there is no space pressure.
Fixed in : 10.2.0.3 , 11.1.0.6
- Bug 5106952
Details:
Flashback logs are not reclaimed by flash recovery area when using guaranteed
restore point (after dropping guaranteed restore point) or when changing
db_flashback_retention_target to a lower value.
Nov 16, 2010
Zone Commands
/usr/sbin/arp -a - nice way of finding what the global zone is.
Sep 22, 2010
sql escape character setup
Sep 21, 2010
sample login.sql using sql variabes
Use the new_value option in the sqlplus column command.
See the example below which grabs the instance name of the database that is being used.
SQL> set termout off timing off feedback off
SQL> column instance new_value instance_name
SQL> select instance_name instance from v$instance ;
SQL> set termout on timing on feedback on
SQL> prompt &instance_name
note: The first set statement hides the output from running the v$instance sql query.
Jun 24, 2010
excel - auto calculations
TOOLS/OPTIONS/CALCULATION and make sure that the automatic option is selected under "Calculation".
Jun 4, 2010
unix user management commands
Create New Group
# groupadd -g "groupid" "groupname"
Add Group to user, additional group
# usermod -G "groupname" "username"
Add Group to user, primary group
# usermod -g "groupname" "username"
Apr 16, 2010
unix - redirecting output
Use 2> /dev/null
i.e.:
df -k 2> /dev/null
This works when using the ksh shell. There will be other derivitives when using other shells.
Feb 3, 2010
transportable tablespaces
Refer to the relevant database documentation, correct version for restrictions when using this feature.
note:
a Ensure the following scripts have been run in the database. These would normally be run at database creation time.
$ORACLE_HOME/rdbms/admin/catplug.sql
$ORACLE_HOME/rdbms/admin/dbmsplts.sql
$ORACLE_HOME/rdbms/admin/prvtplts.plb
sql> desc dbms_plugts
b If running this procedure by a user other than sys then ensure the user has dba privileges and PUBLIC SYNONYMS for the following following have been created.
DBMS_PLUGTS
DBMS_TTS
1. Identify tablespaces that need to be migrated. note: Dependent data objects need to be incapsuated in the process. i.e.: Data + Index objects need to be included.
2. Put relevent tablespaces into readonly mode.
sql> alter tablespace ... readonly;
3. Export metadata from tablesspaces
unix> exp userid/password file=... tablespaces=... transport_tablespaces=y
note: multiple tablespaces need to be delimited by a comma.
4. Copy datafiles that make up the tablespaces identified above into the target environment.
5. Copy the export dat file created in step 3.
6. Import metadata into target database.
unix> imp ... tablespaces=... datafiles=... transport_tablespaces=y
note: tablespaces and datafiles need to be seperated by comma's.
7. Verify tablespaces are updated correctly by querying relevent views, dba_tablespaces and v$datafile.
8. Put tablespaces into read write mode in source and target databases.
sql> alter tablespace ... read write;
Dec 16, 2009
rank
For example, I needed to transform a database from OMF (oracle managed files) to OSF (oracle standard files). As you may know, OMF bear no resemblance to the datafile standard most corporates seem to run, a typical omf data file might look like o1_mf_ts_ofsaa_2gt2g1hr_.dbf, while a osf might look like user_01.dbf
Being a good dba I wanted to script and automate the CREATE CONTROLFILE statement. My soltion to the above problem was to use the rank function.
So something like -
select tablespace_name, file_name, rank() over (PARTITION BY tablespace_name order by file_id) "id"
solved my problem and produced an output something like -
tablespace1 somefile1 1
tablespace1 somefile2 2
tablespace2 somefile1 1
...
I was then able to use the above statement to generate the datafile section of the create controlfile file.
Dec 4, 2009
EXIT from PL/SQL procedure block
So if we run something like -
1 BEGIN
2 dbms_output.put_line('one.');
3 return;
4 dbms_output.put_line('two.');
5* end;
n990538@edrtst> /
one.
PL/SQL procedure successfully completed.
Oct 28, 2009
instr, substr
instr(string1, string2, start position, nth appearance) returns the position where the string exists.
where
string1 is the original string to search from
string2 is the string to search in string 1
start posititon is optional and is the start position to start searching from
nth appearance is optional and is the number of occurances of string2 in string1.
instr('Tech on the net', 'e', 1, 3) would return 14.
substr(string1, start position, length) returns a string.
where
string1 is the string to check.
start position is the position in the string to start the substring from
length is optional and the length of the position.
substr('Tech on the net',1,5) would return 'Tech '
Often using a combination of the above functions is useful.
substr('Tech on the net',1, instr('Tech on the net', 'e', 1, 3)) would return ''Tech on the ne'
Oct 21, 2009
bug - 2942857 - OERI:12327 from complex view merging
DOC ID 2942857.8
Fixed: 9.2.05, 10.1.0.2
Complex view merging may fail with ORA-600[12327] if an COUNT(*) is used and the query has a subquery predicate against the COUNT(*) .
Workaround: Set "_complex_view_merging"=false
Affects EDR, EDMT, DWH.
sed & awk script - find num SID entries in oratab
- remove blank lines from the start of each line
- Find entries based on input parameter - SID.
- find the number of entries.
cat oratab sed -e 's/^[ \t]*//' awk -F: '/^'"$SID"'/ { print $1 }' wc -l
truss
Use the following commands -
truss -ae -o truss.txt -p 123456
truss -f -o truss.txt abc
where
truss.txt is the output file.
123456 is the process id that the truss will run on.
abc is the program that truss will run on.
Oct 13, 2009
SGA
Fixed - Small and always constant depending on platform, os and database version
Variable (large pool, shared pool, java pool)
Database Buffer
Redo Log Buffer
10G
Oracle introduced memory management. Basically you set the following parameters and oracle manages the memory for you. The theory is the database will adjust the memory components as on a as required basis.
sga_taget <> 0
statistics_level = TYPICAL
Jul 22, 2009
zfs parameters
Show Parameters
zpool get
zfs get
There are many parameters that can be used, some which may prove useful are:
compression: Turn compress on at the file system level. Could be useful for staging area.
acl
Scenario 1:
databases like oracle, can create files etc on the database server. The os account that starts the database needs to have write permission on the directory structure. The ability that the database has should be conducted as part of the application and therefore it will depend on where these application directories are located. Best practice would suggest that these files should be available and even owned by a application owner.
Use ACL's to resolve this issue. In a nutshell, the owner and group of the file generated by the database is owned by an application owner and group. Give the oracle user or an oracle group read/write/execute permission on the underlying directory. In unix, ensusure setid for group is set. This ensures that dependent files adopt the permissions of the directory.
unix> chmod g+s dirname
unix> chmod A+group:grpname:read_data/write_data/execute:allow dirname
where grpname is the name of the group that is owned by the database owner.
When dealing with a hierarchical file structure, all directories up to parent should be included.
Warning 1:
if you chmod group permissions, then ACL's may be changed.
