ORACLE表空間的常用語句

2021-06-11 21:12:02 字數 2607 閱讀 9445

檢視資料表空間

select t.tablespace_name,t.bytes,t.blocks,t.autoextensible,t.maxbytes,t.file_name from dba_data_files t;

select * from v$datafile;

select upper(f.tablespace_name) "表空間名",

d.tot_grootte_mb "表空間大小(m)",

d.tot_grootte_mb - f.total_bytes "已使用空間(m)",

to_char(round((d.tot_grootte_mb - f.total_bytes) / d.tot_grootte_mb * 100,2),'990.99') "使用比",

f.total_bytes "空閒空間(m)",

f.max_bytes "最大塊(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;

此錯誤是報oracle的表空間大小不足。首先檢視所有表空間的大小:

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 file_name,blocks,tablespace_name

from dba_data_files

將對應表空間的dpf檔案路徑記下來。比如『/opt/oracle/oradata/test/test.dbf』

最後修改表空間資料檔案:

alter database datafile '/opt/oracle/oradata/test/test.dbf' resize 2000m

查詢新建使用者

select username

from dba_users

where username not in

('text', 'rman_user', 'test', 'scott', 'tsmsys', 'mddata', 'dip',

'dbsnmp', 'sysman', 'mdsys', 'ordsys', 'exfsys', 'dmsys', 'wmsys',

'ctxsys', 'anonymous', 'xdb', 'ordplugins', 'si_informtn_schema',

'olapsys', 'mgmt_view', 'sys', 'system', 'outln');

查詢那些使用者,操縱了那些表造成了鎖機

select s.username,

decode(l.type,'tm','table lock',

'tx','row lock',

null) lock_level,

o.owner,o.object_name,o.object_type,

s.sid,s.serial#,s.terminal,s.machine,s.program,s.osuser

from v$session s,v$lock l,all_objects o

where l.sid = s.sid

and l.id1 = o.object_id(+)

and s.username is not null

其中 tm 為表鎖定 tx 為行鎖定

看鎖阻塞的方法是

select (select username from v$session where sid=a.sid) blocker,

a.sid,

'is blocking',

(select username from v$session where sid=b.sid) blockee,

b.sid

from v$lock a, v$lock b

where a.block = 1

and b.request > 0

and a.id1 = b.id1

and a.id2 = b.id2

Oracle表空間和使用者常用語句

刪除空的表空間,但是不包含物理檔案 drop tablespace tablespace name 刪除非空表空間,但是不包含物理檔案 drop tablespace tablespace name including contents 刪除空表空間,包含物理檔案 drop tablespace t...

oracle 常用語句

oracle 產看表空間 select total.name tablespace name free space,total space free space used space,total space from select tablespace name,sum bytes 1024 102...

oracle常用語句

drop tablespace crm online space including contents and datafiles 刪除表空間 drop user wuliu01 cascade 刪除使用者 exp orcl file d dmp 匯出資料庫 imp orcl file e alen...