Expand the physical space size of the database table space

Table of contents

SQL is commonly used as the basis for judgment:

Table space expansion method:

1. When creating a table space

2. Manually increase the table space data file size

3. Add table space data files


SQL is commonly used as the basis for judgment:

当前已用表空间大小
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;

Some SQL may not have enough permissions to query. It is more convenient to log in to the server and execute the sqlplus command. It is more convenient for the db user to execute SQL;

Table space expansion method:

1. When creating a table space

Set the table space to automatically expand;

Oracle creates tablespaces and users

Steps to create tablespace and user:
User
creation: create user username identified by "password";
Authorization: grant create session to username;
            grant create table to username;
            grant create tablespace to username;
            grant create view to username ;

Table space
Create a table space (generally create N table spaces to store data and an index space):
create tablespace table space name
datafile ' path (the path must be established first)\***.dbf ' size *M
tempfile ' path\ ***.dbf ' size *M
autoextend on -- automatic growth
-- there are also some commands to define the size, which requires
 default storage (
 initial 100K,
 next 100k,
);


 Example: create tablespace
create tablespace DEMOSPACE 
datafile 'E:/oracle_tablespaces/DEMOSPACE_TBSPACE.dbf' 
size 1500M 
autoextend on next 5M maxsize 3000M;
delete tablespace
drop tablespace DEMOSPACE including contents and datafiles

2. Manually increase the table space data file size

For example, the data file of the table space is stored in: /oradata/testdb/esia_test.dbf.dbf

, size expanded to 2048M

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

3. Add table space data files

The original data file is immovable. I am adding a 2G data file for storage to achieve the purpose of expansion.

alter tablespace tablespace name add datafile '/home/oracle/oradata/testname009.dbf' size 2048M;

Note that sqlplus is added after executing sql;

Guess you like

Origin blog.csdn.net/qq_44691484/article/details/128102323