Vous êtes sur la page 1sur 3

Gestion des tablespaces

I. Rappel :
CREATE {BIGFILE|SMALLFILE} TABLESPACE nom_tablespace
DATAFILE ‘nom_fichier’ [size integer {K,M,G,T} AUTOEXTEND {ON|OFF}
[NEXT integer {K,M,G,T}]
[MAXSIZE UNLIMITED | integer[{K|M|G|T}]
BLOCKSIZE integer K]
{ONLINE|OFFLINE}
Tablespace temporaire:

CREATE {BIGFILE|SMALLFILE} TEMPORARY TABLESPACE nom_tablespace


TEMPFILE ‘nom_fichier’ [size integer {K,M,G,T} REUSE]
AUTOEXTEND {ON|OFF}
[NEXT integer {K,M,G,T}]
[MAXSIZE UNLIMITED | integer[{K|M|G|T}]
{ONLINE|OFFLINE}
REUSE: définit la réutilisation du fichier temporaire s’il existe déjà

V$TEMPFILE : Récupère les noms de tous les fichiers temporaires

Création d’un Tablespace UNDO

CREATE {BIGFILE|SMALLFILE} UNDO TABLESPACE nom_tablespace


DATAFILE ‘nom_fichier’ [size integer {K,M,G,T}
AUTOEXTEND {ON|OFF}
[NEXT integer {K,M,G,T}]
[MAXSIZE UNLIMITED | integer[{K|M|G|T}]
{ONLINE|OFFLINE}
L’agrandissement d’un tablespace (applicatifs temp ou de données)

ALTER TABLESPACE nom_tablespace ADD


DATAFILE|TEMPFILE ‘nom_fichier’ [size integer {K|M|G|T}
AUTOEXTEND {ON|OFF}
[NEXT integer {K|M|G|T}]
[MAXSIZE UNLIMITED|integer{K|M|G|T}]

Le déplacement d’un tablespace

1. Mettre le tablespace offline


2. Host copy
3. ALTER tablespace nom_tablespace
RENAME DATAFILE
‘ancien_fichier’
To
‘nouveau_fichier’

1
Supprimer un tablespace :

DROP tablespace nom_tablespace


[INCLUDING CONTENTS
[AND DATAFILES]] ;
Agrandir un bigfile : redimensionner la taille du fichier

II. TP :
SQLplus /nolog

SQL> conn sys/password@orcl as sysdba

SQL> set linesize 180

SQL> column file_name format a60

SQL> column tablespace_name format a40

Les tablespaes du cdb:

SQL> select tablespace_name, file_name from dba_data_files;

Les tablespace de la pdb :

SQL> alter session set container=orclpdb;

SQL> alter pluggable database orclpdb open;

SQL> select tablespace_name, file_name from dba_data_files;

SQL> select name from v$datafile;

SQL> alter session set container=cdb$root;

SQL> select name from v$datafile;

Création d’un tablespace:

Basculer vers le pdb pour y créer un tablespace :

SQL> create tablespace tbs1 datafile ‘C:\dbf\1.dbf’ size 50M;

SQL> create tablespace tbs2 datafile ‘c:\dbf\2.dbf’ size 50M, ‘c:\dbf\3.dbf’ sie 40M;

Agrandir ce tbs2:

SQL> alter tablespace tbs1 add datafile ‘C:\dbf\4.dbf’ size 20M;

SQL> select tablespace_name, file_name from dba_data_files;

Exemple avec Auto extend on:

SQL> create tablespace tbs3 datafile ‘c:\dbf\5.dbf’ size 100M autoextend on next 20M maxsize 1G;

SQL> create table t1(id_t1 integer, name_t1 varchar2(20)) tablespace tbs1;

SQL> insert into t1 values(1,’aa’)(2,’ab’)(3,’ac’)(4,’ad’)(5,’ae’)(6,’af’) --insérer des enregistrements

2
SQL> drop tablespace tbs1; ???????

SQL> drop tablespace tbs1 INCLUDING CONTENTS; ??

SQL> drop tablespace tbs3 INCLUDING CONTENTS and datafiles;

SQL> drop tablespace tbs2;

Les Tablespaces Bigfile:

SQL> create bigfile tablespace bigtbs1 datafile ‘c:\dbf\big1.dbf’ size 100M;

SQL> alter tablespace bigtbs1 add datafile ‘c:\dbf\big2.dbf’ size 100M; ???

SQL> alter tablespace bigtbs1 resize 150M;

SQL> drop tablespace bigtbs1 INCLUDING CONTENTS and DATAFILES;

SQL> create tablespace tbs2 datafile ‘c:\dbf\2.dbf’ size 50M, ‘c:\dbf\3.dbf’ size 40M;

Déplacer le tablespace de son emplacement d’origine :

-- étape 1. SQL> alter tablespace tbs2 offline;

-- étape 2. SQL> host copy C:\dbf\2.dbf c:\Tablespace\2.dbf

-- étape 2. SQL> host copy C:\dbf\3.dbf c:\Tablespace\3.dbf

SQL> select name from v$datafile;

-- étape 3. SQL> alter tablespace tbs2 rename datafile ‘C:\DBF\2.DBF’ ‘C:\DBF\3.DBF’ to


‘c:\tablespace\2.dbf’, ‘c:\tablespace\3.dbf’;

-- étape 4. SQL> alter tablespace tbs2 online;

SQL> select tablespace_name, file_name from dba_data_files;

SQL>

Vous aimerez peut-être aussi