segunda-feira, 30 de agosto de 2010

Simulando um Workload de Produção

Objetivo:
As mudanças nas configurações do ambiente de produção são consideradas críticas e a única forma de mitigar os riscos é a relização de testes o mais próximo possível da realidade da produção e que represente um dia de pico de atividades. Muitas ferramentas foram desenvolvidas com essa finalidade ao longo dos anos, mas nenhuma delas consegue simular um workload real de um base de produção, agora foi disponibilizada uma new feature na versão 11g (RAT - Real Application Testing) que possibilita a reprodução de um Workload de produção durante um periodo desejado em ambiente de teste.
A utilização da new feature RAT é muito simples utilizando o Enterprise Manager, mas vamos fazer uma simulação utilizando as API’s do Oracle para entender melhor o conceito desse novo recurso.


Ambiente:
SO: Linux 2.6.9-67.0.0.0.1.EL i686 i386 GNU/Linux
Base: Oracle Database 11.2.0.1.0


Tópicos:
1. Preparando o ambiente para a simulação;
2. Capturando o Workload de Produção;
3. Pré-processamento do Workload de Produção;
4. Executado o Workload capturado numa base de teste;
5. Analisando a execução de teste e gerando relatório;

1. Preparando o ambiente para simulação


1.1 Baixe o arquivo zip com os scripts e descompacte os arquivos em um diretório de trabalho no servidor linux de teste:
http://st-curriculum.oracle.com/obe/db/11g/r2/prod/manage/dbreplay/files/dbreplay.zip


1.2 Abra um terminal Linux, acesse o diretório onde você gravou os scripts e execute o script “first_time.sh”:



