扩大数据库表空间物理空间大小

目录

常用sql作为判断依据:

表空间扩大方式:

1.创建表空间时

2.手动增加表空间数据文件大小

3.增加表空间数据文件


常用sql作为判断依据:

当前已用表空间大小
select sum(bytes)/1024/1024 || 'MB' from user_extents;

当前连接数据库实例用户绑定表空间
select username,default_tablespace from user_users;
查看用户下的表空间
select default_tablespace from dba_user where username = 'test';

各表空间剩余空间
select sum(t.bytes)/(1024*1024*1024) GB,t.tablespace_name 表空间
from user_free_space t
group by t.tablespace_name;

查看所有表空间
select * from dba_tablespaces;

查看表空间存放数据文件路径
select tablespace_name,file_id,bytes/1024/1024 MB,file_name 
from dba_data_files where 
tablespace_name = '表空间名称' order by file_id;

有些sql可能权限不够查询,登录服务器,执行sqlplus命令,db用户执行sql比较方便;

表空间扩大方式:

1.创建表空间时

设置一下表空间自动扩大;

Oracle建立表空间和用户

建立表空间和用户的步骤:
用户
建立:create user 用户名 identified by "密码";
授权:grant create session to 用户名;
            grant create table to  用户名;
            grant create tablespace to  用户名;
            grant create view to  用户名;

表空间
建立表空间(一般建N个存数据的表空间和一个索引空间):
create tablespace 表空间名
datafile ' 路径(要先建好路径)\***.dbf  ' size *M
tempfile ' 路径\***.dbf ' size *M
autoextend on  --自动增长
--还有一些定义大小的命令,看需要
 default storage(
 initial 100K,
 next 100k,
);


 例子:创建表空间
create tablespace DEMOSPACE 
datafile 'E:/oracle_tablespaces/DEMOSPACE_TBSPACE.dbf' 
size 1500M 
autoextend on next 5M maxsize 3000M;
删除表空间
drop tablespace DEMOSPACE including contents and datafiles

2.手动增加表空间数据文件大小

例如,表空间的数据文件存放在:/oradata/testdb/esia_test.dbf.dbf

,大小扩大到2048M

alter database datafile 'oradata/testdb/esia_test.dbf.dbf' resize 2048M;

3.增加表空间数据文件

原数据文件不动了,我在给你加一个2G的数据文件进行存储 ,来达到扩容的目的

alter tablespace 表空间名称 add datafile '/home/oracle/oradata/testname009.dbf' size 2048M;

注意sqlplus 执行sql后面加;

猜你喜欢

转载自blog.csdn.net/qq_44691484/article/details/128102323
今日推荐