oracle sql性能
1、查询所对象相关的表?
V$LOCK, V$LOCKED_OBJECT, V$SESSION, V$SQLAREA, V$PROCESS ;
查询锁的表的方法:
SELECT
S.SID SESSION_ID, S.USERNAME, DECODE(LMODE, 0, 'None', 1, 'Null', 2,
'Row-S (SS)', 3, 'Row-X (SX)', 4, 'Share', 5, 'S/Row-X (SSX)', 6,
'Exclusive', TO_CHAR(LMODE)) MODE_HELD, DECODE(REQUEST, 0, 'None', 1,
'Null', 2, 'Row-S (SS)', 3, 'Row-X (SX)', 4, 'Share', 5, 'S/Row-X
(SSX)', 6, 'Exclusive', TO_CHAR(REQUEST)) MODE_REQUESTED,
O.OWNER||'.'||O.OBJECT_NAME||' ('||O.OBJECT_TYPE||')', S.TYPE LOCK_TYPE,
L.ID1 LOCK_ID1, L.ID2 LOCK_ID2 FROM V$LOCK L, SYS.DBA_OBJECTS O,
V$SESSION S WHERE L.SID = S.SID AND L.ID1 = O.OBJECT_ID ;
2. 如何解锁?
ALTER SYSTEM KILL SESSION ‘SID,SERIR#’;
3、获取当前用户的错误信息
SELECT * FROM USER_ERRORS;
4、查询当前数据库的字符集
select * from nls_database_parameters;
PARAMETER VALUE
------------------------------ --------------------------------------------------------------------------------
NLS_LANGUAGE AMERICAN
NLS_TERRITORY AMERICA
NLS_CURRENCY $
NLS_ISO_CURRENCY AMERICA
NLS_NUMERIC_CHARACTERS .,
NLS_CHARACTERSET ZHS16GBK
NLS_CALENDAR GREGORIAN
NLS_DATE_FORMAT DD-MON-RR
NLS_DATE_LANGUAGE AMERICAN
NLS_SORT BINARY
NLS_TIME_FORMAT HH.MI.SSXFF AM
NLS_TIMESTAMP_FORMAT DD-MON-RR HH.MI.SSXFF AM
NLS_TIME_TZ_FORMAT HH.MI.SSXFF AM TZR
NLS_TIMESTAMP_TZ_FORMAT DD-MON-RR HH.MI.SSXFF AM TZR
NLS_DUAL_CURRENCY $
NLS_COMP BINARY
NLS_LENGTH_SEMANTICS BYTE
NLS_NCHAR_CONV_EXCP FALSE
NLS_NCHAR_CHARACTERSET AL16UTF16
NLS_RDBMS_VERSION 11.2.0.1.0
20 rows selected
5、获取当前时间日期
select max(ktuxescnw * power(2, 32) + ktuxescnb) from x$ktuxe;
6、怎么可以快速做一个和原表一样的备份表?
create table new_table as (select * from old_table);
7、如何查看数据库的状态?
unix下
ps -ef | grep ora
windows下
看服务是否起来
是否可以连上数据库
8、内存参数设置
shmmax
含义:这个设置并不决定究竟Oracle数据库或者操作系统使用多少物理内存,只决定了最多可以使用的内存数目。这个设置也不影响操作系统的内核资源。
设置方法:0.5*物理内存
例子:Set shmsys:shminfo_shmmax=10485760
shmmin
含义:共享内存的最小大小。
设置方法:一般都设置成为1。
例子:Set shmsys:shminfo_shmmin=1:
shmmni
含义:系统中共享内存段的最大个数。
例子:Set shmsys:shminfo_shmmni=100
shmseg
含义:每个用户进程可以使用的最多的共享内存段的数目。
例子:Set shmsys:shminfo_shmseg=20:
semmni
含义:系统中semaphore identifierer的最大个数。
设置方法:把这个变量的值设置为这个系统上的所有Oracle的实例的init.ora中的最大的那个processes的那个值加10。
例子:Set semsys:seminfo_semmni=100
semmns
含义:系统中emaphores的最大个数。
设置方法:这个值可以通过以下方式计算得到:各个Oracle实例的initSID.ora里边的processes的值的总和(除去最大的Processes参数)+最大的那个Processes×2+10×Oracle实例的个数。
例子:Set semsys:seminfo_semmns=200
semmsl:
含义:一个set中semaphore的最大个数。
设置方法:设置成为10+所有Oracle实例的InitSID.ora中最大的Processes的值。
例子:Set semsys:seminfo_semmsl=-200
9、如何显示当前连接用户?
SHOW USER
10、如何测试SQL语句执行所用的时间,用来排查
SQL>set timing on ;
SQL>select * from tablename;
11、如何知道机器上的Oracle支持多少并发用户数?
SQL>conn internal ;
SQL>show parameter processes ;
12、如何查询做比较大的排序的进程?
SELECT b.tablespace, b.segfile#, b.segblk#, b.blocks, a.sid, a.serial#,
a.username, a.osuser, a.status
FROM v$session a,v$sort_usage b
WHERE a.saddr = b.session_addr
ORDER BY b.tablespace, b.segfile#, b.segblk#, b.blocks ;
显示每个实例中的排序段,
Column | Datatype | Description |
---|---|---|
TABLESPACE_NAME |
VARCHAR2(31) |
表空间名 |
SEGMENT_FILE |
NUMBER |
文件号的扩展 |
SEGMENT_BLOCK |
NUMBER |
Block number of the first extent |
EXTENT_SIZE |
NUMBER |
Extent size |
CURRENT_USERS |
NUMBER |
Number of active users of the segment |
TOTAL_EXTENTS |
NUMBER |
Total number of extents in the segment |
TOTAL_BLOCKS |
NUMBER |
Total number of blocks in the segment |
USED_EXTENTS |
NUMBER |
当前使用的扩展 |
USED_BLOCKS |
NUMBER |
当前使用的块 |
FREE_EXTENTS |
NUMBER |
空闲的扩展 |
FREE_BLOCKS |
NUMBER |
空闲的块 |
ADDED_EXTENTS |
NUMBER |
Number of extent allocations |
EXTENT_HITS |
NUMBER |
Number of times an unused extent was found in the pool |
FREED_EXTENTS |
NUMBER |
Number of deallocated extents |
FREE_REQUESTS |
NUMBER |
Number of requests to deallocate |
MAX_SIZE |
NUMBER |
Maximum number of extents ever used |
MAX_BLOCKS |
NUMBER |
Maximum number of blocks ever used |
MAX_USED_SIZE |
NUMBER |
Maximum number of extents used by all sorts |
MAX_USED_BLOCKS |
NUMBER |
Maximum number of blocks used by all sorts |
MAX_SORT_SIZE |
NUMBER |
Maximum number of extents used by an individual sort |
MAX_SORT_BLOCKS |
NUMBER |
Maximum number of blocks used by an individual sort |
RELATIVE_FNO |
NUMBER |
Relative file number of the sort segment header |
13、如何查询做比较大的排序的进程的SQL语句?
select /*+ ORDERED */ sql_text from v$sqltext a
where a.hash_value = (
select sql_hash_value from v$session b
where b.sid = &sid and b.serial# = &serial)
order by piece asc ;
14、如何监控事例的等待?
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;
如何监控 SGA 的命中率?
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;
151. 如何监控 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;
152. 如何监控 SGA 中共享缓存区的命中率,应该小于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;
监控内存和硬盘的排序比率,最好使它小于 .10,增加 sort_area_size
SELECT name, value FROM v$sysstat WHERE name IN ('sorts (memory)', 'sorts (disk)');
http://www.cnblogs.com/adandelion/articles/272971.html