标签归档:空间

Oracle增加表空间步骤

本文只介绍新增文件的方式(其他方式类似可自行研究):

1、通过命令:show parameter db_block_size,来查询当前数据库单个文件的最大size,如果是8192(8K),最大单个文件为32G,如果是16384(16K),最大单个文件为64G。

2、通过以下命令查询当前系统对应需要增加数据文件的表空间信息。

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 1;

3、通过以下命令查询表空间对应单个文件的信息(主要是保证新增的数据文件跟原有文件保存信息一致,如保证单个文件一致)。

SELECT “File Name”, “Tablespace”, “Status”, “Size (MB)”, “Used (MB)”, “Used (Proportion)”, “Used (%)”, “Auto Extend” FROM(
select * from (
SELECT /*+ all_rows use_concat */
‘SQLDEV:LINK{#;#}’||USER||’#;#DATAFILE#;#’||ddf.file_name||’#;#oracle.dbtools.raptor.dba.navigator.Drill.DBADrillLink’ as “File Name”,
ddf.tablespace_name as “Tablespace”,
ddf.online_status as “Status”,
TO_CHAR(NVL(ddf.bytes / 1024 / 1024, 0), ‘99999990.000’) as “Size (MB)”,
TO_CHAR(DECODE(NVL(u.bytes/1024/1024, 0), 0, NVL((ddf.bytes – NVL(s.bytes, 0))/1024/1024, 0), NVL(u.bytes/1024/1024, 0)), ‘99999999.999’) as “Used (MB)”,
CASE
when ddf.online_status = ‘OFFLINE’ then
‘OFFLINE’
when ddf.online_status = ‘RECOVER’ then
‘RECOVER’
else
‘SQLDEV:GAUGE:0:100:0:0:’|| TRIM(TO_CHAR(DECODE((NVL(u.bytes, 0) / ddf.bytes * 100), 0, NVL((ddf.bytes – NVL(s.bytes, 0)) / ddf.bytes * 100, 0), (NVL(u.bytes, 0) / ddf.bytes * 100)), ‘990’))
end as “Used (Proportion)”,
TO_CHAR(DECODE((NVL(u.bytes, 0) / ddf.bytes * 100), 0, NVL((ddf.bytes – NVL(s.bytes, 0)) / ddf.bytes * 100, 0), (NVL(u.bytes, 0) / ddf.bytes * 100)), ‘990.99’) as “Used (%)”,
ddf.autoextensible as “Auto Extend”
FROM
sys.dba_data_files ddf,
(
SELECT
file_id,
SUM(bytes) bytes
FROM
sys.dba_free_space GROUP BY file_id
) s,
(
SELECT
file_id,
SUM(bytes) bytes
FROM
sys.dba_undo_extents
WHERE
status <> ‘EXPIRED’
GROUP BY file_id
) u
WHERE
(ddf.file_id = s.file_id(+) and ddf.file_id=u.file_id(+))
UNION
SELECT
‘SQLDEV:LINK{#;#}’||USER||’#;#DATAFILE#;#’||v.name||’#;#oracle.dbtools.raptor.dba.navigator.Drill.DBADrillLink’ as “File Name”,
dtf.tablespace_name as “Tablespace”,
dtf.status as “Status”,
TO_CHAR(NVL(dtf.bytes / 1024 / 1024, 0), ‘99999990.000’) as “Size (MB)”,
TO_CHAR(NVL(t.bytes_used/1024/1024, 0), ‘99999990.000’) as “Used (MB)”,
CASE
when dtf.status = ‘OFFLINE’ then
‘OFFLINE’
else
‘SQLDEV:GAUGE:0:100:0:0:’|| TRIM(TO_CHAR(NVL(t.bytes_used / dtf.bytes * 100, 0), ‘990.99’))
end as “Used (Proportion)”,
TO_CHAR(NVL(t.bytes_used / dtf.bytes * 100, 0), ‘990’) as “Used (%)”,
dtf.autoextensible as “Auto Extend”
FROM
sys.dba_temp_files dtf,
sys.v_$tempfile v,
v$temp_extent_pool t
WHERE
(dtf.file_name = v.name or dtf.file_id = v.file#)
and dtf.file_id = t.file_id(+)
ORDER BY 1
) sub1 order by 2 asc
)

4、新增文件命令。

alter tablespace APPS_TS_TX_DATA add datafile ‘/u01/DEV/db/data/a_txn_data07.dbf’ size 10000m;