Some basic queries of oracle

select status, T.* from user_indexes T
where table_name='T_ADMIN_DEALER' -- query whether the table has an index 

select username,default_tablespace from dba_users; --View the relationship between users and the default tablespace
select view_name from user_views --View the view name

select * from user_source; -- query all functions and stored procedures

select * from all_users; -- query all users

select * from v$Session; -- view current user connections

SELECT * FROM USER_ROLE_PRIVS; -- view user roles

select * from session_privs; -- view current user privileges

SELECT * FROM DBA_ROLE_PRIVS; -- view roles owned by all users

select * from dba_roles; -- view all roles

SELECT NAME FROM V$DATABASE; -- view database name

select * from v$recovery_file_dest; - - The location where archived logs are stored

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;  --查看表空间的名称和大小

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 physical file in the tablespace

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; --查看回滚段名称及大小 (select segment_name,status from dba_rollback_segs;)

SELECT NAME FROM v$controlfile; -- view control file 

SELECT MEMBER FROM v$logfile; -- view log file

SELECT SUM(bytes) / (1024 * 1024) AS free_space, tablespace_name
FROM dba_free_space
GROUP BY tablespace_name;
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; --查看表空间使用情况

SELECT owner, object_type, status, COUNT(*) count#
FROM all_objects
GROUP BY owner, object_type, status; --View database objects

SELECT version
FROM product_component_version
WHERE substr(product, 1, 6) = 'Oracle'; --View database version

SELECT created, log_mode, log_mode FROM v$database;
--1G=1024MB
--1M=1024KB
--1K=
1024Bytes --1M=11048576Bytes
--1G=1024*11048576Bytes=11313741824Bytes
SELECT a.tablespace_name "tablespace name",
total "table space size",
free "table space remaining size",
(total - free) "table space usage size",
total / (1024 * 1024 * 1024) "table space size (G)",
free / (1024 * 1024 * 1024) "Table space remaining size (G)",
(total - free) / (1024 * 1024 * 1024) "Table space usage size (G)",
round((total - free) / total, 4) * 100 "Usage %"
FROM (SELECT tablespace_name, SUM(bytes) free
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; -- View the creation date and filing method of the database 

 

DBA views that manage users, roles, and privileges :
DBA_USERS provides information about users
DBA_ROLES displays all roles in the database
DBA_COL_PRIVS displays column-level object authorizations
DBA_ROLE_PRIVS displays users and their roles
DBA_SYS_PRIVS displays users granted system privileges
DBA_TAB_PRIVS displays users and their roles on tables Privileges
ROLE_ROLE_PRIVS Displays the roles granted to the role
ROLE_SYS_PRIVS Displays the system privileges granted to the
role ROLE_TAB_PRIVS Displays the table privileges granted to
the
role

 

SELECT NAME FROM V$DATABASE; -- view database name

select instance_name,host_name,startup_time,status,database_status from v$instance; --Check Oracle instance status

select group#,status,type,member from v$logfile ; --Check Oracle online log status

 

select resource_name,
max_utilization,
initial_allocation,
limit_value
from v$resource_limit; --Check the relevant parameter values ​​in the Oracle initialization file

select sid, event, p1, p2, p3, WAIT_TIME, SECONDS_IN_WAIT
from v$session_wait
where event not like 'SQL%'
and event not like 'rdbms%'; --Check database wait events

SELECT SQL_TEXT
FROM (SELECT * FROM V $SQLAREA ORDER BY DISK_READS)
WHERE ROWNUM <= 5; --Get the SQL statement with the highest Disk Read

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;--最差的10条sql语句

SELECT *
FROM (SELECT *
FROM V$SYSTEM_EVENT
WHERE EVENT NOT LIKE 'SQL%'
ORDER BY TOTAL_WAITS DESC)
WHERE ROWNUM <= 5;--等待时间最多的5个系统等待事件的获取


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;--检查运行很久的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)) SQLFROM 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%';--检查消耗CPU最高的进程


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);--检查碎片程度高的表

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;--检查表空间的I/O比例

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#;-- 检查文件系统的I/O比例

select sid,
serial#,
username,
SCHEMANAME,
osuser,
MACHINE,
terminal,
PROGRAM,
owner,
object_name,
object_type,
o.object_id
from dba_objects o, v$locked_object l, v$session s
where o.object_id = l.object_id
and s.sid = l.session_id;--检查死锁及处理

SELECT a.VALUE + b.VALUE logical_reads,
c.VALUE phys_reads,
round(100 * (1 - c.value / (a.value + b.value)), 4) hit_ratio
FROM v$sysstat a, v$sysstat b, v$sysstat c
WHERE a.NAME = 'db block gets'
AND b.NAME = 'consistent gets'
AND c.NAME = 'physical reads'; --Check the buffer hit rate (if the hit rate is lower than 90%, you need to increase the database parameter db_cache_size.)

select sum(pinhits) / sum (pins) * 100 from v$librarycache; --Check the shared pool hit rate (if it is lower than 95%, you need to adjust the application to use bind variables, or adjust the size of the database parameter shared pool.)

select name,value from v $sysstat where name like '%sort%'; --Check the sort area (if the ratio of disk/(memoty+row) is too high, you need to adjust sort_area_size(workarea_size_policy=false) or pga_aggregate_target(workarea_size_policy=true).)

select name ,value from v$sysstat where name in ('redo entries','redo buffer allocation retries'); --Check the log buffer (if redo buffer allocation retries/redo entries exceeds 1%, you need to increase log_buffer.)



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; --Monitor the growth of data volume (found based on daily inspections this week Database objects whose space expands quickly, and take corresponding measures:

--Deleting historical data
Move stipulates that at least 6 months of historical data are retained in the database, so the previous historical data can be backed up and then cleared to release the resource space occupied by it.

---Expand table space

alter tablespace <tablespace_name> add datafile ‘<file>’ size <size> autoextend off;

Note: When the database structure changes, such as adding table space, adding data files or redo log files, these operations will cause changes to the Oracle database control file. The DBA should back up the control file. The backup method is:

Execute the SQL statement:

alter database backup controlfile to '/home/backup/control.bak';
或:

alter database backup controlfile to trace;

In this way, the SQL command to create the control file will be generated in the USER_DUMP_DEST (specified in the initialization parameter file) directory. )


select index_name, table_name, tablespace_name, status
From dba_indexes
Where owner = 'CTAIS2'
And status <> 'VALID'; --Check for invalid indexes (Note: It is normal for the index status on the partition table to be N/A, if it fails The index is to rebuild the index, such as:

alter index INDEX_NAME rebuild tablespace TABLESPACE_NAME; )

SELECT owner, constraint_name, table_name, constraint_type, status
FROM dba_constraints
WHERE status = 'DISABLE'
and constraint_type = 'P'; -- Check for constraints that do not work (enable if they are invalid, such as:

alter Table TABLE_NAME Enable Constraints CONSTRAINT_NAME;)


SELECT owner, trigger_name, table_name, status FROM dba_triggers WHERE status = 'DISABLED';- -Check for invalid triggers (enable if there are invalid triggers, such as:

alter Trigger TRIGGER_NAME Enable; )

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326411255&siteId=291194637