Oracle Notes
Database Reverse Engineer - Use Visio XP
SQL Editor - Toad
Change Management - Use Oracle Change Management Pack
To see rows processed by a query:
SELECT ROWS_PROCESSED RFOM V$SQLAREA WHERE UPPER(SQL_TEXT) like ‘%%’;
To see if something is rolling back:
SELECT USED_UBLK FROM V$TRANSACTION;
To drop Undo tablespace:
CREATE UNDO TABLESPACE UNDOTBS2 DATAFILE ‘d:\oradata\undotbs02.dbf’ SIZE 2M REUSE AUTOEXTEND ON;
ALTER SYSTEM SET UNDO_TABLESPACE = undotbs2;
DROP TABLESPACE undotbs1;
To monitor Undo tablespace:
SELECT BEGIN_TIME, END_TIME, UNDOTSN, UNDOBLKS, TXNCOUNT,
MAXCONCURRENCY AS “MAXCON”
FROM V$UNDOSTAT;
To switch Temporary tablespace:
CREATE TEMPORARY TABLESPACE TEMP2
TEMPFILE ‘temp02.dbf’ SIZE 5M AUTOEXTEND ON;
ALTER USER PFP_NEW TEMPORARY TABLESPACE TEMP2
DROP TABLESPACE TEMP;
To fix questionable statistics during an export:
set the NLS_LANG variable to the same as the database being exported.
To Flush Oracles Buffer Cache
Oracle 10g: alter system flush buffer_cache;
Oracle 9i: alter session set events = ‘immediate trace name flush_cache’;
To Import and skip tables.
If you have to use ignore=y to load into existing tables, would
be to make it “non-insertable” — eg: if the table is named “T”, rename T to
something else if it exists, and create a new table T that has the wrong
columns. imp will fail on it. afterwards, drop t and rename the other table
back.
To gather stats:
DBMS_STATS.GATHER_SCHEMA_STATS (
ownname=>’XXX’,
estimate_percent =>DBMS_STATS.AUTO_SAMPLE_SIZE,
block_sample=>FALSE,
method_opt=>’REPEAT’,
degree=>12,
granularity=>’DEFAULT’,
cascade=>TRUE,
options=>’GATHER STALE’,
no_invalidate=>TRUE,
gather_temp=>FALSE);
NOTE Gather stale requires you to put monitoring on for those tables which are to be analyzed. It ensures you only do stats if the table changes a lot so you can run stats more often.
Another point to remember is to monitor the results of stats especially with large tables (watch out for full table scans). We found dbms_stats would often get column cardinality (dba_tab_columns) wrong depending on sampling size and especially if we didnt use histograms.
ASKTOM.COM
the recommendation going forward is “dbms_stats” instead of analyze table
it is more flexible (you’ll love gather stale and alter table monitoring — you
only gather stats on that which you need). can run in parallel. is more
automated/automatable.
as with ANY big change — testing is important.
in general,
dbms_stats.gather_table_stats( user, ‘T’, method_opt => ‘for all indexed
columns’, cascade => true )
is more or less the same as
analyze table t compute statistics for table for all indexes for all indexed
columns;
method opt gets histograms
cascade gets indexes
gather_table_stats does the table
From AskTom:
But remember, keep saying
“full scans are not evil, indexes are not good”
“full scans are not evil, indexes are not good”
“full scans are not evil, indexes are not good”
“full scans are not evil, indexes are not good”
until you believe it.
AskTom On Perf Tuning Ratios:
ratios STINK ( i have stronger words but this is a public forum after all ).
There is one ratio I use — soft parse ratio (the ratio of soft to hard parses).
It should be near 100 for most systems. All other ratios — forget about them.
There is no magic “good number”. It is like the stupidest ratio of them all -
cache hit. I have a theory that systems with high cache hit ratios, over 95,
96% — are among the most poorly tuned systems.
Project-DBA:
Good or much experience, focuses on database technology, supports
the designers, involved in all design decisions, implements the data model,
coaches the developers, maintains all development databases, responsible for
versioning and deployment, is aware of all database related activities
Lookup Table Pros
http://asktom.oracle.com/pls/ask/f?p=4950:8:5639879985208498345::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:897311189461
Contract Contact
Kha Sang Phan kphan88@hotmail.com
Execute a script and not hang up
nohup sqlplus user/pass @compute.sql &
Schedule a Job
DECLARE
job_num NUMBER;
BEGIN
dbms_job.submit(
job_num,
‘p_checkqueue;’,
–start
SYSDATE,
–nextrun
’sysdate+1/24′
);
COMMIT;
END;
/
Send An Email
CREATE OR REPLACE PROCEDURE P_Checkqueue AS
c utl_smtp.connection;
v_cnt INT;
PROCEDURE send_header(name IN VARCHAR2, header IN VARCHAR2) AS
BEGIN
utl_smtp.write_data(c, name || ‘: ‘ || header || utl_tcp.CRLF);
END;
BEGIN
SELECT COUNT(*) INTO v_cnt FROM ACC_TRANSACTION;
IF ( v_cnt > 10 ) THEN
c := utl_smtp.open_connection(’smtp.sensis.com.au’);
utl_smtp.helo(c, ‘foo.com’);
utl_smtp.mail(c, ‘Ben.Smith@sensis.com.au’);
utl_smtp.rcpt(c, ‘Ben.Smith@sensis.com.au’);
utl_smtp.open_data(c);
send_header(’From’, ‘”Sender”
send_header(’To’, ‘”Recipient”
send_header(’Subject’, ‘Queue limit exceeded.’);
utl_smtp.write_data(c, utl_tcp.CRLF || ‘Queue is too big! Length: ‘ || v_cnt);
utl_smtp.close_data(c);
utl_smtp.quit(c);
END IF;
EXCEPTION
WHEN utl_smtp.transient_error OR utl_smtp.permanent_error THEN
BEGIN
utl_smtp.quit(c);
EXCEPTION
WHEN utl_smtp.transient_error OR utl_smtp.permanent_error THEN
NULL; — When the SMTP server is down or unavailable, we don’t have
— a connection to the server. The quit call will raise an
— exception that we can ignore.
END;
RAISE_APPLICATION_ERROR(-20000,
‘Failed to send mail due to the following error: ‘ || SQLERRM);
END;
/