The common SQL statement you summarized and found to help your work!
View the name and size of the table space:
SQL> SELECT T.TABLESPACE_NAME, ROUND (SUM (Bytes / (1024 * 1024)), 0) TS_SIZE
From DBA_TABLESPACES T, DBA_DATA_FILES D where t.tablespace_name = d.tablespace_name group by t.tablespace_name;
View the name and size of the physical file of the tablespace:
SQL> SELECT TABLESPACE_NAME, FILE_ID, FILE_NAME, ROUND (Bytes / (1024 * 1024), 0) Total_Space from DBA_DATA_FILES ORDER BY TABLESPACE_NAME
View the name and size of the roll:
SQL> Select segment_name, tablespace_name, r.status,
(Initial_extent / 1024) InitialeXtent, (Next_EXTENT / 1024) Nextextent,
Max_EXTENTS, V.Curext Curextent from DBA_ROLLBACK_SEGS R, V $ ROLLSTAT V
WHERE R.SEGMENT_ID = V.USN ( ) ORDER BY Segment_Name;
How to check what something in a rollover or run or what SQL statement is being executed:
SQL> SELECT D.SQL_Text, A.Name from V $ ROLLNAME A, V $ TRANSACTION B, V $ Session C, V $ SQLText D Where A.usn = B.XIDUSN and B.Addr = C.TADDR and C.SQL_Address = D.Address and C.SQL_Hash_Value = D.hash_Value and A.usn = 1;
(Note: Which one you want to see, just write USN =?
View the control file:
SQL> SELECT * FROM V $ ControlFile;
View log files:
SQL> COL MEMBER FORMAT A50
SQL> SELECT * FROM V $ logfile;
How to view the current SQL * Plus user's SID and Serial #:
SQL> SELECT SID, Serial #, Status from v $ session where audsid = uchesserenv ('sessionID');
How to view the character set of the current database:
SQL> SELECT Userenv ('Language') from Dual;
SQL> SELECT Userenv ('lang') from dual;
How to determine what SQL optimization method currently is currently using:
Use the Explain Plan to generate an Explain Plan, check the value of the POSITION column of id = 0 in Plan_Table.
SQL> SELECT DECODE (nVL (position, -1), - 1, 'RBO', 1, 'CBO') from plan_table where id = 0;
How to view the current latest SCN number:
SQL> SELECT MAX (KTuxescnw * Power (2,32) KTUXESCNB) from W $ KTUXE;
Find scripts for trace files in Oracle:
SQL> SELECT U_DUMP.VALUE || '/' || instance.value || '_ora_' || V $ process.spid || NVL2 (V $ process.traceid, '_' || V $ process.traceid, null ) || '.trc' "trace" from V $ Parameter u_dump cross Join V $ PRAMETER INSTANCE CROSS JOIN V $ Process.addr = V $ session.paddr where u_dump.name = 'user_dump_dest 'and
Instance.name = 'instance_name' and v $ session.audsid = sys_context ('useerenv', 'sessionID');
SQL> SELECT D.VALUE || '/ ORA_' || P.SPID || '.trc' trace_file_namefrom (SELECT P.SPID from Sys.v_ $ MyStat M, Sys.V_ $ Session S, SYS.V_ $ PROCESS P Where m.statistic # = 1 ands.SID = m.sid and p.addr = s.paddr) p, (Select Value from sys.v_ $ parameter where name = 'user_dump_dest') d;
How to view the client login IP address:
SQL> SELECT SYS_CONText ('useerenv', 'ip_address') from dual;
How to create a trigger for tracking client IP addresses in the production database:
SQL> Create or Replace Trigger ON_LOGON_TRIGGER
After Logon on Database
Begin
DBMS_Application_info.set_client_info (sys_context ('useerenv', 'ip_address'));
END;
Query the current date:
SQL> SELECT TO_CHAR (Sysdate, 'YYYY-MM-DD, HH24: MI: SS') from DUAL
View all tablespaces corresponding to the data file name:
SQL> SELECT DISTINCT FILE_NAME, TABLESPACE_NAME, AUTOEXTENSIBLE from DBA_DATA_FILES
View the usage of the table space:
SQL> SELECT SUM (BYTES) / (1024 * 1024) As Free_Space, TableSpace_name
From DBA_FREE_SPACE GROUP BY TABLESPACE_NAME;
SQL> SELECT A.TABLESPACE_NAME, A.BYTES TOTAL, B.BYTES USED, C.BYTES Free,
(B.Bytes * 100) /a.bytes "% used", (C.BYTES * 100) /A.BYTES "% free"
From sys.sm $ TS_AVAIL A, SYS.SM $ TS_USED B, SYS.SM $ TS_FREE C
WHERE A.TABLESPACE_NAME = B.TABLESPACE_NAME AND A.TABLESPACE_NAME = C.TABLESPACE_NAME; SQL> column tablespace_name format a18; SQL> column Sum_M format a12; SQL> column Used_M format a12; SQL> column Free_M format a12; column pto_M format 9.99; SQL> SELECT S.TABLESPACE_NAME, CEIL (SUM (S.BYTES / 1024/1024)) || 'M' SUM_M, CEIL (SUM (SUM (S.USEDSPACE / 1024/1024)) || 'M' USED_M, CEIL (SUM (S.FREESPACE / 1024/1024)) || 'M' Free_M, SUM (S.USEDSPACE) / SUM (S.BYTES) PTUSED
From (Select B.File_ID, B.Tablespace_Name, B.bytes, (B.bytes-Sum (NVL (A.bytes, 0))) UsedSpace, SUM (NVL (A.BYTES, 0)) FreeSpace, (SUM NVL (A.BYTES, 0)) / (B.bytes)) * 100 FreePercentratio from sys.dba_free_space a, sys.dba_data_files b where A.File_ID ( ) = B.file_id group by b.file_id, b.tablespace_name, B.bytes Order By B.TABLESPACE_NAME) S Group by S.Tablespace_name Order By Sum (S.Freespace) / SUM (S.BYTES) DESC;
View the HWM of the data file (you can resize minimum space) and file header size:
SQL> SELECT v1.file_name, v1.file_id, num1 totle_space, num3 free_space, num1-num3 "USED_SPACE (HWM)", nvl (num2,0) data_space, num1-num3-nvl (num2,0) file_headFROM (SELECT file_name, file_id, SUM (bytes) num1 FROM Dba_Data_Files GROUP BY file_name, file_id) v1, (SELECT file_id, SUM (bytes) num2 FROM dba_extents GROUP BY file_id) v2, (SELECT file_id, SUM (bYTES) num3 FROM DBA_FREE_SPACE GROUP BY file_id) v3WHERE v1.file_id = v2.file_id ( ) and v1.file_id = v3.file_id ( );
View data file size and head size:
SQL> SELECT v1.file_name, v1.file_id, num1 totle_space, num3 free_space, num1-num3 Used_space, nvl (num2,0) data_space, num1-num3-nvl (num2,0) file_head FROM (SELECT file_name, file_id, SUM ( bytes) num1 FROM Dba_Data_Files GROUP BY file_name, file_id) v1, (SELECT file_id, SUM (bytes) num2 FROM dba_extents GROUP BY file_id) v2, (SELECT file_id, SUM (bYTES) num3 FROM DBA_FREE_SPACE GROUP BY file_id) v3 WHERE v1.file_id = V2.File_ID ( ) and v1.file_id = v3.file_id ( ); (running above the query, we can ask the following information: Totle_pace: The total size of the data file, byte is unit free_space: the data file is rest Size, byte is a useful space for this data file, byte as unit_space: This data file is spaced in the data space, which is data space, byte. File_Head: This data file header is occupied, word Section unit)
Check of various tablespace growth in the database:
SQL> SELECT A.TABLESPACE_NAME, (1- (a.total) /b.total) * 100 USED_PERCENT
From (select tablespace_name, sum (bytes) total from dba_free_space group by tablespace_name) A, (select tablespace_name, sum (bytes) total from dba_data_files group by tablespace_name) B where A.tablespace_name = B.tablespace_name;
SQL> SELECT UPPER (F.TABLESPACE_NAME) "Table Space Name", D. Tot_Grootte_MB "Table Space Size (M)", D. Tot_Grootte_MB - F. Total_Bytes "has been used with space (M)", to_CHAR (Round) TOT_GROOTTE_MB - F. TOTAL_BYTES) / D. Tot_Grootte_MB * 100, 2), '990.99') "User, F. Total_bytes" Idle Space (M) ", f.max_bytes" Maximum Block (M) "from (SELECT TABLESPACE_NAME Round (SUM (BYTES) / (1024 * 1024), 2) Total_Bytes, Round (Max (Bytes) / (1024 * 1024), 2) Max_Bytes from sys.dba_free_space group by tablespace_name) f, (Select Dd.TablesPace_Name, Round (SUM (DD.BYTES) / (1024 * 1024), 2) TOT_GROOTTE_MB from from sys.dba_data_files dd group by dd.tablespace_name) D where d.tablespace_name = f.tablespace_name
ORDER BY 4 DESC; view each table space occupation disk condition: SQL> Col TableSpace_name Format A20; SQL> SELECT B.FILE_ID File_ID, B.TABLESPACE_NAME TABLESPACE_NAME, B.BYTES BYTES, (B.BYTES-SUM (NVL (A.bytes , 0))) Used, SUM (NVL (A.BYTES, 0)) Free, SUM (NVL (A.bytes, 0)) / (B.bytes) * 100 Percent from DBA_FREE_SPACE A, DBA_DATA_FILES B Where A.FILE_ID = B.file_id group by b.tablespace_name, b.file_id, b.bytes order by b.file_id;
The database object is checked in the next extension and the FREE extension value of the table space:
SQL> SELECT A.TABLE_NAME, A.NEXT_EXTENT, A.TABLESPACE_NAME
From all_tables a, (Select TableSpace_name, max (bytes) AS BIG_CHUNK
From DBA_FREE_SPACE GROUP BY TABLESPACE_NAME) F Where f.tablespace_name = a.tablespace_name and a.next_extent> f.big_chunk
Union Select a.index_name, a.next_extent, a.tablespace_name
From all_indexes a, (Select TableSpace_name, max (bytes) AS BIG_CHUNK
From DBA_FREE_SPACE GROUP BY TABLESPACE_NAME) F Where f.tablespace_name = a.tablespace_name and a.next_extent> f.big_chunk;
Get the highest SQL statement of Disk Read:
SQL> SELECT SQL_TEXT FROM (SELECT * FROM V $ SQLAREA Order by Disk_reads)
WHERE ROWNUM <= 5;
Find the top ten performance poor SQL:
SQL> SELECT * FROM (SELECT PARSING_USER_ID EXECUTIONS, SORTS, Command_Type, Disk_reads, SQL_Text from V $ SQLAREA Order by Disk_Reads Desc) Where rownum <10;
5 system waiting events for the most waiting time:
SQL> SELECT * FROM (SELECT * from V $ system_event where event not limited "sql% 'order by total_waits desc) Where rownum <= 5;
View sessions of the current waiting event:
SQL> Col UserName Format A10
SQL> SET LINE 120
SQL> Col Event Format A30
SQL> Select S.SID, S.Username, SE.Event, Se.Total_Waits, Se.Time_WaITED, SE.average_wait
From v $ session s, v $ session_event se Where S.Username is not null and se.SID = S.SID
And S.status = 'Active' and se.event not like '% SQL * Net%'; SQL> SELECT SID, Event, P1, P2, P3, WAIT_TIME, SECONDS_IN_WAIT, State from V $ Session_Wait Where Event Not Like '% Message% 'and Event Not Like' SQL * Net% 'and Event Not Like'% Timer 'and Event! =' Wakeup Time Manager '
Find the current wait event related to the connected session:
SQL> Select sw.SID, S.Username, sw.event, sw.wait_time, sw.state, sw.seconds_in_wait sec_in_wait
From v $ session s, v $ session_wait sw where s.usename is not null and sw.sid = s.sid
And sw.event not like '% SQL * Net%' Order by sw.wait_time desc;
Oracle's check: check:
SQL> SELECT Segment_Name, Owner, TableSpace_name, Initial_EXTENT, NEXT_EXTENT, DBA_ROLLBACK_SEGS.STATUS from DBA_ROLLBACK_SEGS, V $ dataFile Where File_ID = file #;
Oracle rollback segment extension information check:
SQL> COL Name Format A10
SQL> SET LINESIZE 140
SQL> Select Substr (Name, 1,40) Name, Extents, Rssize, Optsize, Aveactive, Extends, Wraps, Shrinks, HWMSIZE
From V $ ROLLNAME RN, V $ ROLLSTAT RS WHERE (RN.USN = rs.usn);
EXTENTS: Quantity in the rollback segment.
RSSIZE: The size of the rollback segment in bytes.
OPTSIZE: The value set for the Optimal parameter.
AveActive: The size of the average space that is released from bytes in bytes from the rollback segment is deleted.
Extends: The number of times the system is incremented by the rollover section.
Shrinks: The number of times the system is removed from the rollback segment (ie rollback segment shrinkage). When the rollback segment is removed, the system may eliminate one or more panels from this rollback segment.
HWMSIZE: The upper limit of the segment size, that is, the maximum size that has been reached back to the segment.
(If the average size of the rollback segment is close to Optimal, then the value of Optimal is set correctly. If the number of dynamic growth of the rollback segment is high or the number of shrinkage is high, then it is necessary to improve the value of Optimal)
View the use of the rollback segment, which user is using the resource of the rollback segment:
SQL> SELECT S.USERNAME, U.NAME FROM V $ Transaction T, V $ ROLLSTAT R, V $ ROLLNAME U, V $ session s where s.taddr = t.addr andt.xidusn = r.usn and r.usn = u.usn order by S.Username;
How to check one Shared_Server is busy with:
SQL> Select A.Username, A.Machine, A.Program, A.SID, A.Serial #, A.STATUS, C.PIECE, C.SQL_TEXTFROM V $ SESSION A, V $ Process B, V $ SQLText Cwhere B .SPID = 13161 and b.addr = a.paddrand a.sql_address = c.address ( ) Order by c.piece; Database Sharing Cool Performance Check:
SQL> Select Namespace, Gets, Gethitratio, Pins, Pinhitratio, Reloads,
Invalidations from V $ LibraryCache Where Namespace in
('Sqlarea', 'Table / Procedure', 'Body', 'Trigger');
Check data overload ratio:
SQL> Select SUM (Reloads) / Sum (Pins) * 100 "Reload Ratio" from
V $ librarycache;
Check the hit rate of the data dictionary:
SQL> SELECT 1-SUM (GETMISSES) / SUM (Gets) "Data Dictionary Hit
Ratio "from V $ rowcache;
(For library cache, gethitratio and pinhitratio should be greater than 90%, for data overload ratio, RELOAD RATIO should be less than 1%, for the hit rate of data dictionary, Data Dictionary Hit Ratio should be greater than 85%)
Check the surplus of shared memory:
SQL> SELECT REQUEST_MISSES, Request_Failures from V $ Shared_pool_reserve;
(Request_Misses and Request_Failures should be close to 0) for the surplus of shared memory.
Data cache performance check:
SQL> SELECT 1-P.Value / (B.Value C.Value) "DB Buffer Cache Hit
Ratio "from V $ SYSSTAT P, V $ SYSSTAT B, V $ sysstat c where
P.Name = 'Physical Reads' and B.Name = 'DB Block Gets' and
C.Name = 'Consistent Gets';
Check if buffer pool hit_ratio
SQL> SELECT NAME, (Physical_Reads / (DB_BLOCK_GETS CONSITENT_GETS))
"Miss_hit_ratio" from v $ buffer_pool_statistics where (db_block_gets consistent_gets)> 0;
(Normal time DB Buffer Cache Hit Ratio should be greater than 90%, and the buffer pool miss_hit_ratio should be less than 10% when normal.
Database backlink segment performance check:
Check Ratio Execution
SQL> SELECT SUM (WAITS) * 100 / SUM (Gets) "Ratio", SUM (Waits)
"Waits", SUM (Gets) "Gets" from V $ ROLLSTAT D;
Check count / value execution:
SQL> SELECT CLASS, Count From V $ Waitstat Where Class Like '% Undo%'
SQL> SELECT VALUE from V $ sysstat where name = 'consistent gets'; (both VALUE value)
Check if Average_WaIT execution:
SQL> SELECT EVENT, TOTAL_WAITS, TIME_WAITED, AVERAGE_WAIT from V $ SYSTEM_EVENT
WHERE EVENT LIKE '% UNDO%';
Check if RBS Header Get Ratio is executed:
SQL> SELECT N.NAME, S.USN, S.WRAPS, DECODE (S.Waits, 0, 1, 1- S.Waits / S.Gets) "RBS
Header Get Ratio "from V $ ROLLSTAT S, V $ ROLLNAME N where s.usn = n.usn;
(Normal time Ratio should be less than 1%, count / value should be less than 0.01%, Average_wait is preferably 0, the smaller the value, the better, the RBS Header Get Ratio should be greater than 95%)
Kill the script:
SQL> SELECT A.SID, B.SPID, A.Serial #, A.LockWait, A.USERNAME, A. OSUSER, A.LOGON_TIME, A.LAST_CALL_ET / 3600 Last_HOUR, A.STATUS, 'ORAKILL' || SID | | '|| spid host_command,' alter system kill session '' || a.sid || ',' || a.serial # || '' '' SQL_COMMANDFROM V $ Session A, V $ Process B Where a .Paddr = B.Addr and sid> 6;
View the performance of the sort segment:
SQL> SELECT NAME, VALUE FROM V $ SYSSTAT WHERE NAME IN ('Sorts (AMORY)', 'Sorts (Disk);
View Database Library Object:
SQL> Select Owner, Object_Type, Status, Count (*) Count # from all_Objects group by Owner, Object_Type, Status
View the version of the database:
SQL> SELECT * FROM V $ VERSION;
View the creation date and archive of the database:
SQL> SELECT CREATED, LOG_MODE, LOG_MODE FROM V $ DATABASE;
Capture SQL running for a long time:
SQL> Column UserName Format A12
SQL> Column Opname Format A16
SQL> Column ProGress Format A8
SQL> select username, sid, opname, round (sofar * 100 / totalwork, 0) || '%' as progress, time_remaining, sql_text from v $ session_longops, v $ sql where time_remaining <> 0 and sql_address = address and sql_hash_value = Hash_Value;
View the parameters of the data sheet:
SQL> SELECT partition_name, high_value, high_value_length, tablespace_name, pct_free, pct_used, ini_trans, max_trans, initial_extent, next_extent, min_extent, max_extent, pct_increase, FREELISTS, freelist_groups, LOGGING, BUFFER_POOL, num_rows, blocks, empty_blocks, avg_space, chain_cnt, avg_row_len, sample_size , Last_Analyzed from DBA_TAB_PARTITIONS - WHERE TABLE_NAME =: TName and Table_owner =: TownerRDer by partition_position; View Yisheng Yicheng:
SQL> SELECT * from V $ located_Object;
SQL> SELECT * FROM V $ Transaction;
Find Object to which process is used:
SQL> Select P.SPID, S.SID, S.Serial # Serial_Num, S.Username User_Name, A.TYPE OBJECT_TYPE, S.OSUSER OS_USER_NAME, A.OWNER, A. Object Object_name, Decode (Sign (48 - Command), 1, To_char (Command), 'Action Code #' || To_char (Command)) Action, P.Program Oracle_Process, S.Terminal Terminal, S.Program Program, S.Status Session_Status from V $ Session S, V $ Access A , v $ process p where s.paddr = p.addr and s.type = 'user' and a.sid = s.sid and a.Object = 'subscriber_attr'order by S.Username, S. OSUSER;
View the rollback segment:
SQL> COL Name Format A10
SQL> SET LINESIZE 100
SQL> select rownum, sys.dba_rollback_segs.segment_name Name, v $ rollstat.extents Extents, v $ rollstat.rssize Size_in_Bytes, v $ rollstat.xacts XActs, v $ rollstat.gets Gets, v $ rollstat.waits Waits, v $ rollstat .writes Writes, sys.dba_rollback_segs.status status from v $ rollstat, sys.dba_rollback_segs, v $ rollname where v $ rollname.name ( ) = sys.dba_rollback_segs.segment_name and v $ rollstat.usn ( ) = v $ rollname .usn order by rownum
View the resource process (TOP session):
SQL> Select s.schemaname schema_name, decode (48 - command), 1, to_char (command), 'action code #' || to_char (command)) action, status session_status, s.suser os_user_name, s.SID, P.SPID, S. Serial # Serial_Num, NVL (S.Username, '[Oracle Process]') User_Name, S.Terminal Terminal, S.Program Program, St.Value Criteria_Value from V $ SESSSTAT ST, V $ Session S, v $ process p where st.sid = s.SID and st.statistic # = to_number ('38 ') and (' all '=' all 'or s.status =' all ') and p.addr = s.paddr Order by St.Value DESC, P.SPID ASC, S.USERNAME ASC, S.OSUSER ASC; Find the corresponding statement according to PID:
SQL> SELECT A.USERNAME,
A. Machine, A.Program, A.SID, A.Serial #, A.STATUS, C.PIECE, C.SQL_Text
From v $ sessions a, v $ process b, v $ sqltext c where b.spid = SPID
And B.Addr = a.paddr and a.sql_address = c.address ( ) Order by C.Piece;
Looking for a process of Oracle according to SID:
SQL> SELECT Pro.SPID from V $ Session SES, V $ Process Pro Where Ss.SID = 21 and SES.PADDR = Pro.Addr;
Monitor the current database who is running what SQL statement: SQL> SELECT OSUSER, UserName, SQL_Text from V $ Session A, V $ SQLText B where a.sql_address = B.Address Order By Address, Piece
How to view a user in the database, what SQL statement is running
SQL> SELECT SQL_TEXT FROM V $ SQLText T, V $ session s where t.address = s.sql_address
And T.hash_Value = s.sql_hash_value and s.machine = 'xxxxx' or usrname = 'wacos';
How to detect the SQL statement that the reception is being issued:
SQL> SELECT User_name, SQL_Text from V $ Open_CURSOR WHERE SID IN (SELECT SID, Serial # from v $ session where status = 'Active'));
Query the current SQL statement:
SQL> SELECT Program, SQL_Address from V $ Session WHERE PADDR in (SELECT ADDR
From v $ process where spid = 3556);
Program SQL_Address
------------------------------------------------ -------------- SQLPLUS @ CTC20 (TNS V1-V3) 000000038FCB1A90
SQL> SELECT SQL_TEXT FROM V $ SQLAREA WHERE Address = '000000038FCB1A90'
Find the SQL statement corresponding to the process consumed the highest CPU:
SQL> Set line 240
SQL> SET VERIFY OFF
SQL> Column Sid Format 999
SQL> Column Pid Format 999
SQL> Column S_ # Format 999
SQL> Column UserName Format A9 Heading "ORA User"
SQL> Column Program Format A29
SQL> Column SQL Format A60
SQL> Column OsName Format A9 Heading "OS User"
SQL> Select P.PID PID, S.SID SID, P.SPID SPID, S.USERNAME UserName,
S.OSuser osname, p.serial # s _ #, p.Terminal, P.Program Program,
P. Background, S.Status, Rtrim (Substr (A.SQL_Text, 1, 80)) SQL
From V $ Process P, V $ Session S, v $ sqlarea a where p.addr = s.paddr
And S.SQL_Address = a.address ( ) and p.spid Like '% & 1%;
Enter Value for 1: PID (here you enter PIDs with the highest process of CPU)
SQL> SET TERMOUT OFF
SQL> spool maxcpu.txt
SQL> SELECT ' || S.Username Username,
RTRIM (a.sql_text, chr (10), '')) || ';' From V $ Process P, V $ Session S,
V $ sqlarea a where p.addr = s.paddr and s.sql_address = a.address ( )
And P.spid Like '% && 1%';
Enter Value for 1: PID (here you enter PIDs with the highest process of CPU)
Spool off (this sentence is in the final execution)
Acquisition of 2 SQL statements with the highest CPU rate
Execute: Top, get the PID of the process of the highest CPU usage through TOP.
SQL> select sql_text, spid, v $ session.program, process from v $ sqlarea, v $ session, v $ process where v $ sqlarea.address = v $ session.sql_address and v $ sqlarea.hash_value = v $ session.sql_hash_value
And v $ session.paddr = v $ process.addr and v $ process.spid in (pid);
SQL> Col Machine Format A30 SQL> Col g 200 SQL> SET LINE 200 SQL> Select SID, Serial #, Username, OSuser, Machine, Program, Process, To_Char (Logon_Time, 'YYYY / MM / DD HH24: MI: SS ') from v $ session where paddr in (select addr from v $ process where spid in ([$ spid])); SQL> select sql_text from v $ sqltext_with_newlines where hash_value = (select SQL_HASH_VALUE from v $ session where sid = & sid) ORDER by Piece;
View Lock (LOCK):
SQL> SELECT / * Rule * / LS.OSUSER OS_USER_NAME, LS.USERNAME USER_NAME, DECODE (Ls.Type, 'RW', 'Row Wait Enqueue Lock ",' TM ',' DML Enqueue Lock ',' TX ', 'Transaction Enqueue Lock', 'UL', 'User Supplied Lock') Lock_Type, O.Object_name Object, Decode (Ls.Lmode, 1, Null, 2, 'Row Share', 3, 'Row Exclusive', 4, ' Share ', 5,' Share Row Exclusive ', 6,' Exclusive ', NULL) LOCK_MODE, O.OWNER, LS.SID, LS.SERIAL # Serial_Num, Ls.ID1, LS.ID2 from sys.dba_objects O, (Select S. Orsuser, S.Username, L. Type, L.Lmode, S.SID, S.Serial #, L.ID1, L.ID2 from V $ Session S, V $ LOCK L Where s.SID = L.SID ) ls where object_id = ls.id1 and o.owner <> sys' order by o.owner, o.object_name;
SQL> Select sys.v_ $ session.osuser, sys.v_ $ session.machine, V $ lock.sid, sys.v_ $ session.serial #, decode (V $ loc.TYPE, 'MR', 'Media Recovery " , 'RT', 'Redo Thread', 'Un', 'User Name', 'TX', 'Transaction', 'TM', 'DML', 'UL', 'PL / SQL User Lock', 'DX' , 'Distributed XAction', 'CF', 'Control File', 'IS', 'Instance State', 'FS', 'File Set', 'IR', 'Instance Recovery', 'St', 'Disk Space Transaction ',' TS ',' Temp Segment ',' IV ',' Library Cache Invalida-Tion ',' Ls ',' Log Start Or Switch ',' RW ',' Row Wait ',' SQ ',' Sequence Number ',' TE ',' TEMP TABLE ',' UNKNOWN ') LOCKTYPE, RTRIM (Object_Type) ||' '|| RTRIM (OWNER) ||'. '|| Object_Name Object_name, Decode (LMODE, 0, 'NONE', 1, 'NULL', 2, 'ROW-S', 3, 'ROW-X', 4, 'Share', 5, 'S / ROW-X', 6, 'Exclusive', 'unknown') LockMode, Decode (Request, 0, 'None', 1, 'Null', 2, 'Row-S', 3, 'Row-x', 4, 'Share', 5, 'S / row-x', 6, 'Exclusive', 'unknown') RequestMode, CTIME, BLOCK B from V $ LOCK, All_Objects, Sys.V_ $ Session Where V $ LOCK.SID> 6 and Sys.v_ $ session .sid = V $ lock.sid and v $ lock.id1 = all_obj ECTS.OBJECT_ID;
With DBA roles, see the current database locks can be used as the following SQL statement: SQL> Col Owner for A12 SQL> Col Object_name for A16 SQL> SELECT B.OWNER, B.Object_name, L.Session_ID, L.LOCKED_MODE FROM V $ locked_object l, dba_objects b where b.object_id = l.object_id; SQL> select t2.username, t2.sid, t2.serial #, t2.logon_time from v $ locked_object t1, v $ session t2 where t1.session_id = t2. Sid Order by t2.logon_time; SQL> SELECT SQL_ADDRESS FROM V $ sessions where sid =
; SQL> SELECT * FROM V $ SQLTEXT where address =
;
SQL> Select Command_Type, Piece, SQL_Text from V $ SQLText WHERE Address = (SELECT SQL_ADDRESS FROM V $ Session a where sid = 18);
SQL> SELECT Object_id from v $ locked_Object;
SQL> Select Object_name, Object_Type from DBA_Objects Where Object_ID = ''; if there is a long-term one column, it may be a lock that is not released. We can use the following SQL statement to kill the long-term unnecessary lock: SQL> ALTER SYSTEM KILL Session 'SID, Serial #'; View Wait (Wait):
SQL> SELECT V $ Waitstat.class, V $ Waitstat.count Count, Sum (V $ sysstat.value) SUM_VALUE FROM V $ WAITSTAT, V $ SYSSTAT WHERE V $ SYSSTAT.NAME IN ('DB Block Gets',' Conistent Gets ') Group by V $ WaitStat.class, V $ WaitStat.count; View SGA situation:
SQL> SELECT NAME, BYTES from Sys.v_ $ SGASTAT ORDER BY Name ASC; View catched object:
SQL> SELECT OWNER, NAME, DB_LINK, NAMESPACE, TYPE, Shable_Mem, Loads, Executions, Locks, Pins, Kept from V $ db_object_cache; view v $ sqlarea:
SQL> SELECT SQL_TEXT, SHARABLE_MEM, PERSISTENT_MEM, RUNTIME_MEM, SORTS, VERSION_COUNT, LOADED_VERSIONS, OPEN_VERSIONS, USERS_OPENING, EXECUTIONS, USERS_EXECUTING, LOADS, FIRST_LOAD_TIME, INVALIDATIONS, PARSE_CALLS,
Disk_reads, buffer_gets, rows_processed from v $ sqlarea; view Object Category Number:
Select Decode (O.Type #, 1, 'Index', 2, 'Table', 3, 'Cluster', 4, 'View', 5, 'Synynym', 6, 'Sequence', 'Other') Object_Type, Count (*) Quantity from sys.obj $ o Where o.type #> 1 Group by decode (O.Type #, 1, 'INDEX', 2, 'TABLE', 3, 'Cluster', 4, 'View' , 5, 'Synym', 6, 'SEQUENCE', 'OTHER') Union Select 'Column', Count (*) from Sys.col $ Union Select 'DB Link', Count (*) from all_Objects; related Connection Information: 1) View which users are connected
Select S.OSUSER OS_USER_NAME, DECODE (Sign (48 - Command), 1, TO_CHAR (Command), 'Action Code #' || to_char (command)) Action, P.Program Oracle_Process, Status Session_Status, S.Terminal Terminal, S .program program, s.username user_name, s.fixed_table_sequence activity_meter, '' query, 0 memory, 0 max_memory, 0 cpu_usage, s.sid, s.serial # serial_num from v $ session s, v $ process p where s.paddr = p.addr and s.type = 'user' order by S.Username, S. OSUSER
2) View the resource occupation of the corresponding connection according to V.SID
Select n.name, v.value, n.class, n.statistic # from v $ statname n, v $ sessstat v where v.sid = 18 and v.statistic # = n.statistic # Order by n.class, n .statistic #;
3) View according to SID to see the corresponding connection is running SQL
SELECT / * PUSH_SUBQ * / Command_Type, SQL_Text, Sharable_Mem, Persistent_Mem, Runtime_Mem, Sorts, Version_Count,
loaded_versions, open_versions, users_opening, executions, users_executing, loads, first_load_time, invalidations, parse_calls, disk_reads, buffer_gets, rows_processed, sysdate start_time, sysdate finish_time, '>' || address sql_address, 'N' status from v $ sqlarea where address = ( SELECT SQL_ADDRESS from V $ session where sid = 8);
According pid View sql statement: SQL> select sql_text from v $ sqlwhere address in (select sql_address from v $ sessionwhere sid in (select sid from v $ session where paddr in (select addr from v $ process where spid = & pid))); Query table space usage:
SQL> SELECT A.TABLESPACE_NAME "Table Space Name",
100-Round ((NVL (B.Bytes_Free, 0) /A.BYTES_ALLOC) * 100, 2) "Occupation (%)",
Round (A.BYTES_ALLOC / 1024/1024, 2) "Capacity (M)",
Round (NVL (B.BYTES_FREE, 0) / 1024/1024, 2) "Idle (M)",
Round ((A.BYTES_ALLOC-NVL (B.BYTES_FREE, 0)) / 1024/1024, 2) "Use (M)",
Largest "Maximum Expansion Section (M)", To_Char (Sysdate, 'YYY-MM-DD HH24: MI: SS') "Sample Time" from (SUM (F.Bytes) Bytes_alloc,
Sum (Decode (F.autoextensible, 'Yes', F.maxbytes, 'NO', F.BYTES) MAXBYTES
From dba_data_files f group by tablespace_name) a,
(Select F.Tablespace_name, SUM (F.BYTES) BYTES_FREE
From dba_free_space f Group by tablespace_name) b,
(Select Round (Max (ff.length) * 16/1024, 2) Largest, Ts.Name TableSpace_name
From sys.FET $ ff, sys.file $ tf, sys.ts $ TS
Where ts.ts # = ff.ts # and ff.file # = tf.relfile # and ts.ts # = tf.ts #
Group by ts.name, tf.blocks) c where a.tablespace_name = B.TABLESPACE_NAME AND ADABLESPACE_NAME = C.TABLESPACE_NAME Download Adobe Reader
SQL> SELECT UPPER (F.TABLESPACE_NAME) "Table Space Name", D. Tot_Grootte_MB "Table Space Size (M)", D. Tot_Grootte_MB - F. Total_Bytes "has been used with space (M)", to_CHAR (Round) TOT_GROOTTE_MB - F. TOTAL_BYTES) / D. Tot_Grootte_MB * 100, 2), '990.99') "User, F. Total_bytes" Idle Space (M) ", f.max_bytes" Maximum Block (M) "from (SELECT TABLESPACE_NAME Round (SUM (BYTES) / (1024 * 1024), 2) Total_Bytes, Round (Max (Bytes) / (1024 * 1024), 2) Max_Bytes from sys.dba_free_space group by tablespace_name) f, (Select Dd.TablesPace_Name, Round (SUM (BYTES) / (1024 * 1024), 2) TOT_GROOTTE_MB from from sys.dba_data_files dd group by dd.tablespace_name) D where d.tablespace_name = f.Tablespace_name Order by 4 DESC; the degree of fragmentation of the query table space:
SQL> SELECT TABLESPACE_NAME, Count (TableSpace_name) from dba_free_space group by tablespace_name haVing count (TABLESPACE_NAME)> 10;
SQL> ALTER TABLESPACE NAME COALESCE;
SQL> ALTER TABLE TABLE_NAME DEAALLOCATE UNUSED
SQL> Create or Replace View TS_BLOCKS_V AS
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
SQL> SELECT * from TS_BLOCKS_V;
SQL> SELECT TABLESPACE_NAME, SUM (BYTES), Max (Bytes), Count (Block_ID) from DBA_FREE_SPACE GROUP BY TABLESPACE_NAME;
SQL> SELECT 'ALTER TABLESPACE' || TableSpace_name || 'coalesce;' from DBA_FREE_SPACE_COALESCED WHERE Percent_EXTENTS_COALESCED <100OR Percent_blocks_coalesced <100;
Since the free space debris is composed of several parts, such as the range, the maximum range size, etc., we can use FSFI - Free Space Fragmentation Index (free space debris index) value: fsfi = 100 * SQRT (max (extent) / SUM (Extents) * 1 / SQRT (SQRT (count (extents)))
rem fsfi value compute rem fsfi.sql column fsfi format 999,99 select tablespace_name, sqrt (max (blocks) / sum (blocks)) * (100 / sqrt (sqrt (count (blocks)))) fsfi from dba_free_space group by tablespace_name ORDER BY 1; Spool Fsfi.rep; / Spool OFF;
It can be seen that the maximum possible value of FSFI is 100 (an ideal single-text table space). As the range increases, the FSFI value slowly decreases, and the FSFI value will fall quickly as the maximum size is reduced.
For example, run the script fsfi.sql in a database, get the following FSFI value: TableSpace_name FSFI ------------------------------------------------------------------------------------------ ----- RBS 74.06 System 100.00 Temp 22.82 Tools 75.79 User_Tools 100.00 YDCX_DATA 47.34 YDCX_IDX 57.19 YDJF_DATA 33.80 YDJF_IDX 75.55 ---- Counting the FSFI value of the database, you can use it as a comparable parameter. In a table space with enough effective free space, and the FSFI value exceeds 30, there is little problem of effective free space. When a space will be close to the parameter, you need to make a fragmentation.
What database instances are running:
SQL> SELECT INST_NAME FROM V $ ACTIVE_INSTANCES;
Take the DBA role to see the current database lock:
SQL> SELECT Object_ID, session_id, locked_mode from v $ locked_object;
SQL> SELECT T2.USERNAME, T2.SID, T2.SERIAL #, T2.LOGON_TIME FROM V $ Locked_Object T1, V $ Session T2
WHERE T1.SESSION_ID = T2.SID ORDER BY T2.LOGON_TIME;
View the table is a partition table:
example:
SQL> SELECT TABLE_NAME, Partitioned from User_Tables Where Table_name = 'LocalUSage'
Table_name par
---------------------------------------
Localusage Yes
View the partition name of the partition table and the corresponding table space name:
SQL> SELECT TABLE_NAME, Partition_name, TableSpace_name from user_tab_partitions where table_name like '% usage%';
Check whether the index is a partition index:
SQL> SELECT INDEX_NAME, TABLE_NAME, STATUS, PARTITIONED FROM USER_INDEXES WHERE TABLE_NAME LIKE '% USAGE'; if returned PATITIONED is YES, then please execute the following statement to query the partition index types: SELECT index_name, table_name, locality FROM user_part_indexes;
DUAL is an actually existing table in Oracle, and any user can read, often in the SELEC that is not available.
View the system time:
SQL> SELECT TO_CHAR (SYSDATE, 'YY-MM-DD HH24: MI: SS') Shijian from Dual
View the number of extents in the index section:
SQL> Select segment_name, count (*) from DBA_EXTENTS
WHERE segment_type = 'index' and owner = 'scott' group by segment_name;
View the user index in the system table (used to check the existence of other users in the System tablespace):
SQL> SELECT Count (*) from dba_indexes where tablespace_name = 'system' and Owner Not in ('sys', 'system');
View the extension of the index in the WacOS table space:
SQL> Select Substr (segment_name, 1, 20) "Segment Name", Bytes, Count (Bytes)
From dba_extents where segment_name in (SELECT INDEX_NAME FROM DBA_INDEXES
WHERE TABLESPACE_NAME = 'wacos') Group by segment_name, bytes Order by segment_name;
View the read and write performance of the tablespace data file:
SQL> Select Name, Phyrds, Phywrts, Avgiotim, Miniotim, Maxiowtm, Maxiortm from V $ Filestat, V $ DataFile WHERE V $ FileStat.File # = V $ datafile.file #;
SQL> Select fs.name name, f.phyrds, f.phyblkrd, f.phywrts, f.phyblkwrt, f.readtim, f.writetim
From v $ filestat f, v $ datafile fs where f.file # = fs.file # Order by fs.name;
(Note: If Phyblkrd is close to PHYRDS, there is a table with full table scanning in this table space, these tables need to adjust indexes or optimize SQL statements)
Conversion table space is locally mode management:
SQL> EXEC SYS.DBMS_SPACE_ADMIN.TABLESPACE_MIGRATE_TO_LOCAL ('TBS_TEST');
Check out which user is using the tempo:
SQL> Select Username, SID, Serial #, SQL_Address, Machine, Program, TableSpace, SegType, Contents from V $ Session Se, V $ sort_usage suwhere se.saddr = su.session_addr;
Viewing the Running Session in IO:
SQL> Se.Serial #, pr.spid, se.user, se.status, se.terminal, se.program, se.module, se.sql_address, st.event, st.p1xt, si. Physical_reads, si.block_changes from V $ Session Se, V $ Session_Wait St, V $ sess_io si, v $ process pra where st.sid = se.sid and st.SID = si.sid and se.paddr = pr.Addr and SE.SID> 6 and st.wait_time = 0 and st.event not Like '% SQL%' Order by Physical_Reads DESC; lookup SQL of the first ten performance poor:
SQL> SELECT * FROM (SELECT PARSING_USER_ID EXECUTIONS, SORTS, Command_Type, Disk_reads, SQL_Text from V $ SQLAREA Order by Disk_Reads Desc) Where rownum <10;
Delete the statement of all tables under the user: SQL> SELECT 'DROP TABLE' || Table_Name || 'Cascade Constraints;' from User_Tables;
View LOCK and kill the session:
SQL> Set Linesize 132 PageSize 66
Break on Kill on UserName on Terminal
Column Kill Heading 'Kill String' Format A13
Column res be here resource type 'Format 999
Column id1 Format 9999990
Column ID2 Format 9999990
Column LMODE BEADING 'LOCK HELD' FORMAT A20
Column Request Heading 'Lock Requested' Format A20
Column serial # Format 99999
Column UserName Format A10 Heading "Username"
Column Terminal Heading Term Format A6
Column Tab Format A35 Heading "Table Name"
Column Owner Format A9
Column Address Format A18
SQL> SELECT NVL (S.UserName, 'Internal') UserName,
NVL (S.Terminal, 'None') Terminal,
L.SID || ',' || s.serial # kill,
U1.NAME || ',' || Substr (T1.NAME, 1, 20) TAB,
Decode (L.Lmode, 1, 'NO LOCK',
2, 'Row Share',
3, 'ROW EXCLUSIVE',
4, 'Share',
5, 'Share Row Exclusive',
6, 'Exclusive', NULL) LMODE,
Decode (L.Request, 1, 'NO LOCK',
2, 'Row Share',
3, 'Row Exclusive', 4, 'Share',
5, 'Share Row Exclusive',
6, 'Exclusive', NULL) Request
From V $ LOCK L,
V $ session s,
Sys.user $ u1,
Sys.obj $ T1
WHERE L.SID = S.SID
And t1.obj # = decode (L.ID2, 0, L.ID1, L.ID2)
And u1.user # = T1.OWNER #
And S.Type! = 'Background'
Order by 1, 2, 5;
--alter system kill session ',';
Column UserName Format A15
Column Sid Format 9990 Heading SID
Column Type Format A4
Column Lmode Format 990 Heading 'Held'
Column Request Format 990 Heading 'Req'
Column id1 Format 9999990
Column ID2 Format 9999990
Break ON ID1 SKIP 1 DUP
Spool tfslckwt.lst
SQL> SELECT sn.username,
M.SID,
M.TYPE,
Decode (M.Lmode, 0, 'None',
1, 'Null',
2, 'Row Share',
3, 'ROW EXCL.',
4, 'Share',
5, 'S / ROW EXCL.',
6, 'ExClusive',
LMODE, LTRIM (To_Char (LMODE, '990'))) LMODE,
Decode (M.Request, 0, 'None',
1, 'Null',
2, 'Row Share',
3, 'ROW EXCL.',
4, 'Share',
5, 'S / ROW EXCL.',
6, 'ExClusive',
Request, Ltrim (To_Char (M.Request, '990')))) Request,
M.ID1,
M.ID2
From v $ session SN,
V $ LOCK M
WHERE (sn.sid = m.sid and m.request! = 0)
OR (sn.SID = m.sid and
m.Request = 0 and LMODE! = 4 and
(ID1, ID2) in (Select S.ID1,
S.ID2
From v $ locoo
WHERE REQUEST! = 0 and s.id1 = m.id1 and sid2 = m.id2)
)
Order by ID1, ID2, m.Request;
Spool off
Clear Breaks
View all indexes under WacOS tablespace:
SQL> SELECT 'Analyze Index' || Segment_name || 'Validate Structure;' from DBA_SEGMENTS WHERE TABLESPACE_NAME = 'Wacos'and Segment_Type =' INDEX ';
How to identify IO competition and load balancing:
SQL> COL file name Format A35SQL> SELECT
DF.NAME file name,
fs.Phyrds Reading,
Fs.phywrts write time,
(fs.readtim / decode (fs.phyrds, 0, -1, fs.phyrds)) read time,
(fs.writetim / decode (fs.phywrts, 0, -1, fs.phywrts) write time
From
V $ datafile df,
V $ filestat fs
WHERE DF.FILE # = fs.file #
Order by DF.NAME
/
File name reading time a number of read times write time
------------------------------------------------------------------------------------------ ---- ---------- ---------- ----------
C: /oracle/oradata/oradb/dr01.dbf 885 883 0 0
C: /oracle/oradata/oradb/indx01.dbf 885 883 0 0
C: /oracle/oradata/oradb/oem_repository.ora 885 883 0 0
C: /oracle/oradata/oradb/rbs01.dbf 925 22306 0 0
C: /oracle/oradata/oradb/system01.dbf 50804 155025 0 0
C: /oracle/oradata/oradb/temp01.dbf 887 894 0 0
C: /oracle/oradata/oradb/tools01.dbf 886 892 0 0
C: /oracle/oradata/oradb/users01.dbf 885 883 0 0
8 lines have been selected.
Where: ORADB is the database name, because the databases in this example have been installed by default, no optimization, adjustment,
So, I have been working on the SYSTEM table space, causing the data files in the SYSTEM table space SYSTEM01.DBF to be read and written.
This also illustrates that try not to do an operation-independent operation with the system table space, and should establish a separate table space to each user.
Which sessions are using the roll bands:
SQL> COL returns to Format A10
SQL> Col Sid Format 9990
SQL> COL user name Format A10
SQL> COL operation procedure Format A80
SQL> Col Status Format A6 Trunc
SQL> SELECT R.NAME Return Square,
S.SID,
S.Serial #,
S.Username username,
T.STATUS,
T.CR_GET,
T.PHY_IO,
T.USED_UBLK,
T.Noundo,
Substr (S.Program, 1, 78) Operator
From sys.v_ $ session s, sys.v_ $ transaction t, sys.v_ $ rollname rwhere t.addr = s.taddr and t.xidusn = R.usn
Order by t.cr_get, t.phy_io;
45. Checking Who Lock What Object: Set Line 200 Col "O / S-User" Format A10 Col "ORA-User" Format A10 Col "Obj Locked" Format A30 SELECT / * Rule*/s.machine, s. OSUser "O / S-User", S.Username "Ora-User", S.SID "session-id", s.serial # "serial", s.Process "Process-ID", S.Status "status" , L.Name "obj locked", L.Mode_held "Lock Mode" from v $ session s, dba_dml_locks l, v $ process p where l.session_id = s.sid and p.addr = s.paddr /
Causes the LOCK information, such as LOCK type, etc .: SQL> Col Event Format A30 SQL> Set line 160 SQL> Col Machine Format A10 SQL> Col UserName Format A15 SQL> SELECT B.SID, B. Serial #, B.USERNAME , Machine, Event, WAIT_TIME, CHR (Bitand (P1, -16777216) / 16777215) || CHR (Bitand (P1, 16711680) / 65535) "Enqueue Type" from v $ session_wait a, v $ session b where Event not Like 'Sql * n%' and Event not like 'RDBMS%' and a.sid = B.SID and B.SID> 8 and Event = 'enqueue' Order by UserName;
List of the locked Oracle Objects
SQL> SET LINE 120
SQL> Column Object_name Format A32
SQL> Column OS_USER_NAME FORMAT A12
SQL> Column ORAUSER FORMAT A12
Column SQL_Text Format A32
Column serial # format 999999
Column Sid Format 99999
SQL> SELECT OS_USER_NAME, ORACLE_USERNAME AS ORAUSER, S.SID, O.Object_name,
O.Object_type, s.serial #, a.sql_text
From V $ locked_Object L, DBA_Objects O, V $ Session S, V $ SQLAREA A
Where l.object_id = O.Object_ID
And S.SQL_Address = a.address
And L.Session_ID = S.SID;
SELECT 'ALTER SYSTEM KILL Session' '' || To_Char (S.SID) || ',' || to_CHAR (S.Serial #) || '' ';' AS "Statement To Kill"
From v $ locked_Object L, DBA_Objects O, V $ Session S
Where l.object_id = O.Object_ID
And L.Session_ID = S.SID;
Oracle database performance monitoring SQL
Waiting for SQL> SELECT EVENT, SUM (Decode (Wait_Time, 0, 0, 1)) "prev", SUM (Decode (Wait_Time, 0, 1, 0)) "CURR", count (*) "TOT" From v $ session_wait group by Event ORDER BY 4; Squash Squar SQL> Select Name, Waits, Gets, Waits / Gets "Ratio" from v $ ROLLSTAT A, V $ ROLLNAME B Where A.usn = B. USN; I / O ratio SQL> 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 ORDER BY DF.TABLESPACE_NAME; Monitor file system I / O ratio SQL> 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 bwhere a.file # = B.File #; find all users index SQL> 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; Monitor SGA's hit rate SQL> 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 Monitor the hit rate SQL> Select Parameter, Gets, getMisses, getMisses / (Gets) / (SUM (GetMisses) / (SUM (Gets) / (SUM (Gets) / (SUM (Gets) / (SUM (Gets) GetMisses))))) * 100 "Hit Ratio" from v $ ROWCACHE WHERE GETS GETMISSES <> 0 Group by parameter, gets, getMisses; monitoring the hit rate of CCA in SGA,
Should be less than 1% SQL> SELECT SUM (Pins) "Total Pins", SUM (Reloads) "Total Reloads", SUM (Reloads) / SUM (Pins) * 100 Libcache from V $ librarycache; SQL> SELECT SUM (Pinhits-Reloads ) / SUM (Pins) "Hit Radio", SUM (Reloads) / SUM (Pins) "Reload Percent" from V $ librarycache; Displaying all database objects Category and SQL> 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 Monitor the hit rate of the SGA medium-red log buffer, should be less than 1% SQL> SELECT NAME, GETS, MISSES, IMMEDIDIATE_GETS, IMMEDIATE_MISS, DECODE (Gets, 0, 0, Misses / Gets * 100) Ratio1, Decode (IMMEDIATE_GETS IMMEDIATE_MISS, 0, 0, IMMEDIATE_MISSES / (IMMEDIATE_GETS IMMEDIATE_MISS * 100) Ratio2 from v $ latch where name in ('redo allocation', 'redo copy'); monitoring memory and hard disk sorting ratio, it is best to make it less than. 10, add sort_area_size sql> select name, value from v $ sysstat where name in ('sorts ",' sorts (disk)); monitor the current database who is running what SQL statement S QL> SELECT OSUSER, Username, SQL_Text from V $ Session A, V $ SQLText B Where A.SQL_Address = B.Address Order By Address, Piece; Monitor Dictionary Buffer SQL> SELECT (SUM (Pins - Reloads)) / SUM Pins "lib cache" from v $ librarycache; sql> select (sum (gets - getmisses - usage - fixed) / sum (gets) "Row Cache" from v $ rowcache; SQL> SELECT SUM (PINS) "Executions" SUM (RELOADS) "Cache Misses While Executing" from V $ librarycache; (the latter except for the former, this ratio is less than 1%, close to 0% is good) SQL> Select SUM (Gets) "Dictionary Gets", SUM (GetMisses ) "Dictionary Cache Get Misses" from V $ ROWCACHE; Find Oracle Character Set SQL>
Select * from sys.props $ where name = 'nls_characterset'; Monitor MTS SQL> SELECT Busy / (Busy IDle) "Shared Servers Busy" from v $ dispatcher; (This value is greater than 0.5, parameters need to increase) SQL> select sum (wait) / sum (totalq) "dispatcher waits" from v $ queue where type = 'dispatcher'; SQL> select count (*) from v $ dispatcher; SQL> select servers_highwater from v $ mts; (servers_highwater close mts_max_servers when parameters need to increase) the degree of fragmentation SQL> select tablespace_name, count (tablespace_name) from dba_free_space group by tablespace_name having count (tablespace_name)> 10; SQL> alter tablespace name coalesce; SQL> alter table name deallocate unused; SQL> create or replace view ts_blocks_v as 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; SQL> select tablespace_name, sum (bytes), Max (Bytes), Count (Block_ID) from DBA_Free_Space Group by TableSpace_name; View Fragmentation Table SQL> SELECT Segment_name Table_Name, Count (*) EXT Ents 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. tables, indexes of the inspection stored SQL> 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; SQL> select segment_name, count (*) from dba_extents where segment_type = 'INDEX' and owner = '& owner' group by segment_name; 18, find use CPU plurality User Session SQL> SELECT A.SID, SPID, STATUS, SUBSTR (A.Program, 1, 40) PROG, A.TERMINAL, OSUSER, VALUE / 60/100 VALUE FROM V $ Session A, V $ Process B, V $ seestat c where c.statistic # = 12 and c.SID = a.sid and a.paddr = b.addr Order by value desc; (12 is CPU Used by this session)
Table space statistics
A, script description:
This is my most common script that uses it to display the status of all tablespaces in the database, such as the size of the table space, the use of space, the percentage of use, how much the number of free space and the current table space is now.
B, the script original:
Select Upper (f.tablespace_name "Table Space Name",
D. Tot_Grootte_MB "Table Space Size (M)",
D. TOT_GROOTTE_MB - F. TOTAL_BYTES "The space (M) has been used,"
TO_CHAR ((D. Tot_Grootte_MB - F. TOTAL_BYTES) / D. TOT_GROOTTE_MB * 100, 2), '990.99') "Use Comparison",
F. Total_Bytes "Idle Space (M)",
F.max_bytes "Maximum Block (M)"
From
(Select TableSpace_name,
Round (SUM (Bytes) / (1024 * 1024), 2) Total_bytes,
Round (Max (Bytes) / (1024 * 1024), 2) MAX_BYTES
From sys.dba_free_space
Group by TableSpace_name) f,
(Select Dd.Tablespace_name, Round (SUM (DD.BYTES) / (1024 * 1024), 2) TOT_GROOTTE_MB
From sys.dba_data_files dd
Group by dd.tablespace_name) D
Where d.tablespace_name = f.tablespace_name
ORDER BY 4 DESC;
View unable to extensible segment
A, script description:
Oracle is not extended for a paragraph or index, which is not the remaining space in the table space, but is taken in the largest block in these remaining spaces. Is it comparable to the "next" value of the index, so Sometimes a table space remains in the free space, oracle or the index cannot be expanded when you use it, that is, because this is too much. This script is some of the information that cannot be expanded. B, the script original:
Select segment_name,
Segment_type,
Owner,
A.Tablespace_name "TableSpaceename",
Initial_extent / 1024 "INITAL_EXTENT (K)",
Next_extent / 1024 "next_extent (k)",
PCT_INCREASE,
B.BYTES / 1024 "TableSpace Max Free Space (K)",
B. Sum_Bytes / 1024 "TableSpace Total Free Space (K)"
From DBA_SEGMENTS A,
(Select TableSpace_name, max (bytes) Bytes, SUM (Bytes) SUM_BYTES from DBA_FREE_SPACE GROUP BY TABLESPACE_NAME) B
Where a.tablespace_name = b.tablespace_name
And next_extent> B.BYTES
Order BY 4, 3, 1;
Viewing the space used by the segment (table segment, index)
A, script description:
Sometimes you might want to know how much a table or an index take up, this script is to meet your requirements, replace the content in <>.
B, the script original:
SELECT OWNER,
Segment_name,
Sum (Bytes) / 1024/1024
From DBA_SEGMENTS
WHERE OWNER =
And segment_name =
GROUP BY OWNER, Segment_Name
ORDER BY 3 DESC;
View the table lock in the database
A, script description:
The style of this apartment is much, like all kinds, but I think this is the most practical, don't believe you, don't say more, the lock is the content that every DBA must be involved, when you know some Which SESSION is locked by a table, you used this script.
B, the script original:
SELECT A.OWNER,
A.Object_name,
B.xIDUSN,
B.XIDSLOT,
B.XIDSQN,
B.Session_ID,
B. Oracle_Username,
B.OS_USER_NAME,
B.Process,
B.locked_mode,
C. Machine,
C.STATUS,
C. Server,
C.SID,
C. Serial #,
C.Program
From all_Objects a,
V $ locked_Object B,
Sys.gv_ $ session c
Where (a.Object_id = B.Object_ID)
AND (B.Process = C.Process)
- and
ORDER BY 1, 2;
Process stored procedure is locked
A, script description:
In the actual process, you may have to recompile a store procedure, always in the waiting state, and finally will not lock the object. At this time, you can use this script to find the SID of the lock process, you need to pay attention to check V $ access this The view is very slow, it needs some patience. B, the script original:
Select * from v $ access where owner =