Table: select * fromcat; select * fromtab; selecttable_namefromuser_tables; view: selecttextfromu
Table: select * from cat; select * from tab; select table_name from user_tables; view: select text from u
Table:
Select * from cat;
Select * from tab;
Select table_name from user_tables;
View:
Select text from user_views where view_name = upper ('& view_name ');
Index:
Select index_name, table_owner, table_name, tablespace_name, status from user_indexes order by table_name;
Trigger:
Select trigger_name, trigger_type, table_owner, table_name, status from user_triggers;
Snapshot:
Select owner, name, master, table_name, last_refresh, next from user_snapshots order by owner, next;
Synonym:
Select * from syn;
Sequence:
Select * from seq;
Database link:
Select * from user_db_links;
Constraints:
Select TABLE_NAME, CONSTRAINT_NAME, SEARCH_CONDITION, STATUS
From user_constraints WHERE TABLE_name = upper ('& TABLE_Name ');
This user's permission to read other user objects:
Select * from user_tab_privs;
System permissions of the User:
Select * from user_sys_privs;
User:
Select * from all_users order by user_id;
Free space remaining in the tablespace:
Select tablespace_name, sum (bytes) Total bytes, max (bytes), count (*) from dba_free_space group by tablespace_name;
Data Dictionary:
Select table_name from dict order by table_name;
Lock and Resource Information:
Select * from v $ lock; DDL lock not included
Database character set:
Select name, value $ from props $ where;
Inin. ora parameters:
Select name, value from v $ parameter order by name;
SQL sharing pool:
Select SQL _ text from v $ sqlarea;
Database:
Select * from v $ database
Control file:
Select * from V $ controlfile;
Redo log file information:
Select * from V $ logfile;
Log File Information from the control file:
Select * from V $ log;
Data File Information from the control file:
Select * from V $ datafile;
Current Value of the NLS parameter:
Select * from V $ nls_parameters;
Oracle version:
Select * from v $ version;
Description of the background process:
Select * from v $ bgprocess;
View version information:
Select * from product_component_version;
Oracle-common monitoring SQL
1. Waiting for monitoring cases:
Select event, sum (decode (wait_time, 1) prev, sum (decode (wait_time, 0) curr, count (*)
From v $ session_wait
Group by event order by 4;
2. rollback segment contention:
Select name, waits, gets, waits/gets ratio from v $ rollstat a, v $ rollname B where a. usn = B. usn;
3. I/O ratio of the monitored tablespace:
Select df. tablespace_name name, df. file_name "file", f. phyrds pyr, f. phyblkrd pbr, f. phywrts pyw,
F. phyblkwrt pbw
From v $ filestat f, dba_data_files df
Where f. file # = df. file_id
4. I/O ratio of the empty file system:
Select substr (a. file #, 1, 2) "#", substr (a. name, 1, 30) "name", a. status, a. bytes,
B. phyrds, B. phywrts
From v $ datafile a, v $ filestat B
Where a. file # = B. file #
5. Search for all indexes under a user:
Select user_indexes.table_name, user_indexes.index_name, uniqueness, column_name
From user_ind_columns, user_indexes
Where user_ind_columns.index_name = user_indexes.index_name
And user_ind_columns.table_name = user_indexes.table_name
Order by user_indexes.table_type, user_indexes.table_name,
User_indexes.index_name, column_position;
6. Monitor SGA hit rate
Select a. value + B. value "logical_reads", c. value "phys_reads ",
Round (100 * (a. value + B. value)-c. value)/(a. value + B. value) "BUFFER HIT RATIO"
From v $ sysstat a, v $ sysstat B, v $ sysstat c
Where a. statistic # = 38 and B. statistic # = 39
And c. statistic # = 40;
7. Monitor the hit rate of the Dictionary Buffer in SGA
Select parameter, gets, Getmisses, getmisses/(gets + getmisses) * 100 "miss ratio ",
(1-(sum (getmisses)/(sum (gets) + sum (getmisses) * 100 "Hit ratio"
From v $ rowcache
Where gets + getmisses <> 0
Group by parameter, gets, getmisses;
8. Monitor the hit rate of the shared cache area in SGA, which should be less than 1%
Select sum (pins) "Total Pins", sum (reloads) "Total Reloads ",
Sum (reloads)/sum (pins) * 100 libcache
From v $ librarycache;
Select sum (pinhits-reloads)/sum (pins) "hit radio", sum (reloads)/sum (pins) "reload percent"
From v $ librarycache;
9. display the category and size of all database objects
Select count (name) num_instances, type, sum (source_size) source_size,
Sum (parsed_size) parsed_size, sum (code_size) code_size, sum (error_size) error_size,
Sum (source_size) + sum (parsed_size) + sum (code_size) + sum (error_size) size_required
From dba_object_size
Group by type order by 2;
10. Monitor the log cache hit rate in SGA, which should be less than 1%
SELECT name, gets, misses, immediate_gets, immediate_misses,
Decode (gets, 100, misses/gets *) ratio1,
Decode (immediate_gets + immediate_misses, 0, 0,
Immediate_misses // (immediate_gets + immediate_misses) * 100) ratio2
FROM v $ latch WHERE name IN ('redo allocation', 'redo copy ');
11. Monitor the sorting ratio of memory to hard disk. It is best to make it smaller than. 10 and increase sort_area_size.
SELECT name, value FROM v $ sysstat WHERE name IN ('sorts (memory) ', 'sorts (disk )');
12. Monitor who is running the SQL statement of the current database
SELECT oSUSEr, username, SQL _ text from v $ session a, v $ sqltext B
Where a. SQL _ address = B. address order by address, piece;
13. Monitoring Dictionary Buffer
SELECT (SUM (PINS-RELOADS)/SUM (PINS) "lib cache" from v $ LIBRARYCACHE;
SELECT (SUM (GETS-GETMISSES-USAGE-FIXED)/SUM (GETS) "row cache" from v $ ROWCACHE;
Select sum (PINS) "EXECUTIONS", SUM (RELOADS) "cache misses while executing" from v $ LIBRARYCACHE;
The latter is divided by the former. This ratio is less than 1%, and it is better to close to 0%.
Select sum (GETS) "dictionary gets", SUM (GETMISSES) "dictionary cache get misses"
From v $ ROWCACHE
14. Find the ORACLE Character Set
Select * from sys. props $ where;
15. Monitor MTS
Select busy/(busy + idle) "shared servers busy" from v $ dispatcher;
When the value is greater than 0.5, the parameter must be increased.
Select sum (wait)/sum (totalq) "dispatcher waits" from v $ queue where type = 'dispatcher ';
Select count (*) from v $ dispatcher;
Select servers_highwater from v $ mts;
When servers_highwater is close to mts_max_servers, increase the Parameter
16. Fragmentation degree
Select tablespace_name, count (tablespace_name) from dba_free_space group by tablespace_name
Having count (tablespace_name)> 10;
Alter tablespace name coalesce;
Alter table name deallocate unused;
Create or replace view ts_blocks_v
Select tablespace_name, block_id, bytes, blocks, 'free space' segment_name from dba_free_space
Union all
Select tablespace_name, block_id, bytes, blocks, segment_name from dba_extents;
Select * from ts_blocks_v;
Select tablespace_name, sum (bytes), max (bytes), count (block_id) from dba_free_space
Group by tablespace_name;
View tables with high fragmentation levels
SELECT segment_name table_name, COUNT (*) extents
FROM dba_segments WHERE owner not in ('sys ', 'system') group by segment_name
Having count (*) = (select max (COUNT (*) FROM dba_segments group by segment_name );
17. Check the storage of tables and Indexes
Select segment_name, sum (bytes), count (*) ext_quan from dba_extents where
Tablespace_name = '& tablespace_name' and segment_type = 'table' group by tablespace_name, segment_name;
Select segment_name, count (*) from dba_extents where segment_type = 'index' and owner = '& owner'
Group by segment_name;
18. Find a user session with multiple CPUs
12 is cpu used by this session
Select a. sid, spid, status, substr (a. program, 60/100) prog, a. terminal, osuser, value/value
From v $ session a, v $ process B, v $ sesstat c
Where c. statistic # = 12 and c. sid = a. sid and a. paddr = B. addr order by value desc;
20. Monitor the usage of log_buffer: (the value should be smaller than 1%; otherwise, increase the size of log_buffer)
Select rbar. name, rbar. value, re. name, re. value, (rbar. value * 100)/re. value | '%' "radio"
From v $ sysstat rbar, v $ sysstat re
Where rbar. name = 'redo buffer allocation retries'
And re. name = 'redo entries ';
19. view the running SQL statements:
Select SQL _ TEXT
From v $ SQL
Common Oracle SQL statements
Query table structure
Select substr (table_name, 1, 20) tabname,
Substr (column_name, 1, 20) column_name,
Rtrim (data_type) | '(' | data_length | ')' from system. dba_tab_columns
Where owner = 'username'
Table space usage status
Select a. file_id "FileNo", a. tablespace_name "Tablespace_name ",
Round (a. bytes/1024/1024, 4) "Total MB ",
Round (a. bytes-sum (nvl (B. bytes, 0)/1024/1024, 4) "Used MB ",
Round (sum (nvl (B. bytes, 0)/1024/1024, 4) "Free MB ",
Round (sum (nvl (B. bytes, 0)/a. bytes * 100,4) "% Free"
From dba_data_files a, dba_free_space B
Where a. file_id = B. file_id (+)
Group by a. tablespace_name,
A. file_id, a. bytes order by a. tablespace_name
Queries a table in a mode where data is not empty.
Declare
Cursor c is select TNAME from tab;
VCount Number;
Table_nm Varchar2 (100 );
Sq varchar2 (300 );
Begin
For r in c loop
Table_nm: = r. TNAME;
Sq: = 'select count (*) from' | table_nm;
Execute immediate sq into vCount;
If vCount> 0 then
Dbms_output.put_line (r. tname );
End if;
End loop;
End;
Client host information
SELECT
SYS_CONTEXT ('userenv', 'terminal') TERMINAL,
SYS_CONTEXT ('userenv', 'host') HOST,
SYS_CONTEXT ('userenv', 'OS _ user') OS _USER,
SYS_CONTEXT ('userenv', 'IP _ address') IP _ ADDRESS
FROM DUAL
View rollback segment name and size
COLUMN roll_name FORMAT a13 HEADING 'rollback name'
COLUMN tablespace FORMAT a11 HEADING 'tablspace'
COLUMN in_extents FORMAT a20 HEADING 'init/Next extents'
COLUMN m_extents FORMAT a10 HEADING 'min/Max extents'
COLUMN status FORMAT a8 HEADING 'status'
COLUMN wraps FORMAT 999 HEADING 'wraps'
COLUMN shrinks FORMAT 999 HEADING 'shrink'
COLUMN opt FORMAT 999,999,999 HEADING 'opt. size'
COLUMN bytes FORMAT 999,999,999 HEADING 'bytes'
COLUMN extents FORMAT 999 HEADING 'extents'
SELECT
A. owner | '.' | a. segment_name roll_name
, A. tablespace_name tablespace
, TO_CHAR (a. initial_extent) | '/' |
TO_CHAR (a. next_extent) in_extents
, TO_CHAR (a. min_extents) | '/' |
TO_CHAR (a. max_extents) m_extents
, A. status
, B. bytes
, B. extents
, D. shrinks
, D. wraps
, D. optsize opt
FROM
Dba_rollback_segs
, Dba_segments B
, V $ rollname c
, V $ rollstat d
WHERE
A. segment_name = B. segment_name
AND a. segment_name = c. name (+)
AND c. usn = d. usn (+)
Order by a. segment_name;