[oracle@odbsrv02 scripts]$ pwd
/u02/dbreplay/scripts
[oracle@odbsrv02 scripts]$ chmod 755 *.sh
[oracle@odbsrv02 scripts]$ ./first_time.sh
rm: cannot remove `wcr_demo': No such file or directory
make: *** [clean] Error 1
gcc -c -I. -I/u01/app/oracle/product/11.2.0/lab1/rdbms/public test_common.c
gcc -c -I. -I/u01/app/oracle/product/11.2.0/lab1/rdbms/public wcr_demo.c
gcc -g -o wcr_demo test_common.o wcr_demo.o -L/u01/app/oracle/product/11.2.0/lab1/lib -lclntsh
[oracle@odbsrv02 scripts]$

Obs: O erro apontado pode ser ignorado.


1.3 Altere a senha do usuário sys no script wcr_demo_init.sh de acordo com o seu ambiente e execute este script;



[oracle@odbsrv02 scripts]$ ./wcr_demo_init.sh

SQL*Plus: Release 11.2.0.1.0 Production on Thu Aug 5 10:35:21 2010

Copyright (c) 1982, 2009, Oracle. All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL>
User altered.

SQL>
User altered.

SQL>
SQL> Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL*Plus: Release 11.2.0.1.0 Production on Thu Aug 5 10:35:22 2010

Copyright (c) 1982, 2009, Oracle. All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL>
SQL> Connected.
SQL>
SQL> drop table wcr_grid
*
ERROR at line 1:
ORA-00942: table or view does not exist


SQL> drop table wcr_grid
*
ERROR at line 1:
ORA-00942: table or view does not exist


SQL>
Table created.

SQL>
SQL> SET ECHO ON
SQL> SET FEEDBACK 1
SQL> SET NUMWIDTH 10
SQL> SET LINESIZE 80
SQL> SET TRIMSPOOL ON
SQL> SET TAB OFF
SQL> SET PAGESIZE 100
SQL>
SQL> connect scott/tiger
Connected.
SQL>
SQL> delete from wcr_grid;

0 rows deleted.

SQL>
SQL> declare
2 id number;
3 x number;
4 y number;
5 c varchar2(100);
6 begin
7 x := 0;
8 y := 0;
9 id := 0;
10 c := 'black';
11
12 for i in 1..10 loop
13
14 for i in 1..10 loop
15
16 insert into wcr_grid values (id, x, y, c);
17 y := y + 1;
18 id := id + 1;
19
20 end loop;
21
22 x := x + 1;
23 y := 0;
24
25 end loop;
26 end;
27 /

PL/SQL procedure successfully completed.

SQL>
SQL> commit;

Commit complete.

SQL> Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@odbsrv02 scripts]$

.


1.4 Adicione o diretório de scripts à variável de ambiente PATH e adicione o diretório $ORACLE_HOME/lib à variável de ambiente LD_LIBRARY_PATH:


[oracle@odbsrv02 scripts]$ export PATH=.:$PATH
[oracle@odbsrv02 scripts]$ export LD_LIBRARY_PATH=$ORACLE_HOME/lib


2. Capturando o Workload de Produção


2.1 Desative o Banco de Dados – Este procedimento não é obrigatório, mas é recomendado para evitar a captura de transações incompletas, ou seja, as transações que iniciaram antes do inicio do processo de captura;



[oracle@odbsrv02 bin]$ ./emctl stop dbconsole
Oracle Enterprise Manager 11g Database Control Release 11.2.0.1.0
Copyright (c) 1996, 2009 Oracle Corporation. All rights reserved.
https://odbsrv02.localdomain:5501/em/console/aboutApplication
Stopping Oracle Enterprise Manager 11g Database Control ...
... Stopped.
[oracle@odbsrv02 bin]$ lsnrctl stop

LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 05-AUG-2010 11:06:51

Copyright (c) 1991, 2009, Oracle. All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1)))
The command completed successfully
[oracle@odbsrv02 bin]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Thu Aug 5 11:07:02 2010

Copyright (c) 1982, 2009, Oracle. All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@odbsrv02 bin]$

.


2.2 Antes de iniciar o Banco de Dados faça um Cold Backup que será restaurado na base de teste, dessa forma podemos garantir que os dados da aplicação do inicio da captura do workload serão os mesmos no inicio do “Replay”;


2.3 Crie um diretório para armazenar os arquivos de captura do workload:



[oracle@odbsrv02 dbreplay]$ mkdir /u02/dbreplay/workload
[oracle@odbsrv02 dbreplay]$ cd /u02/dbreplay/workload
[oracle@odbsrv02 workload]$ pwd
/u02/dbreplay/workload
[oracle@odbsrv02 workload]$

.


2.4 Inicie o Banco de Dados em modo restrito para evitar que usuários acessem a base e iniciem transações antes de iniciarmos a captura do workload:



[oracle@odbsrv02 workload]$ lsnrctl start

LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 05-AUG-2010 11:46:59

Copyright (c) 1991, 2009, Oracle. All rights reserved.

Starting /u01/app/oracle/product/11.2.0/lab1/bin/tnslsnr: please wait...

TNSLSNR for Linux: Version 11.2.0.1.0 - Production
System parameter file is /u01/app/oracle/product/11.2.0/lab1/network/admin/listener.ora
Log messages written to /u01/app/oracle/diag/tnslsnr/odbsrv02/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=odbsrv02.localdomain)(PORT=1521)))

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 11.2.0.1.0 - Production
Start Date 05-AUG-2010 11:47:00
Uptime 0 days 0 hr. 0 min. 0 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/11.2.0/lab1/network/admin/listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/odbsrv02/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=odbsrv02.localdomain)(PORT=1521)))
Services Summary...
Service "PLSExtProc" has 1 instance(s).
Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
[oracle@odbsrv02 workload]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Thu Aug 5 11:47:07 2010

Copyright (c) 1982, 2009, Oracle. All rights reserved.

Connected to an idle instance.

SQL> startup restrict;
ORACLE instance started.

Total System Global Area 795127808 bytes
Fixed Size 1339456 bytes
Variable Size 276828096 bytes
Database Buffers 511705088 bytes
Redo Buffers 5255168 bytes
Database mounted.
Database opened.
SQL>
SQL> select logins from v$instance;

LOGINS
----------
RESTRICTED

SQL>

.


2.5 Inicie a captura do workload, este procedimento retira automaticamente a base do modo restrito:



SQL> create directory "ago10" as '/u02/dbreplay/workload';

Directory created.

SQL>
SQL> begin
2 dbms_workload_capture.start_capture ( name => '2010Ago',
3 dir => 'ago10');
4 end;
5 /

PL/SQL procedure successfully completed.

SQL>
SQL> select logins from v$instance;

LOGINS
----------
ALLOWED

SQL>

Name => Nome que você atribui a essa captura de workload
Dir => Especifique um diretório que vai receber os arquivos de workload
Duration => Especifique quantos segundos a captura vai durar

Dos três parametros somente o “Dir” é obrigatório, você pode omitir o parâmetro
“Duration” e encerrar a captura manualmente utilizando a procedure FINISH_CAPTURE
da package DBMS_WORKLOAD_CAPTURE.


.


2.6 Volte para a sessão Linux do tópico 1 e inicie o script que vai simular o workload:



[oracle@odbsrv02 scripts]$ pwd
/u02/dbreplay/scripts
[oracle@odbsrv02 scripts]$ ./wcr_demo_workload.sh
[1] 5937
[2] 5938
[3] 5939
[4] 5940
[5] 5941
[6] 5942
[7] 5943
Color: blue, Thinktime: 0.010000, Number of pixels:100, Number of updates:3000 Initial delay:0 updates per commit:1
Color: salmon, Thinktime: 0.000010, Number of pixels:100, Number of updates:2000 Initial delay:40 updates per commit:1
Color: orange, Thinktime: 0.000010, Number of pixels:100, Number of updates:2000 Initial delay:30 updates per commit:1
Color: yellow, Thinktime: 0.000010, Number of pixels:100, Number of updates:2000 Initial delay:10 updates per commit:1
[8] 5944
Color: red, Thinktime: 0.010000, Number of pixels:100, Number of updates:3000 Initial delay:0 updates per commit:1
Color: green, Thinktime: 0.010000, Number of pixels:100, Number of updates:3000 Initial delay:0 updates per commit:1
Color: black, Thinktime: 0.010000, Number of pixels:100, Number of updates:3000 Initial delay:0 updates per commit:1
[9] 5948
[10] 5954
[11] 5956
[12] 5957

SQL*Plus: Release 11.2.0.1.0 Production on Thu Aug 5 13:38:09 2010

Copyright (c) 1982, 2009, Oracle. All rights reserved.


SQL*Plus: Release 11.2.0.1.0 Production on Thu Aug 5 13:38:09 2010

Copyright (c) 1982, 2009, Oracle. All rights reserved.


SQL*Plus: Release 11.2.0.1.0 Production on Thu Aug 5 13:38:09 2010

Copyright (c) 1982, 2009, Oracle. All rights reserved.


SQL*Plus: Release 11.2.0.1.0 Production on Thu Aug 5 13:38:10 2010

Copyright (c) 1982, 2009, Oracle. All rights reserved.


SQL*Plus: Release 11.2.0.1.0 Production on Thu Aug 5 13:38:10 2010

Copyright (c) 1982, 2009, Oracle. All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> SQL>
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL>
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL>
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

PL/SQL procedure successfully completed.

SQL> Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

PL/SQL procedure successfully completed.

SQL> Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

PL/SQL procedure successfully completed.

SQL> Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

PL/SQL procedure successfully completed.

SQL> Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[12] Done q.sh
[11] - Done q.sh
[10] + Done q.sh
[9] + Done q.sh
[8] + Done q.sh
[7] + Done wcr_demo -d 40 -c salmon -t 0.00001 -u 2000
[6] + Done wcr_demo -d 30 -c orange -t 0.00001 -u 2000
[5] + Done wcr_demo -c yellow -d 10 -t 0.00001 -u 2000
[4] + Done wcr_demo -u 3000 -t 0.01 -c black
[3] + Done wcr_demo -u 3000 -t 0.01 -c blue
[2] + Done wcr_demo -u 3000 -t 0.01 -c green
[1] + Done wcr_demo -u 3000 -t 0.01 -c red
[oracle@odbsrv02 scripts]$

.


2.7 Quando todas as sessões encerrarem, desative a captura de workload:



SQL> begin
2 dbms_workload_capture.finish_capture ();
3 end;
4 /

PL/SQL procedure successfully completed.

SQL>

.


2.8 Verifique o relatório gerado no diretório:


       /u02/dbreplay/workload/wcr_cr.text


Database Capture Report For LAB1

DB Name DB Id Release RAC Capture Name Status
------------ ----------- ----------- --- -------------------------- ----------
LAB1 2204424562 11.2.0.1.0 NO 2010Ago COMPLETED


Start time: 05-Aug-10 15:14:07 (SCN = 5050437)
End time: 05-Aug-10 16:45:12 (SCN = 5124608)
Duration: 1 hour 31 minutes 5 seconds
Capture size: 8.02 MB
Directory object: ago10
Directory path: /u02/dbreplay/workload
Directory shared in RAC: TRUE
Filters used: 0 EXCLUSION filters

Captured Workload Statistics DB: LAB1 Snaps: 212-254
-> 'Value' represents the corresponding statistic aggregated
across the entire captured database workload.
-> '% Total' is the percentage of 'Value' over the corresponding
system-wide aggregated total.

Statistic Name Value % Total
---------------------------------------- ------------- ---------
DB time (secs) 2162.97 99.90
Average Active Sessions 0.40
User calls captured 36367 99.30
User calls captured with Errors 0
Session logins 25 18.38
Transactions 36000 98.44

.


3. Pré-processamento do Workload de Produção


3.1 Para dar sequência nesta simulação precisamos restaurar o backup que foi feito antes da execução do Workload simulado nas etapas anteriores, no nosso exemplo vamos utilizar uma maquina virtual clone do servidor inicial;


3.2 Crie o diretório para receber os arquivos de workload:



[oracle@odbsrv12 dbreplay]$ pwd
/u02/dbreplay
[oracle@odbsrv12 dbreplay]$ mkdir captura
[oracle@odbsrv12 dbreplay]$ cd captura/
[oracle@odbsrv12 captura]$ pwd
/u02/dbreplay/captura
[oracle@odbsrv12 captura]$

[oracle@odbsrv12 captura]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Fri Aug 6 03:40:44 2010

Copyright (c) 1982, 2009, Oracle. All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> create directory captura as '/u02/dbreplay/captura';

Directory created.

SQL>

.


3.3 Transfira os arquivos de captura gerados na etapa 2.5 no diretório: /u02/dbreplay/workload para a base onde você vai reproduzir o workload no diretório: /u02/dbreplay/captura;


3.4 Execute o processo de pré-processamento do Workload:



SQL> begin
2 dbms_workload_replay.process_capture (capture_dir => 'CAPTURA');
3 end;
4 /

PL/SQL procedure successfully completed.

SQL>

OBS: Este processo vai criar um novo diretório (pp11.2.0.1.0) dentro do diretório
“/u02/dbreplay/captura” onde serão armazenados os arquivos que serão utilizados
no REPLAY do workload.

.


4. Executado o Workload capturado numa base de teste

4.1 Antes de executar o Replay algumas configurações precisam ser realizadas para evitar erros no processo de Replay e a alteração indevida de dados na produção:



* Altere o horário para o mesmo horário da captura do workload em produção;
* Resolva todas as referências externas ao Banco de d ados
(DBLinks, Directories, external tables, URLs, etc...)

.


4.2 Para reproduzir o workload capturado precisamos de uma ou mais instalação de client Oracle 11g e os arquivos pre-processados da captura do workload precisam estar acessíveis aos clients;


4.3 Antes de iniciarmos precisamos verificar quantos clients serão necessários para executar o Replay do workload:



F:\Oracle\OBE\Oracle11g_Mngmt_Replay\workload>wrc mode=calibrate replaydir=.

Workload Replay Client: Release 11.2.0.1.0 - Production on Seg Ago 23 15:15:08 2010

Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.


Report for Workload in: .
-----------------------

Recommendation:
Consider using at least 1 clients divided among 1 CPU(s)
You will need at least 48 MB of memory per client process.
If your machine(s) cannot match that number, consider using more clients.

Workload Characteristics:
- max concurrency: 13 sessions
- total number of sessions: 26

Assumptions:
- 1 client process per 50 concurrent sessions
- 4 client process per CPU
- 256 KB of memory cache per concurrent session
- think time scale = 100
- connect time scale = 100
- synchronization = TRUE


F:\Oracle\OBE\Oracle11g_Mngmt_Replay\workload>


Obs: O processo de calibragem sugere que um client será suficiente para processar
as 26 sessões do workload capturado.

.


4.4 Conecte numa sessão SQLPlus e prepare o processo de Replay:



F:\Oracle\OBE\Oracle11g_Mngmt_Replay\workload>sqlplus /nolog

SQL*Plus: Release 11.2.0.1.0 Production on Seg Ago 23 15:12:24 2010

Copyright (c) 1982, 2010, Oracle. All rights reserved.

SQL> connect sys/oracle@lab12 as sysdba;
Conectado.
SQL> BEGIN
2 DBMS_WORKLOAD_REPLAY.initialize_replay (replay_name => 'test_capture_1',
3 replay_dir => 'CAPTURA');
4 DBMS_WORKLOAD_REPLAY.prepare_replay (synchronization => TRUE);
5 END;
6 /

Procedimento PL/SQL concluído com sucesso.

SQL>

.


4.5 Inicie o client para execução do Replay:



F:\Oracle\OBE\Oracle11g_Mngmt_Replay\workload>wrc system/oracle@lab12 mode=replay replaydir=. CONNECTION_OVERRIDE=TRUE

Workload Replay Client: Release 11.2.0.1.0 - Production on Seg Ago 23 16:29:24 2010

Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.


Wait for the replay to start (16:29:24)

Obs1: O processo de Replay só será iniciado após a execução da próxima etapa.

Obs2: O parametro CONNECTION_OVERRIDE esta sendo utilizado pois o workload de teste
gerado na base de captura foi executado de um client no mesmo servidor do banco e
o Replay esta sendo executado em um client que não esta no servidor do banco.


.


4.6 Após iniciar o client na etapa anterior para executar o workload, este permanecerá parado até que seja executado o comando "start" abaixo numa sessão de SQLPLUS:



SQL> BEGIN
2 DBMS_WORKLOAD_REPLAY.start_replay;
3 END;
4 /

Procedimento PL/SQL concluído com sucesso.

SQL>

.


4.7 Quando o processo de Replay estiver concluido a sessão de client apresentará a mensagem de finalização:



F:\Oracle\OBE\Oracle11g_Mngmt_Replay\workload>wrc system/oracle@lab12 mode=replay replaydir=. CONNECTION_OVERRIDE=TRUE

Workload Replay Client: Release 11.2.0.1.0 - Production on Seg Ago 23 16:29:24 2010

Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.


Wait for the replay to start (16:29:24)
Replay started (16:30:16)
Replay finished (17:45:25)

F:\Oracle\OBE\Oracle11g_Mngmt_Replay\workload>

.


5. Analisando a execução de teste e gerando relatório

5.1 Emita o relatório comparativo da Captura e Replay e verifique as diferenças entre os dois processos:



SQL> select dbms_workload_replay.report(1,'TEXT') from dual;

DBMS_WORKLOAD_REPLAY.REPORT(1,'TEXT')
----------------------------------------------------------------------------------------------------------------------
DB Replay Report for test_capture_1
---------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------
| DB Name | DB Id | Release | RAC | Replay Name | Replay Status |
----------------------------------------------------------------------------
| LAB1 | 2204424562 | 11.2.0.1.0 | NO | test_capture_1 | COMPLETED |
----------------------------------------------------------------------------

Replay Information
--------------------------------------------------------------------------
| Information | Replay | Capture |
--------------------------------------------------------------------------
| Name | test_capture_1 | 2010Ago |
--------------------------------------------------------------------------
| Status | COMPLETED | COMPLETED |
--------------------------------------------------------------------------
| Database Name | LAB1 | LAB1 |
--------------------------------------------------------------------------
| Database Version | 11.2.0.1.0 | 11.2.0.1.0 |
--------------------------------------------------------------------------
| Start Time | 06-08-10 08:42:50 | 05-08-10 15:14:07 |
--------------------------------------------------------------------------
| End Time | 06-08-10 09:40:48 | 05-08-10 16:45:12 |
--------------------------------------------------------------------------
| Duration | 57 minutes 58 seconds | 1 hour 31 minutes 5 seconds |
--------------------------------------------------------------------------
| Directory Object | CAPTURA | CAPTURA |
--------------------------------------------------------------------------
| Directory Path | /u02/dbreplay/captura | /u02/dbreplay/captura |
--------------------------------------------------------------------------

Replay Options
---------------------------------------------------------
| Option Name | Value |
---------------------------------------------------------
| Synchronization | SCN |
---------------------------------------------------------
| Connect Time | 100% |
---------------------------------------------------------
| Think Time | 100% |
---------------------------------------------------------
| Think Time Auto Correct | TRUE |
---------------------------------------------------------
| Number of WRC Clients | 1 (1 Completed, 0 Running ) |
---------------------------------------------------------

Replay Statistics
-----------------------------------------------------------------
| Statistic | Replay | Capture |
-----------------------------------------------------------------
| DB Time | 2236.754 seconds | 2162.968 seconds |
-----------------------------------------------------------------
| Average Active Sessions | .64 | .4 |
-----------------------------------------------------------------
| User calls | 36367 | 36367 |
-----------------------------------------------------------------
| Network Time | 380.858 seconds | . |
-----------------------------------------------------------------
| Think Time | 4002.013 seconds | . |
-----------------------------------------------------------------

Replay Divergence Summary
-------------------------------------------------------------------
| Divergence Type | Count | % Total |
-------------------------------------------------------------------
| Session Failures During Replay | 0 | 0.00 |
-------------------------------------------------------------------
| Errors No Longer Seen During Replay | 0 | 0.00 |
-------------------------------------------------------------------
| New Errors Seen During Replay | 0 | 0.00 |
-------------------------------------------------------------------
| Errors Mutated During Replay | 0 | 0.00 |
-------------------------------------------------------------------
| DMLs with Different Number of Rows Modified | 0 | 0.00 |
-------------------------------------------------------------------
| SELECTs with Different Number of Rows Fetched | 0 | 0.00 |
-------------------------------------------------------------------

.

sexta-feira, 6 de agosto de 2010

Upgrade Oracle10gR2 para Oracle11gR2

Objetivo:

Precisamos fazer um upgrade de uma base Oracle 10gR2 para 11gR2, existem vários procedimentos que podemos utilizar para realizar este upgrade, neste exemplo vamos realizar um upgrade manual utilizando alguns scripts da Oracle disponíveis no diretório $ORACLE_HOME/rdbms/admin de uma instalação do Oracle 11gR2.


Ambiente:
SO: Linux 2.6.9-67.0.0.0.1.EL i686 i386 GNU/Linux
Base: Oracle Database 10.2.0.5.0


Tópicos:

1. Instalando os binários do Oracle 11gR2;
2. Verificando os pré-requisitos;
3. Preparando o banco para Upgrade;
4. Realizando o Upgrade da base;
5. Tarefas após o Upgrade da base;


1. Instalando os binários do Oracle 11gR2


  • Unzip dos arquivos de instalação em um filesystem no servidor que hospeda a base 10gR2, neste exemplo /u02/install;

  • Instale os binários do Oracle 11gR2 utilizando o OUI no diretório: /u01/app/oracle/product/11.2.0/lab1;


2. Verificando os pré-requisitos;

    2.1 Crie um diretório para o Upgrade:
    [oracle@odbsrv02 oracle]$ mkdir /u01/app/oracle/upgrade
      2.2 Copie o script pré-upgrade (utlu112i.sql) do $ORACLE_HOME/rdbms/admin para o diretório de Upgrade:
      [oracle@odbsrv02 upgrade]$ cd /u01/app/oracle/product/11.2.0/lab1/rdbms/admin
      [oracle@odbsrv02 admin]$ cp utlu112i.sql /u01/app/oracle/upgrade
      [oracle@odbsrv02 admin]$ ll /u01/app/oracle/upgrade
      total 188
      -rw-r--r-- 1 oracle oinstall 185744 Jul 9 00:10 utlu112i.sql
      [oracle@odbsrv02 admin]$
      2.3 Conecte-se a base 10g e execute o script de pré-upgrade gravando o resultado num arquivo de log:
      [oracle@odbsrv02 admin]$ cd /u01/app/oracle/upgrade
      [oracle@odbsrv02 upgrade]$ sqlplus / as sysdba

      SQL*Plus: Release 10.2.0.5.0 - Production on Fri Jul 9 00:12:16 2010

      Copyright (c) 1982, 2010, Oracle. All Rights Reserved.


      Connected to:
      Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - Production
      With the Partitioning, OLAP, Data Mining and Real Application Testing options

      SQL> @utlu112i;


      2.4 Abaixo podemos vizualizar o resultado do script:

      
      Oracle Database 11.2 Pre-Upgrade Information Tool    07-09-2010 00:17:12
      .
      **********************************************************************
      Database:
      **********************************************************************
      --> name:          LAB1
      --> version:       10.2.0.5.0
      --> compatible:    10.2.0.1.0
      --> blocksize:     8192
      --> platform:      Linux IA (32-bit)
      --> timezone file: V4
      .
      **********************************************************************
      Tablespaces: [make adjustments in the current environment]
      **********************************************************************
      --> SYSTEM tablespace is adequate for the upgrade.
      .... minimum required size: 764 MB
      .... AUTOEXTEND additional space required: 224 MB
      --> UNDOTBS1 tablespace is adequate for the upgrade.
      .... minimum required size: 76 MB
      --> SYSAUX tablespace is adequate for the upgrade.
      .... minimum required size: 545 MB
      .... AUTOEXTEND additional space required: 215 MB
      --> TEMP tablespace is adequate for the upgrade.
      .... minimum required size: 61 MB
      .... AUTOEXTEND additional space required: 31 MB
      --> EXAMPLE tablespace is adequate for the upgrade.
      .... minimum required size: 94 MB
      .
      **********************************************************************
      Flashback: OFF
      **********************************************************************
      **********************************************************************
      Update Parameters: [Update Oracle Database 11.2 init.ora or spfile]
      **********************************************************************
      WARNING: --> "java_pool_size" needs to be increased to at least 64 MB
      .
      **********************************************************************
      Renamed Parameters: [Update Oracle Database 11.2 init.ora or spfile]
      **********************************************************************
      -- No renamed parameters found. No changes are required.
      .
      **********************************************************************
      Obsolete/Deprecated Parameters: [Update Oracle Database 11.2 init.ora or spfile]
      **********************************************************************
      --> background_dump_dest         11.1       DEPRECATED   replaced by
      "diagnostic_dest"
      --> user_dump_dest               11.1       DEPRECATED   replaced by
      "diagnostic_dest"
      --> core_dump_dest               11.1       DEPRECATED   replaced by
      "diagnostic_dest"
      .
      **********************************************************************
      Components: [The following database components will be upgraded or installed]
      **********************************************************************
      --> Oracle Catalog Views         [upgrade]  VALID
      --> Oracle Packages and Types    [upgrade]  VALID
      --> JServer JAVA Virtual Machine [upgrade]  VALID
      --> Oracle XDK for Java          [upgrade]  VALID
      --> Oracle Workspace Manager     [upgrade]  VALID
      --> OLAP Analytic Workspace      [upgrade]  VALID
      --> OLAP Catalog                 [upgrade]  VALID
      --> EM Repository                [upgrade]  VALID
      --> Oracle Text                  [upgrade]  VALID
      --> Oracle XML Database          [upgrade]  VALID
      --> Oracle Java Packages         [upgrade]  VALID
      --> Oracle interMedia            [upgrade]  VALID
      --> Spatial                      [upgrade]  VALID
      --> Data Mining                  [upgrade]  VALID
      --> Expression Filter            [upgrade]  VALID
      --> Rule Manager                 [upgrade]  VALID
      --> Oracle OLAP API              [upgrade]  VALID
      .
      **********************************************************************
      Miscellaneous Warnings
      **********************************************************************
      WARNING: --> Database is using a timezone file older than version 11.
      .... After the release migration, it is recommended that DBMS_DST package
      .... be used to upgrade the 10.2.0.5.0 database timezone version
      .... to the latest version which comes with the new release.
      WARNING: --> Database contains schemas with stale optimizer statistics.
      .... Refer to the Upgrade Guide for instructions to update
      .... schema statistics prior to upgrading the database.
      .... Component Schemas with stale statistics:
      ....   SYS
      ....   OLAPSYS
      ....   SYSMAN
      WARNING: --> Database contains schemas with objects dependent on network
      packages.
      .... Refer to the Upgrade Guide for instructions to configure Network ACLs.
      .... USER HR has dependent objects.
      .... USER ORACLE_OCM has dependent objects.
      WARNING: --> EM Database Control Repository exists in the database.
      .... Direct downgrade of EM Database Control is not supported. Refer to the
      .... Upgrade Guide for instructions to save the EM data prior to upgrade.
      WARNING:--> recycle bin in use.
      .... Your recycle bin is turned on and it contains
      .... 1 object(s).  It is REQUIRED
      .... that the recycle bin is empty prior to upgrading
      .... your database.
      .... The command:  PURGE DBA_RECYCLEBIN
      .... must be executed immediately prior to executing your upgrade.
      .
      
      PL/SQL procedure successfully completed.
      
      SQL>
      
      .

      3. Preparando o banco para Upgrade;
      3.1 Antes de iniciar o upgrade verifique as recomendações apontadas no relatório gerado pelo script pré-upgrade e realize as modificações necessárias para atender aos pré-riquisitos do upgrade.

      3.2 Atualize as estatísticas apontadas no relatório:

      
      SQL> EXECUTE DBMS_STATS.GATHER_SCHEMA_STATS('CTXSYS',DBMS_STATS.AUTO_SAMPLE_SIZE);
      
      PL/SQL procedure successfully completed.
      
      SQL> EXECUTE DBMS_STATS.GATHER_SCHEMA_STATS('OLAPSYS',DBMS_STATS.AUTO_SAMPLE_SIZE);
      
      PL/SQL procedure successfully completed.
      
      SQL> EXECUTE DBMS_STATS.GATHER_SCHEMA_STATS('SYSMAN',DBMS_STATS.AUTO_SAMPLE_SIZE);
      
      PL/SQL procedure successfully completed.
      
      SQL> EXECUTE DBMS_STATS.GATHER_DICTIONARY_STATS();
      
      PL/SQL procedure successfully completed.
      
      SQL>
      
      .

      3.3 Desative a fila de processos Batch:

      
      SQL> alter system set job_queue_processes=0 scope=BOTH;
      
      System altered.
      
      SQL>
      
      Obs: Se houver algum script agendado na crontab do Linux, tambem devemos desativa-lo durante o processo de upgrade.
      
      .

      3.4 Altere o valor do parametro java_pool_size:

      
      SQL> alter system set java_pool_size = 70M scope=BOTH;
      
      .

      3.4 Ao realizar um upgrade em uma base de produção temos que verificar uma série de situações que podem comprometer o processo de upgrade, o note ID 837570.1 disponibiliza uma lista completa das verificações necessárias.
      4. Realizando o Upgrade da base
      4.1 Faça um backup do spfile e copie o arquivo de initlab1.ora do ORACLE_HOME/dbs (10g) para o ORACLE_HOME/dbs ( 11g);

      4.2 O parametro de inicialização DIAGNOSTIC_DEST substituiu os parametros USER_DUMP_DEST e BACKGROUND_DUMP_DEST que se tornaram obsoletos, altere o arquivo de inicialização ajustando os diretórios para o novo ORACLE_HOME (11g):
      [oracle@odbsrv02 dbs]$ cat initlab1.ora
      lab1.__db_cache_size=255852544
      lab1.__java_pool_size=75497472
      lab1.__large_pool_size=4194304
      lab1.__shared_pool_size=192937984
      lab1.__streams_pool_size=4194304
      *.aq_tm_processes=0
      *.audit_file_dest='/u01/app/oracle/product/11.2.0/lab1/diagnostics/adump'
      *.compatible='10.2.0.1.0'
      *.control_files='/u01/app/oracle/product/10.2.0/oradata/db_1/lab1/control01.ctl',
      '/u01/app/oracle/product/10.2.0/oradata/db_1/lab1/control02.ctl',
      '/u01/app/oracle/product/10.2.0/oradata/db_1/lab1/control03.ctl'
      *.core_dump_dest='/u01/app/oracle/product/11.2.0/lab1/diagnostics/cdump'
      *.db_block_size=8192
      *.db_domain=''
      *.db_name='lab1'
      *.dispatchers='(PROTOCOL=TCP) (SERVICE=lab1XDB)'
      *.java_pool_size=75497472
      *.job_queue_processes=0
      *.nls_length_semantics='BYTE'
      *.open_cursors=300
      *.pga_aggregate_target=25165824
      *.processes=150
      *.remote_login_passwordfile='EXCLUSIVE'
      *.resource_manager_plan=''
      *.sga_max_size=536870912
      *.sga_target=536870912
      *.undo_management='AUTO'
      *.undo_retention=900
      *.undo_tablespace='UNDOTBS1'
      *.utl_file_dir='/u01/app/oracle/product/10.2.0/flash_recovery_area/db_1/LAB1/archivelog'
      *.diagnostic_dest='/u01/app/oracle/product/11.2.0/lab1/diagnostics'
      4.3 Desative a geração de archive para a realização do upgrade, isto permitirá que o upgrade seja realizado num intervalo de tempo menor;
      4.4 Desative o EM DBConsole se estiver ativo;

      4.5 Desative o banco: shutdown immediate;

      4.6 Desative o Listener;

      4.7 Faça um backup full da base antes do upgrade;

      4.8 Copie o arquivo de password do diretório $ORACLE_HOME/dbs do ORACLE_HOME 10g para o ORACLE_HOME 11g;

      4.9 Configure as variáveis de ambiente para a base 11g:
      [oracle@odbsrv02 dbs]$ export ORACLE_BASE=/u01/app/oracle
      [oracle@odbsrv02 dbs]$ export ORACLE_HOME=/u01/app/oracle/product/11.2.0/lab1
      [oracle@odbsrv02 dbs]$ export PATH=/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/home/oracle/bin:/u01/app/oracle/product/11.2.0/lab1/bin
      4.10 Altere o arquivo /etc/oratab para o ORACLE_HOME (11G):
      EXEMPLO /etc/oratab
      #lab1:/u01/app/oracle/product/10.2.0/db_1:N
      lab1:/u01/app/oracle/product/11.2.0/lab1:N

      4.11 Execute o script de upgrade da base:

      
      [oracle@odbsrv02 ~]$ cd $ORACLE_HOME/rdbms/admin
      [oracle@odbsrv02 admin]$ sqlplus / as sysdba
      
      SQL*Plus: Release 11.2.0.1.0 Production on Fri Jul 9 07:12:01 2010
      
      Copyright (c) 1982, 2009, Oracle.  All rights reserved.
      
      Connected to an idle instance.
      
      SQL> startup upgrade;
      ORACLE instance started.
      
      Total System Global Area  535662592 bytes
      Fixed Size                  1337720 bytes
      Variable Size             218105480 bytes
      Database Buffers          310378496 bytes
      Redo Buffers                5840896 bytes
      Database mounted.
      Database opened.
      SQL> @catupgrd;
      
      .

      5. Tarefas após o Upgrade da base;

      5.1 Após o upgrade a base é encerrada e torna-se inativa, vamos ativar a base e verificar a integridade dos objetos:

      
      [oracle@odbsrv02 admin]$ sqlplus / as sysdba
      
      SQL*Plus: Release 11.2.0.1.0 Production on Fri Jul 9 08:19:41 2010
      
      Copyright (c) 1982, 2009, Oracle.  All rights reserved.
      
      Connected to an idle instance.
      
      SQL> startup
      ORACLE instance started.
      
      Total System Global Area  535662592 bytes
      Fixed Size                  1337720 bytes
      Variable Size             218105480 bytes
      Database Buffers          310378496 bytes
      Redo Buffers                5840896 bytes
      Database mounted.
      Database opened.
      SQL> @utlrp.sql
      .
      .
      SQL> select count(*) from dba_objects where status <> 'VALID';
      
      COUNT(*)
      ----------
      0
      
      SQL>
      SQL> @utlu112s.sql
      .
      Oracle Database 11.2 Post-Upgrade Status Tool           08-05-2010 08:40:05
      .
      Component                                Status         Version  HH:MM:SS
      .
      Oracle Server
      .                                         VALID      11.2.0.1.0  00:19:46
      JServer JAVA Virtual Machine
      .                                         VALID      11.2.0.1.0  00:04:47
      Oracle Workspace Manager
      .                                         VALID      11.2.0.1.0  00:01:02
      OLAP Analytic Workspace
      .                                         VALID      11.2.0.1.0  00:00:28
      OLAP Catalog
      .                                         VALID      11.2.0.1.0  00:01:20
      Oracle OLAP API
      .                                         VALID      11.2.0.1.0  00:01:15
      Oracle Enterprise Manager
      .                                         VALID      11.2.0.1.0  00:12:49
      Oracle XDK
      .                                         VALID      11.2.0.1.0  00:03:40
      Oracle Text
      .                                         VALID      11.2.0.1.0  00:01:14
      Oracle XML Database
      .                                         VALID      11.2.0.1.0  00:05:51
      Oracle Database Java Packages
      .                                         VALID      11.2.0.1.0  00:01:06
      Oracle Multimedia
      .                                         VALID      11.2.0.1.0  00:07:51
      Spatial
      .                                         VALID      11.2.0.1.0  00:07:49
      Oracle Expression Filter
      .                                         VALID      11.2.0.1.0  00:00:32
      Oracle Rule Manager
      .                                         VALID      11.2.0.1.0  00:00:19
      Gathering Statistics
      .                                                                00:07:40
      Total Upgrade Time: 01:17:41
      
      PL/SQL procedure successfully completed.
      
      SQL>
      
      .

      5.2 Confirmado que a base esta integra podemos executar o script que realizará as tarefas finais com a base aberta em modo normal:

      
      SQL> spool /u01/app/oracle/upgrade/catuppst.log;
      SQL> @catuppst.sql
      SQL> @utlrp.sql
      SQL> select count(*) from dba_objects where status <> 'VALID';
      
      COUNT(*)
      ----------
      0
      
      SQL>
      
      .

      5.3 Copie o arquivo listener.ora do ORACLE_HOME 10g para o 11g, modifique o arquivo alterando o ORACLE_HOME para 11g e inicie o Listener:

      
      [oracle@odbsrv02 admin]$ cd /u01/app/oracle/product/10.2.0/db_1/network/admin/
      [oracle@odbsrv02 admin]$ cp listener.ora /u01/app/oracle/product/11.2.0/lab1/network/admin/
      [oracle@odbsrv02 admin]$ ll /u01/app/oracle/product/11.2.0/lab1/network/admin/
      total 12
      -rw-r--r--  1 oracle oinstall  516 Aug  5 08:49 listener.ora
      drwxr-xr-x  2 oracle oinstall 4096 Aug  5 05:52 samples
      -rw-r--r--  1 oracle oinstall  187 May  9  2007 shrept.lst
      [oracle@odbsrv02 admin]$ cd /u01/app/oracle/product/11.2.0/lab1/network/admin
      [oracle@odbsrv02 admin]$ vi listener.ora
      [oracle@odbsrv02 admin]$ cat listener.ora
      # listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0/lab1/network/admin/listener.ora
      # Generated by Oracle configuration tools.
      
      SID_LIST_LISTENER =
      (SID_LIST =
      (SID_DESC =
      (SID_NAME = PLSExtProc)
      (ORACLE_HOME = /u01/app/oracle/product/11.2.0/lab1)
      (PROGRAM = extproc)
      )
      )
      
      LISTENER =
      (DESCRIPTION_LIST =
      (DESCRIPTION =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
      (ADDRESS = (PROTOCOL = TCP)(HOST = odbsrv02.localdomain)(PORT = 1521))
      )
      )
      
      [oracle@odbsrv02 admin]$
      [oracle@odbsrv02 admin]$ lsnrctl start
      
      LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 05-AUG-2010 08:55:16
      
      Copyright (c) 1991, 2009, Oracle.  All rights reserved.
      
      Starting /u01/app/oracle/product/11.2.0/lab1/bin/tnslsnr: please wait...
      
      TNSLSNR for Linux: Version 11.2.0.1.0 - Production
      System parameter file is /u01/app/oracle/product/11.2.0/lab1/network/admin/listener.ora
      Log messages written to /u01/app/oracle/diag/tnslsnr/odbsrv02/listener/alert/log.xml
      Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1)))
      Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=odbsrv02.localdomain)(PORT=1521)))
      
      Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1)))
      STATUS of the LISTENER
      ------------------------
      Alias                     LISTENER
      Version                   TNSLSNR for Linux: Version 11.2.0.1.0 - Production
      Start Date                05-AUG-2010 08:55:19
      Uptime                    0 days 0 hr. 0 min. 1 sec
      Trace Level               off
      Security                  ON: Local OS Authentication
      SNMP                      OFF
      Listener Parameter File   /u01/app/oracle/product/11.2.0/lab1/network/admin/listener.ora
      Listener Log File         /u01/app/oracle/diag/tnslsnr/odbsrv02/listener/alert/log.xml
      Listening Endpoints Summary...
      (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1)))
      (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=odbsrv02.localdomain)(PORT=1521)))
      Services Summary...
      Service "PLSExtProc" has 1 instance(s).
      Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
      The command completed successfully
      [oracle@odbsrv02 admin]$
      
      .

      5.4 Atualize os arquivo “/etc/oratab” e “/home/oracle/.bash_profile” com o ORACLE_HOME 11g.