DB2: alterar localização de containers

Uma atividade de administração que não é incomum em bancos de dados é a readequação de arquivos de dados (chamados de CONTAINERS em DB2) em novos diretórios ou sistemas de arquivos.
No DB2, isto pode ser feito com o comando db2relocatedb.
Com os comandos abaixo, vamos escolher uma tablespace, para realocar seus containers:
db2 => LIST TABLESPACES

           Tablespaces for Current Database

 Tablespace ID                        = 0
 Name                                 = SYSCATSPACE
 Type                                 = Database managed space
 Contents                             = All permanent data. Regular table space.
 State                                = 0x0000
   Detailed explanation:
     Normal

 Tablespace ID                        = 1
 Name                                 = TEMPSPACE1
 Type                                 = System managed space
 Contents                             = System Temporary data
 State                                = 0x0000
   Detailed explanation:
     Normal

 Tablespace ID                        = 2
 Name                                 = USERSPACE1
 Type                                 = Database managed space
 Contents                             = All permanent data. Large table space.
 State                                = 0x0000
   Detailed explanation:
     Normal

 Tablespace ID                        = 3
 Name                                 = IBMDB2SAMPLEREL
 Type                                 = Database managed space
 Contents                             = All permanent data. Large table space.
 State                                = 0x0000
   Detailed explanation:
     Normal

 Tablespace ID                        = 4
 Name                                 = IBMDB2SAMPLEXML
 Type                                 = Database managed space
 Contents                             = All permanent data. Large table space.
 State                                = 0x0000
   Detailed explanation:
     Normal

 Tablespace ID                        = 5
 Name                                 = SYSTOOLSPACE
 Type                                 = Database managed space
 Contents                             = All permanent data. Large table space.
 State                                = 0x0000
   Detailed explanation:
     Normal

 Tablespace ID                        = 6
 Name                                 = TESTE
 Type                                 = Database managed space
 Contents                             = All permanent data. Large table space.
 State                                = 0x0000
   Detailed explanation:
     Normal

db2 => LIST TABLESPACE CONTAINERS FOR 6

            Tablespace Containers for Tablespace 6

 Container ID                         = 0
 Name                                 = /prod/container01
 Type                                 = File

 Container ID                         = 1
 Name                                 = /prod/container0S
 Type                                 = File

 Container ID                         = 2
 Name                                 = /prod/container03
 Type                                 = File

 Container ID                         = 3
 Name                                 = /prod/container04
 Type                                 = File

db2 => QUIT
DB20000I  The QUIT command completed successfully.
Em seguida, paramos a instância completamente e copiamos manualmente os containers:
[db2inst1@nerv00 ~]$ db2stop force
SQL1064N  DB2STOP processing was successful.
[db2inst1@nerv00 ~]$ cp /prod/container01 /home/db2inst1/prod/container01
[db2inst1@nerv00 ~]$ cp /prod/container0S /home/db2inst1/prod/container0S
[db2inst1@nerv00 ~]$ cp /prod/container03 /home/db2inst1/prod/container03
[db2inst1@nerv00 ~]$ cp /prod/container04 /home/db2inst1/prod/container04
Depois criamos um arquivo para ser utilizado pelo comando db2relocatedb. Neste arquivo, através da variável CONT_PATH, colocamos a tradução dos containers, no formato CaminhoVelho/CaminhoNovo.
[db2inst1@nerv00 ~]$ cat relocate.cfg
DB_NAME=SAMPLE
DB_PATH=/home/db2inst1
INSTANCE=db2inst1
NODENUM=0
CONT_PATH=/prod/*,/home/db2inst1/prod/*
Agora executamos o comando, para informar ao DB2 que trocamos os contaienrs de lugar.
[db2inst1@nerv00 ~]$ db2relocatedb -f relocate.cfg
Files and control structures were changed successfully.
DBT1000I  The tool completed successfully.
Em seguida podemos iniciar a instância e conferir o resultado.
[db2inst1@nerv00 ~]$ db2start
SQL1063N  DB2START processing was successful.
[db2inst1@nerv00 ~]$ LIST TABLESPACE CONTAINERS FOR 6
-bash: LIST: command not found
[db2inst1@nerv00 ~]$ db2
(c) Copyright IBM Corporation 1993,2007
Command Line Processor for DB2 Client 9.7.5
You can issue database manager commands and SQL statements from the command prompt. For example: db2 => connect to sample db2 => bind sample.bnd
For general help, type: ?. For command help, type: ? command, where command can be the first few keywords of a database manager command. For example: ? CATALOG DATABASE for help on the CATALOG DATABASE command ? CATALOG for help on all of the CATALOG commands.
To exit db2 interactive mode, type QUIT at the command prompt. Outside interactive mode, all commands must be prefixed with 'db2'. To list the current command option settings, type LIST COMMAND OPTIONS.
For more detailed help, refer to the Online Reference Manual.
db2 => CONNECT TO SAMPLE
Database Connection Information
Database server = DB2/LINUXX8664 9.7.5 SQL authorization ID = DB2INST1 Local database alias = SAMPLE
db2 => LIST TABLESPACE CONTAINERS FOR 6
Tablespace Containers for Tablespace 6
Container ID = 0 Name = /home/db2inst1/prod/container01 Type = File
Container ID = 1 Name = /home/db2inst1/prod/container0S Type = File
Container ID = 2 Name = /home/db2inst1/prod/container03 Type = File
Container ID = 3 Name = /home/db2inst1/prod/container04 Type = File
db2 =>

Leave a Reply

O seu endereço de e-mail não será publicado. Campos obrigatórios são marcados com *

This site uses Akismet to reduce spam. Learn how your comment data is processed.