The following are common scripts for Oracle DBAs.
1. Check data buffer and shared zone hit rate
- Declare
- Reads_value number (15 );
- Direct_value number (15 );
- Lob_value number (15 );
- Consical_value number (15 );
- Db_value number (15 );
- X number;
- Y number;
- Z number;
- Begin
- Select value into reads_value from v $ sysstat where name ='Physical reads';
- Select value into direct_value from v $ sysstat where name ='Physical reads direct';
- Select value into lob_value from v $ sysstat where name ='Physical reads direct (lob )';
- Select value into consical_value from v $ sysstat where name ='Consistent gets';
- Select value into db_value from v $ sysstat where name ='Db block gets';
- X: = direct_value + lob_value;
- Y: = 1-(reads_value-x)/(consical_value + db_value-x );
- Dbms_output.put_line ('Data buffer hit rate is :'| Y );
- If(Y & gt; = 0.9) then
- Dbms_output.put_line ('The data cache size with a hit rate greater than 0.9 is more appropriate');
- Else
- Dbms_output.put_line ('Data cache hit rate is less than 0.9. debug db_cache_size');
- EndIf;
- Select sum (pinhits-reloads)/sum (pins) into z from v $ librarycache;
- Dbms_output.put_line ('Shared area hit rate is :'| Z );
- If(Z >=0.9) then
- Dbms_output.put_line ('The shared area hit rate is greater than 0.9');
- Else
- Dbms_output.put_line ('Shared area hit rate is less than 0.9. debug db_cache_size');
- EndIf;
- End;
2. Check the usage of the table space.
- Select a. tablespace_name, total, free, (total-free)/total used from
- (Select tablespace_name, sum (bytes)/1024/1024 total from dba_data_files group by tablespace_name),
- (Select tablespace_name, sum (bytes)/1024/1024 free from dba_free_space group by tablespace_name) B
- Where a. tablespace_name = B. tablespace_name;
3. Check and table Space Generation statements
- -- Table Space Generation statement, run in SQL form
- Select dbms_metadata.get_ddl ('Tablespace', Tablespace_name) from dba_tablespaces;
- -- Table Generation statement
- Select dbms_metadata.get_ddl ('Table', Upper ('& TABLE_NAME'), Upper ('& USER_NAME') From dual;
4. Find out the statements with high cpu consumption and io IN THE SYSTEM
- Select SQL _TEXT, SQL _FULLTEXT from v $ SQL a where a. HASH_VALUE
- In(Select hash_value from v $ sqlarea where buffer_gets> 1000000
- Or disk_reads> 1000000/* Order by buffer_gets + disk_reads desc */);
5. Find the slow SQL statement in the current system
① Use the topas command in aix to find the pid with a relatively large cpu system
② Use the SQL statement method to find specific statements
- -- Spid is the process number
- Select SQL _TEXT, SQL _FULLTEXT, FIRST_LOAD_TIME from v $ SQL where ADDRESS = (select SQL _ADDRESS from v $ session where
- PADDR = (select ADDR from v $ process where spid = & spid ));
6. Find More tablespace fragments
- Select tablespace_name,
- Count (*) chunks,
- Max (bytes/1024/1024) max_chunk
- From dba_free_space
- Group by tablespace_name;
Note: the higher the score, the larger the tablespace fragmentation.