日期:2014-05-16  浏览次数:20765 次

oracle基础杂记
select session_id sid ,owner,name,type,mode_held held,mode_requested request from dba_ddl_locks;
select count(*) from v$process;
select count(*) from v$session;

show parameter session;
show parameter session;
--索引是需要排序的,因此需要临时表空间
--临时表空间
select * from dba_temp_files;
create index need sort store in temp tbs;

--表空间的使用率
select d.tablespace_name,space "sum_space(m)",blocks sum_blocks,used_space "used_space(m)", round(nvl(used_space, 0) / space * 100,

2) "used_rate(%)",nvl(free_space, 0) "free_space(m)"
from (select tablespace_name,round(sum(bytes) / (1024 * 1024), 2) space,sum

(blocks) blocks
from dba_temp_files group by tablespace_name) d,
(select tablespace_name,round(sum(bytes_used) / (1024 * 1024), 2)

used_space, round(sum(bytes_free) / (1024 * 1024), 2) free_space
from v$temp_space_header group by tablespace_name) f
where

d.tablespace_name = f.tablespace_name(+);

select * from v$database;
select * from v$process;
select * from v$session;
select * from v$active_instances;
select * from v$instance;

lsnrctl status
listener service
tnsping service[orcl]


GRANT execute on DBMS_PIPE to "XZXNB";

SQL> select count(*) from v$session  #连接数
SQL> Select count(*) from v$session where status='ACTIVE' #并发连接数
SQL> show parameter processes  #最大连接
SQL> alter system set processes = value scope = spfile;重启数据库  #修改连接

process:这个参数限制了能够连接到SGA的操作系统进程数(或者是 Windows 系统中的线程数),这个总数必须足够大,从而能够适用于后台进程与所有的

专用服务器进程,此外,共享服务器进程与调度进程的数目也被计算在内.此外,共享 服务器进程与调度进程的数目也被计算在内.因此,在专用服务器环境

中,这是一种限制并发连接数的方法.

Sessions:是被应 用于oracle层次而非操作系统层次.在不考虑通过专用服务器或共享服务器进行登录的情况下,这个参数限制了对指定实例的并发登陆

数.

SQL> Select count(*) from v$session where status='ACTIVE' ;

SELECT to_timestamp('20080904100555,055','yyyymmddhh24miss,ff') FROM dual;

--1、建立表空间
CREATE SMALLFILE TABLESPACE "DATA" DATAFILE 'D:\MyWork\data\DATA'
SIZE 100M LOGGING EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO;



alter database datafile 'D:\MyWork\data\DATA' autoextend on;

--2、建立用户
drop user XZXNB cascade;
CREATE USER "XZXNB" PROFILE "DEFAULT" IDENTIFIED BY "xzxnb" DEFAULT TABLESPACE "DATA" TEMPORARY TABLESPACE "TEMP" ACCOUNT UNLOCK;
GRANT CREATE ANY VIEW TO "XZXNB";
GRANT UNLIMITED TABLESPACE TO "XZXNB";
GRANT "CONNECT" TO "XZXNB";
GRANT "DBA" TO "XZXNB";
GRANT "RESOURCE" TO "XZXNB";
commit;



查询Oracle正在执行和执行过的SQL语句 

2009-02-17 10:47:09|  分类: 数据库 |字号 订阅
---正在执行的

select a.username, a.sid,b.SQL_TEXT, b.SQL_FULLTEXT
  from v$session a, v$sqlarea b
where a.sql_address = b.address
---执行过的
select b.SQL_TEXT,b.FIRST_LOAD_TIME,b.SQL_FULLTEXT
  from v$sqlarea b
where b.FIRST_LOAD_TIME between '2009-10-15/09:24:47' and
       '2009-10-15/09:24:47' order by b.FIRST_LOAD_TIME
(此方法好处可以查看某一时间段执行过的sql,并且 SQL_FULLTEXT 包含了完整的 sql 语句)

其他
select OSUSER,PROGRAM,USERNAME,SCHEMANAME,B.Cpu_Time,STATUS,B.SQL_TEXT
from V$SESSION A LEFT JOIN V$SQL B ON A.SQL_ADDRESS=B.ADDRESS AND A.SQL_HASH_VALUE=B.HASH_VALUE order by b.cpu_time desc


select address, sql_text, piece
  from v$session, v$sqltext
where address = sql_address
  -- and machine = < you machine name >
order by address, piece

查找前十条性能差的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 ;

查看占io较大的正在运行的session

SELECT se.sid,se.serial#,pr.SPID,se.username,se.status,