oracle数据库表空间
2016-01-05 16:21
465 查看
1.查看表空间自动增长情况:
SELECT T.TABLESPACE_NAME,D.FILE_NAME,
D.AUTOEXTENSIBLE,D.BYTES,D.MAXBYTES,D.STATUS
FROM DBA_TABLESPACES T,DBA_DATA_FILES D
WHERE T.TABLESPACE_NAME =D.TABLESPACE_NAME
ORDER BY TABLESPACE_NAME,FILE_NAME;
2.查看各表空间分配情况。
select tablespace_name, sum(bytes) / 1024 / 1024 from dba_data_files
group by tablespace_name;
3.查看各表空间空闲情况。
select tablespace_name, sum(bytes) / 1024 / 1024 from dba_free_space group by tablespace_name;
4.更改数据表大小(10G)
alter database datafile '/ora/oradata/radius/undo.dbf' resize 10240m;
5.设置表空间不足时自动增长
5.1查看表空间是否自动增长
SELECT FILE_NAME,TABLESPACE_NAME,AUTOEXTENSIBLE FROM dba_data_files;
5.2 设置表空间自动增长
ALTER DATABASE DATAFILE 'c:\SmartDB01.ora' AUTOEXTEND ON;//打开自动增长
ALTER DATABASE DATAFILE 'c:\SmartDB01.ora' AUTOEXTEND ON NEXT 200M ;//每次自动增长200m
ALTER DATABASE DATAFILE 'c:\SmartDB01.ora' AUTOEXTEND ON NEXT 200M MAXSIZE 1024M;//每次自动增长200m,数据表最大不超过1G
===============================--1查看表空间已经使用的百分比
select a.tablespace_name,a.bytes/1024/1024 "Sum MB",(a.bytes-b.bytes)/1024/1024 "used MB",b.bytes/1024/1024 "free MB",round(((a.bytes-b.bytes)/a.bytes)*100,2) "percent_used"
from
(select tablespace_name,sum(bytes) bytes from dba_data_files group by tablespace_name) a,
(select tablespace_name,sum(bytes) bytes,max(bytes) largest from dba_free_space group by tablespace_name) b
where a.tablespace_name=b.tablespace_name
order by ((a.bytes-b.bytes)/a.bytes) desc
“Sum MB”表示表空间所有的数据文件总共在操作系统占用磁盘空间的大小
比如:test表空间有2个数据文件,datafile1为300MB,datafile2为400MB,那么test表空间的“Sum MB”就是700MB
“userd MB”表示表空间已经使用了多少
“free MB”表示表空间剩余多少
“percent_user”表示已经使用的百分比
--2比如从1中查看到MLOG_NORM_SPACE表空间已使用百分比达到90%以上,可以查看该表空间总共有几个数据文件,每个数据文件是否自动扩展,可以自动扩展的最大值。
[html]
view plaincopyprint?
select file_name,tablespace_name,bytes/1024/1024 "bytes MB",maxbytes/1024/1024 "maxbytes MB" from dba_data_files
where tablespace_name='MLOG_NORM_SPACE';
--4确认磁盘空间足够,增加一个数据文件
[html]
view plaincopyprint?
alter tablespace MLOG_NORM_SPACE
add datafile '/oracle/oms/oradata/mlog/Mlog_Norm_data001.dbf'
size 10M autoextend on maxsize 20G
--6如果删除表空间数据文件,如下:
[html]
view plaincopyprint?
alter tablespace MLOG_NORM_SPACE
drop datafile '/oracle/oms/oradata/mlog/Mlog_Norm_data001.dbf'
alter tablespace MLOG_NORM_SPACE
drop datafile '/oracle/oms/oradata/mlog/Mlog_Norm_data001.dbf'
备注: linux下查看磁盘剩余空间和文件夹大小
df -hl 查看磁盘剩余空间
du -sm 文件夹
返回该文件夹总M数
更多功能查看:
df --help
du --help
du --help
用法:du [选项]... [文件]...
总结每个<文件>的磁盘用量,目录则取总用量。
长选项必须用的参数在使用短选项时也是必须的。
-a, --all write counts for all files, not just directories
--apparent-size print apparent sizes, rather than disk usage; although
the apparent size is usually smaller, it may be
larger due to holes in (`sparse') files, internal
fragmentation, indirect blocks, and the like
-B, --block-size=SIZE use SIZE-byte blocks
-b, --bytes equivalent to `--apparent-size --block-size=1'
-c, --total produce a grand total
-D, --dereference-args dereference FILEs that are symbolic links
-H like --si, but also evokes a warning; will soon
change to be equivalent to --dereference-args (-D)
-h, --human-readable print sizes in human readable format (e.g., 1K 234M 2G)
--si like -h, but use powers of 1000 not 1024
-k like --block-size=1K
-l, --count-links count sizes many times if hard linked
-L, --dereference dereference all symbolic links
-P, --no-dereference don't follow any symbolic links (this is the default)
-0, --null end each output line with 0 byte rather than newline
-S, --separate-dirs do not include size of subdirectories
-s, --summarize display only a total for each argument
-x, --one-file-system skip directories on different filesystems
-X FILE, --exclude-from=FILE Exclude files that match any pattern in FILE.
--exclude=PATTERN Exclude files that match PATTERN.
--max-depth=N print the total for a directory (or file, with --all)
only if it is N or fewer levels below the command
line argument; --max-depth=0 is the same as
--summarize
--help 显示此帮助信息并离开
--version 显示版本信息并离开
du -smh oracle 查看文件夹的大小(oracle 文件夹名)
54G //显示oracle文件夹的大小为54G
SELECT T.TABLESPACE_NAME,D.FILE_NAME,
D.AUTOEXTENSIBLE,D.BYTES,D.MAXBYTES,D.STATUS
FROM DBA_TABLESPACES T,DBA_DATA_FILES D
WHERE T.TABLESPACE_NAME =D.TABLESPACE_NAME
ORDER BY TABLESPACE_NAME,FILE_NAME;
2.查看各表空间分配情况。
select tablespace_name, sum(bytes) / 1024 / 1024 from dba_data_files
group by tablespace_name;
3.查看各表空间空闲情况。
select tablespace_name, sum(bytes) / 1024 / 1024 from dba_free_space group by tablespace_name;
4.更改数据表大小(10G)
alter database datafile '/ora/oradata/radius/undo.dbf' resize 10240m;
5.设置表空间不足时自动增长
5.1查看表空间是否自动增长
SELECT FILE_NAME,TABLESPACE_NAME,AUTOEXTENSIBLE FROM dba_data_files;
5.2 设置表空间自动增长
ALTER DATABASE DATAFILE 'c:\SmartDB01.ora' AUTOEXTEND ON;//打开自动增长
ALTER DATABASE DATAFILE 'c:\SmartDB01.ora' AUTOEXTEND ON NEXT 200M ;//每次自动增长200m
ALTER DATABASE DATAFILE 'c:\SmartDB01.ora' AUTOEXTEND ON NEXT 200M MAXSIZE 1024M;//每次自动增长200m,数据表最大不超过1G
===============================--1查看表空间已经使用的百分比
select a.tablespace_name,a.bytes/1024/1024 "Sum MB",(a.bytes-b.bytes)/1024/1024 "used MB",b.bytes/1024/1024 "free MB",round(((a.bytes-b.bytes)/a.bytes)*100,2) "percent_used"
from
(select tablespace_name,sum(bytes) bytes from dba_data_files group by tablespace_name) a,
(select tablespace_name,sum(bytes) bytes,max(bytes) largest from dba_free_space group by tablespace_name) b
where a.tablespace_name=b.tablespace_name
order by ((a.bytes-b.bytes)/a.bytes) desc
“Sum MB”表示表空间所有的数据文件总共在操作系统占用磁盘空间的大小
比如:test表空间有2个数据文件,datafile1为300MB,datafile2为400MB,那么test表空间的“Sum MB”就是700MB
“userd MB”表示表空间已经使用了多少
“free MB”表示表空间剩余多少
“percent_user”表示已经使用的百分比
--2比如从1中查看到MLOG_NORM_SPACE表空间已使用百分比达到90%以上,可以查看该表空间总共有几个数据文件,每个数据文件是否自动扩展,可以自动扩展的最大值。
[html]
view plaincopyprint?
select file_name,tablespace_name,bytes/1024/1024 "bytes MB",maxbytes/1024/1024 "maxbytes MB" from dba_data_files
where tablespace_name='MLOG_NORM_SPACE';
[html] view plaincopyprint? select dbms_metadata.get_ddl('TABLESPACE','MLOG_NORM_SPACE') from dual; select dbms_metadata.get_ddl('TABLESPACE','MLOG_NORM_SPACE') from dual;
--4确认磁盘空间足够,增加一个数据文件
[html]
view plaincopyprint?
alter tablespace MLOG_NORM_SPACE
add datafile '/oracle/oms/oradata/mlog/Mlog_Norm_data001.dbf'
size 10M autoextend on maxsize 20G
[html] view plaincopyprint? select file_name,file_id,tablespace_name from dba_data_files where tablespace_name='MLOG_NORM_SPACE' select file_name,file_id,tablespace_name from dba_data_files where tablespace_name='MLOG_NORM_SPACE'
--6如果删除表空间数据文件,如下:
[html]
view plaincopyprint?
alter tablespace MLOG_NORM_SPACE
drop datafile '/oracle/oms/oradata/mlog/Mlog_Norm_data001.dbf'
alter tablespace MLOG_NORM_SPACE
drop datafile '/oracle/oms/oradata/mlog/Mlog_Norm_data001.dbf'
备注: linux下查看磁盘剩余空间和文件夹大小
df -hl 查看磁盘剩余空间
du -sm 文件夹
返回该文件夹总M数
更多功能查看:
df --help
du --help
du --help
用法:du [选项]... [文件]...
总结每个<文件>的磁盘用量,目录则取总用量。
长选项必须用的参数在使用短选项时也是必须的。
-a, --all write counts for all files, not just directories
--apparent-size print apparent sizes, rather than disk usage; although
the apparent size is usually smaller, it may be
larger due to holes in (`sparse') files, internal
fragmentation, indirect blocks, and the like
-B, --block-size=SIZE use SIZE-byte blocks
-b, --bytes equivalent to `--apparent-size --block-size=1'
-c, --total produce a grand total
-D, --dereference-args dereference FILEs that are symbolic links
-H like --si, but also evokes a warning; will soon
change to be equivalent to --dereference-args (-D)
-h, --human-readable print sizes in human readable format (e.g., 1K 234M 2G)
--si like -h, but use powers of 1000 not 1024
-k like --block-size=1K
-l, --count-links count sizes many times if hard linked
-L, --dereference dereference all symbolic links
-P, --no-dereference don't follow any symbolic links (this is the default)
-0, --null end each output line with 0 byte rather than newline
-S, --separate-dirs do not include size of subdirectories
-s, --summarize display only a total for each argument
-x, --one-file-system skip directories on different filesystems
-X FILE, --exclude-from=FILE Exclude files that match any pattern in FILE.
--exclude=PATTERN Exclude files that match PATTERN.
--max-depth=N print the total for a directory (or file, with --all)
only if it is N or fewer levels below the command
line argument; --max-depth=0 is the same as
--summarize
--help 显示此帮助信息并离开
--version 显示版本信息并离开
du -smh oracle 查看文件夹的大小(oracle 文件夹名)
54G //显示oracle文件夹的大小为54G
相关文章推荐
- C# 连接 Oracle 的几种方式
- oracle 删除用户,提示“无法删除当前已连接的用户”
- oracle数据库之快速精简教程
- 如何提高oracle的查询速度(详解)
- oracle创建表空间
- 用mysql实现类似于oracle dblink的功能
- Windows C盘格式化或者同平台迁移oracle数据库
- oracle之使用dblink操作远程数据库
- Oracle11g 账号锁定及密码有效期问题
- oracle解除表锁定
- oracle修改序列
- 修改oracle用户密码永不过期
- oracle11R2 log_archive_format
- Oracle trunc()函数
- Oracle 12c ASM 防火防盗新特性揭秘
- 【转】45 个非常有用的 Oracle 查询语句
- 数据库(oracle)常用查询,去年年底时间,当年年初时间,日月年时间格式
- Oracle 查看表空间剩余与创建空间语法
- ORACLE 序列
- oracle错误消息字符串和表里字符串字段(分别)乱码的原因(NLS)