Alterar DBID para o número que você quiser

[oracle@Melquior ~]$ rlwrap sqlplus / AS SYSDBA

SQL*Plus: Release 12.2.0.1.0 Production on Wed May 31 13:16:37 2017

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


Conectado a:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

SQL> SHUTDOWN IMMEDIATE;
Banco de dados fechado.
Banco de dados desmontado.
Instancia ORACLE desativada.
SQL> STARTUP MOUNT
Instancia ORACLE iniciada.

Total System Global Area 4294967296 bytes
Fixed Size                  8801008 bytes
Variable Size             956302608 bytes
Database Buffers         3321888768 bytes
Redo Buffers                7974912 bytes
Banco de dados montado.
SQL> @MyDBID.sql

Procedimento PL/SQL concluido com sucesso.


OLD_NAME
--------------------------------------------------------------------------------
ORCL

Enter the new Database Name:ORCL
Enter the new Database ID:1234567890

Procedimento PL/SQL concluido com sucesso.


Procedimento PL/SQL concluido com sucesso.

Convert ORCL(1472721270) to ORCL(1234567890)

Procedimento PL/SQL concluido com sucesso.

ControlFile:
=> Change Name:0
=> Change DBID:1
DataFile: /u01/app/oracle/oradata/ORCL/datafile/o1_mf_system_dlgpok9f_.dbf
=> Skipped:0
=> Change Name:0
=> Change DBID:1
DataFile:
/u01/app/oracle/oradata/ORCL/5061BF97829E4649E053060FA8C0769B/datafile/o1_mf_sys
tem_dlgpovft_.dbf
=> Skipped:0
=> Change Name:0
=> Change DBID:1
DataFile: /u01/app/oracle/oradata/ORCL/datafile/o1_mf_sysaux_dlgpp3p7_.dbf
=> Skipped:0
=> Change Name:0
=> Change DBID:1
DataFile:
/u01/app/oracle/oradata/ORCL/5061BF97829E4649E053060FA8C0769B/datafile/o1_mf_sys
aux_dlgppd9c_.dbf
=> Skipped:0
=> Change Name:0
=> Change DBID:1
DataFile: /u01/app/oracle/oradata/ORCL/datafile/o1_mf_undotbs1_dlgppk07_.dbf
=> Skipped:0
=> Change Name:0
=> Change DBID:1
DataFile:
/u01/app/oracle/oradata/ORCL/5061BF97829E4649E053060FA8C0769B/datafile/o1_mf_und
otbs1_dlgppodk_.dbf
=> Skipped:0
=> Change Name:0
=> Change DBID:1
DataFile: /u01/app/oracle/oradata/ORCL/datafile/o1_mf_users_dlgpqy20_.dbf
=> Skipped:0
=> Change Name:0
=> Change DBID:1
DataFile:
/u01/app/oracle/oradata/ORCL/50637889AF0868E3E053060FA8C0F77B/datafile/o1_mf_sys
tem_dlgxwqk6_.dbf
=> Skipped:0
=> Change Name:0
=> Change DBID:1
DataFile:
/u01/app/oracle/oradata/ORCL/50637889AF0868E3E053060FA8C0F77B/datafile/o1_mf_sys
aux_dlgxwqkr_.dbf
=> Skipped:0
=> Change Name:0
=> Change DBID:1
DataFile:
/u01/app/oracle/oradata/ORCL/50637889AF0868E3E053060FA8C0F77B/datafile/o1_mf_und
otbs1_dlgxwqks_.dbf
=> Skipped:0
=> Change Name:0
=> Change DBID:1
DataFile:
/u01/app/oracle/oradata/ORCL/50637889AF0868E3E053060FA8C0F77B/datafile/o1_mf_use
rs_dlgxxo6v_.dbf
=> Skipped:0
=> Change Name:0
=> Change DBID:1
DataFile: /u01/app/oracle/oradata/ORCL/datafile/o1_mf_soe_dlj1kzsp_.dbf
=> Skipped:0
=> Change Name:0
=> Change DBID:1
DataFile:
/u01/app/oracle/oradata/ORCL/50637889AF0868E3E053060FA8C0F77B/datafile/o1_mf_soe
_dlvzb86p_.dbf
=> Skipped:0
=> Change Name:0
=> Change DBID:1
DataFile: /u01/app/oracle/oradata/ORCL/datafile/o1_mf_soe_dlvzlcvt_.dbf
=> Skipped:0
=> Change Name:0
=> Change DBID:1
DataFile: /u01/app/oracle/oradata/ORCL/datafile/o1_mf_soe_dlvzlh11_.dbf
=> Skipped:0
=> Change Name:0
=> Change DBID:1
DataFile: /u01/app/oracle/oradata/ORCL/datafile/o1_mf_soe_dlvzljvp_.dbf
=> Skipped:0
=> Change Name:0
=> Change DBID:1
DataFile: /u01/app/oracle/oradata/ORCL/datafile/o1_mf_soe_dlvzll9y_.dbf
=> Skipped:0
=> Change Name:0
=> Change DBID:1
DataFile:
/u01/app/oracle/oradata/ORCL/50637889AF0868E3E053060FA8C0F77B/datafile/o1_mf_shs
b_dlxlg2fx_.dbf
=> Skipped:0
=> Change Name:0
=> Change DBID:1
DataFile:
/u01/app/oracle/oradata/ORCL/50637889AF0868E3E053060FA8C0F77B/datafile/o1_mf_shs
bp_dlxlg551_.dbf
=> Skipped:0
=> Change Name:0
=> Change DBID:1
DataFile: /u01/app/oracle/oradata/ORCL/datafile/o1_mf_temp_dlgppq66_.tmp
=> Skipped:0
=> Change Name:0
=> Change DBID:1
DataFile:
/u01/app/oracle/oradata/ORCL/5061BF97829E4649E053060FA8C0769B/datafile/o1_mf_tem
p_dlgppqjm_.tmp
=> Skipped:0
=> Change Name:0
=> Change DBID:1
DataFile:
/u01/app/oracle/oradata/ORCL/50637889AF0868E3E053060FA8C0F77B/datafile/o1_mf_tem
p_dlgxwqkv_.dbf
=> Skipped:0
=> Change Name:0
=> Change DBID:1

