terça-feira, 24 de novembro de 2015

Fragmentando tablespace

 Fragmentação de tablespaces


 Passo 1 - connectar como dba
 a connect system/uninove
 b alter user sys identified by oracle
 c connect sys as sysdba senha:oracle


  passo2 - criando uma tablespa

 a select file_name from dba_data_files;
 b create tablespace tbs_teste

CREATE TABLESPACE tbs_teste
DATAFILE
'C:\APP\ALUNO\ORADATA\ORCL\arq_texte_01.dbf' SIZE 50 M reuse
extent management local
segment space management auto;

passo 3 criando um usuario

create user teste identified by teste
default tablespace tbs_teste
quota unlimited on tbs_teste;

passo 4 grant connect, resource to teste

passo 5 connectar com usuario teste
a criar uma tabela criente na tablespace criada
b criar uma sequence
c fazer uma carga de 100.000
d select count (*) from cliente


create table cliente(
id_cliente number(6),
nome_cliente varchar2(20),
cpf_cliente varchar2(20))
tablespace tbs_teste;


 create sequence
 sequencia_cliente
 start with 40;


 DECLARE
      contador INTEGER;
      CPF_CLI NUMBER(11):=35419972816;
     BEGIN
       contador := 1;
       while contador <= 100000 loop
               insert into cliente values (sequencia_cliente.nextval, 'marcio_marcelo', CPF_CLI);
              contador := contador + 1;
        CPF_CLI := CPF_CLI +1;
       end loop;
       commit;
    end;
  /

select count (*) from cliente;

passo 6 analisar a tabela

analyze table cliente compute statistics;

passo 7  consultar blocos livres e blocos utilizados

select a.blocks, b.blocks hwm, b.empty_blocks
from
user_segments a, user_tables b
where a. segment_name=b.table_name and
b.table_name='CLIENTE';

passo 8 deletando as linhas da tabela cliente

delete from cliente;
commit;

passo 9 analisar a tabela

analyze table cliente compute statistics;

passo 10 consulta dos blocos

select a.blocks, b.blocks hwm, b.empty_blocks
from
user_segments a, user_tables b
where a. segment_name=b.table_name and
b.table_name='CLIENTE';

passo 11 connectar administrador e efetuar
consulta dos extents utilizados
pelo segmento cliente

select extent_id,blocks,block_id from
dba_extents
where upper (segment_name)='CLIENTE' and upper(owner)='TESTE';

passo 12 criar e popular titulo
a connect teste/teste
b create table titulo (id number);
c insert into titulo select level from dual connect by level <=20000;

passo 13 consulta blocos livres e blocos usados

select a.blocks, b.blocks hwm, b.empty_blocks
from
user_segments a, user_tables b
where a. segment_name=b.table_name and
b.table_name='TITULO';

passo 14 consulta dos extents

select extent_id,blocks,block_id from
dba_extents
where upper (segment_name)='TITULO' and upper(owner)='TESTE';

passo 15 eliminar a fragmentação
connect teste/teste
a - alter table cliente move;
b - alter table cliente enable row movement;
c - alter table cliente shrink space;

passo 16  (no system) consulta dos extents do segmento cliente

select extent_id,blocks,block_id from
dba_extents
where upper (segment_name)='CLIENTE' and upper(owner)='TESTE';


Nenhum comentário:

Postar um comentário