01 Create a data table space
Locally managed tablespaces:
create tablespace test01 datafile '/oracle/oradata/orcl/test01a.dbf' size 2m autoextend off segment space management auto;
autoextend off - do not automatically expand
segment space management auto - Automatic Segment Management, recommended
Do not automatically extended table space
CREATE TABLESPACE test02 LOGGING DATAFILE '/oracle/oradata/orcl/test02a.dbf' SIZE 2M AUTOEXTEND OFF, '/oracle/oradata/orcl/test02b.dbf' SIZE 2M AUTOEXTEND OFF EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO;
Automatic extension table space
CREATE TABLESPACE test03 LOGGING DATAFILE '/oracle/oradata/orcl/test03a.dbf' SIZE 2M AUTOEXTEND ON NEXT 1M MAXSIZE 20M, '/oracle/oradata/orcl/test03b.dbf' SIZE 2M AUTOEXTEND ON NEXT 1M MAXSIZE 20M EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO;
Create a large table space:
CREATE BIGFILE TABLESPACE bigtbs DATAFILE '/u02/oracle/data/bigtbs01.dbf' SIZE 50G;
02 create a temporary table space
create temporary tablespace temp1 tempfile '/oracle/oradata/orcl/temp1.dbf' size 5m autoextend off;
03 UNDO table space to create
create undo tablespace testundo1 datafile '/oracle/oradata/orcl/testundo1.dbf' size 2m autoextend off;
Expand and modify the size of No. 04 space
Table space to add data files
alter tablespace temp1 add tempfile '/oracle/oradata/orcl/temp1b.dbf' size 5m autoextend off;
alter tablespace test01 add datafile '/oracle/oradata/orcl/test01b.dbf' size 1m autoextend off;
Modify the table space file size
alter database datafile '/oracle/oradata/orcl/test02b.dbf' resize 2m;
select name, bytes from v$tempfile;
alter database tempfile '/oracle/oradata/orcl/temp1.dbf' resize 5m;
05 table space renaming
ALTER TABLESPACE test03 RENAME TO test04;
06 Delete table space
drop tablespace testundo1; - delete table space, without deleting the corresponding data file
drop tablespace test04 including contents and datafiles; - plus the option to delete files with the data together
ORA-02449:: unique / primary keys in table referenced by foreign keys if there
select p.owner, p.table_name, p.constraint_name, f.table_name referencing_table, f.constraint_name foreign_key_name, f.status fk_status from dba_constraints P, dba_constraints F, dba_tables T where p.constraint_name = f.r_constraint_name and f.constraint_type = 'R' and p.table_name = t.table_name and t.tablespace_name = UPPER('&tablespace_name') order by 1,2,3,4,5;
Delete the table space and the corresponding table space file
drop tablespace test04 including contents and datafiles cascade constraints;
07 read-write mode change table space
alter tablespace test01 read only; --test01 read only tablespace
alter tablespace test01 read write; - test01 tablespace writable
View table space states
select tablespace_name,status from dba_tablespaces;
Read-write mode table
alter table test read only; - read-only table so alter table test read write; - so that the table can be read
08 Change the table space online mode
alter tablespace users offline; - offline user table space alter database datafile 6 offline; - 6 offline data file alter database datafile 6 offline for drop; - 6 data file offline, and needs to be recovered alter database datafile 6 online; - - the No. 6 files online recover datafile 6; - 6 file recovery