Procedimento PL/SQL concluido com sucesso.

SQL> ALTER DATABASE OPEN RESETLOGS;

Banco de dados alterado.

SQL> SELECT DBID FROM V$DATABASE;

      DBID
----------
1234567890

SQL>
SQL> exit
Desconectado de Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
[oracle@Melquior ~]$

Abaixo está o conteúdo do arquivo MyDBID.sql.

[oracle@Melquior ~]$ cat MyDBID.sql
var old_name varchar2(20)
var old_dbid number
var new_name varchar2(20)
var new_dbid number

exec select name, dbid into :old_name,:old_dbid from v$database

print old_name

accept new_name prompt "Enter the new Database Name:"
accept new_dbid prompt "Enter the new Database ID:"

exec :new_name:='&&new_name'
exec :new_dbid:=&&new_dbid

set serveroutput on
exec dbms_output.put_line('Convert '||:old_name||  '('||to_char(:old_dbid)||') to '||:new_name|| '('||to_char(:new_dbid)||')')

declare
  v_chgdbid   binary_integer;
  v_chgdbname binary_integer;
  v_skipped   binary_integer;
begin
  dbms_backup_restore.nidbegin(:new_name,:old_name,:new_dbid,:old_dbid,0,0,10);
  dbms_backup_restore.nidprocesscf(v_chgdbid,v_chgdbname);
  dbms_output.put_line('ControlFile: ');
  dbms_output.put_line('  => Change Name:'||to_char(v_chgdbname));
  dbms_output.put_line('  => Change DBID:'||to_char(v_chgdbid));
  for i in (select file#,name from v$datafile)
     loop
     dbms_backup_restore.nidprocessdf(i.file#,0,v_skipped,v_chgdbid,v_chgdbname);
     dbms_output.put_line('DataFile: '||i.name);
     dbms_output.put_line('  => Skipped:'||to_char(v_skipped));
     dbms_output.put_line('  => Change Name:'||to_char(v_chgdbname));
     dbms_output.put_line('  => Change DBID:'||to_char(v_chgdbid));
     end loop;
  for i in (select file#,name from v$tempfile)
     loop
     dbms_backup_restore.nidprocessdf(i.file#,1, v_skipped,v_chgdbid,v_chgdbname);
     dbms_output.put_line('DataFile: '||i.name);
     dbms_output.put_line('  => Skipped:'||to_char(v_skipped));
     dbms_output.put_line('  => Change Name:'||to_char(v_chgdbname));
     dbms_output.put_line('  => Change DBID:'||to_char(v_chgdbid));
     end loop;
  dbms_backup_restore.nidend;
end;
/

[oracle@Melquior ~]$

8 comments

  1. Muito interessante !! A cada nova versão, estamos vendo grandes avanços e melhorias no SGBD, que está se tornando cada vez mais completo, rápido e seguro.

    1. Na verdade esta não é uma nova funcionalidade do 12cR2, era possível em versões anteriores.

    1. Na verdade esta não é uma melhoria do 12cR2, embora eu tenha feito o teste nesta versão. Eu já testei em 11gR2 e funcionou, creio que funcione em versões mais antigas ainda também.

    1. Obrigado Marcelo. Foi um aluno que me mostrou isso, eu não lembro quem é mas faz tempo, e só fui testar agora.

Leave a Reply

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

Esse site utiliza o Akismet para reduzir spam. Aprenda como seus dados de comentários são processados.