oracle 表空間基本操作

2022-09-16 01:00:11 字數 4515 閱讀 7463

--

查表空間使用率情況(含臨時表空間)

select

d.tablespace_name "name", d.status "status",

to_char (nvl (a.bytes

/1024

/1024, 0), '

99,999,990.90

') "size (m)",

to_char (nvl (a.bytes

- nvl (f.bytes, 0), 0) /

1024

/1024

,

'99999999.99')

use,

to_char (nvl ((a.bytes

- nvl (f.bytes, 0)) / a.bytes *

100, 0

),

'990.00

') "used %"

from

sys.dba_tablespaces d,

(select tablespace_name, sum

(bytes) bytes

from

dba_data_files

group

bytablespace_name) a,

(select tablespace_name, sum

(bytes) bytes

from

dba_free_space

group

bytablespace_name) f

where d.tablespace_name = a.tablespace_name(+

)

and d.tablespace_name = f.tablespace_name(+

)

andnot (d.extent_management like

'local

'and d.contents like

'temporary')

union

allselect

d.tablespace_name "name", d.status "status",

to_char (nvl (a.bytes

/1024

/1024, 0), '

99,999,990.90

') "size (m)",

to_char (nvl (t.bytes,

0) /

1024

/1024, '

99999999.99

') use

, to_char (nvl (t.bytes

/ a.bytes *

100, 0), '

990.00

') "used %"

from

sys.dba_tablespaces d,

(select tablespace_name, sum

(bytes) bytes

from

dba_temp_files

group

bytablespace_name) a,

(select tablespace_name, sum

(bytes_cached) bytes

from

v$temp_extent_pool

group

bytablespace_name) t

where d.tablespace_name = a.tablespace_name(+

)

and d.tablespace_name = t.tablespace_name(+

)

and d.extent_management like

'local

'and d.contents like

'temporary';

1. 查詢表空間剩餘位元組大小

select tablespace_name, sum(bytes)/

1024

/1024

as "free space

(m)"

from

dba_free_space

where tablespace_name =

'&tablespace_name

'group

bytablespace_name;

注:如果是臨時表空間,請查詢dba_temp_free_space

select tablespace_name, free_space/

1024

/1024

as "free space

(m)"

from

dba_temp_free_space

where tablespace_name =

'&tablespace_name';

2. 查詢表空間所有資料檔案路徑

select tablespace_name, file_id, file_name, bytes/

1024

/1024

as"bytes(m)"

from

dba_data_files

where tablespace_name =

'&tablespace_name';

注:如果是臨時表空間,請查詢dba_temp_files

select tablespace_name, file_id, file_name, bytes/

1024

/1024

as "space

(m)"

from

dba_temp_files

where tablespace_name =

'&tablespace_name';

3. 為空間不足的表空間增加資料檔案

alter tablespace &tablespace_name add datafile '

&datafile_name

'size 2g;

注:如果要為臨時表空間擴容,使用下面的語句

alter tablespace &tablespace_name add tempfile '

&datafile_name

'size 2g;

4.檢視臨時表空間的大小 和 資料檔案路徑

select tablespace_name, file_id, file_name, bytes/

1024

/1024

as "space

(m)"

from

dba_temp_files

where tablespace_name =

'temp';

或者select name, bytes/

1024

/1024

as "大小(m)" from v$tempfile order

bybytes;

5.重建並修改預設臨時表空間辦法:

--查詢當前資料庫預設臨時表空間名

select

*from database_properties where property_name=

'default_temp_tablespace';

--建立新的臨時表空間

create

temporary tablespace temp02 tempfile '

e:\oracle\oradata\lims\temp02.dbf

' size 1024m autoextend on;--

修改預設表空間為剛剛建立的臨時表空間

alter

database

default

temporary

tablespace temp02;

--檢視使用者所用臨時表空間的情況

select username,temporary_tablespace from

dba_users;

--刪除原來的臨時表空間

drop tablespace temp including contents and

datafiles;

--檢視所有表空間名確認臨時表空間是否已刪除

select tablespace_name from

dba_tablespaces;

[---------------------

bǎnquán shēngmíng: běnwén wèi csdn bó zhǔ `okhymok'de yuánchuàng wénzhāng, zūnxún cc 4.0 by-sa bǎnquán xiéyì, zhuǎnzài qǐng fù shàng yuánwén chūchù liànjiē jí běn shēngmíng.

yuánwén liànjiē:

---------------------

original link:

Oracle 表空間基本操作

1.查詢資料庫現在的表空間 select tablespace name,file name,sum bytes 1024 1024 table size from dba data files group by tablespace name,file name 2.建立表空間 create ta...

Oracle 表空間基本操作

1.查詢資料庫現在的表空間 select tablespace name,file name,sum bytes 1024 1024 table size from dba data files group by tablespace name,file name 2.建立表空間 create ta...

oracle有關表空間的基本操作

建立表空間 create tablespace students managent datafile e oracle product 10.2.0 da913047 data da91304701 students management.dbf size 50m,e oracle product ...