Thay đổi thông tin DBNAME trong Oracle database

— 3:26 PM Thursday, December 14, 2023

— Quy trình thay đổi tên DB

— Viết bởi duong_nguyen

— Thủ tục đổi tên database sang tên mới

— Các bước thực hiện

— 1. Đổi thông tin db name

— 2. Đổi thông tin instance name

— thông tin DB hiện tại:

SQL> select dbid, name from v$database;

DBID NAME

———- ———

2903811275 ORADB

— shutdown DB

SQL> shut IMMEDIATE;

Database closed.

Database dismounted.

— Khởi động lại trong chế độ mount

SQL> startup mount;

— Kết nối vào tiện ích NID utility

— setname=yes => chỉ đổi db name

— setname=no => đổi db name và dbid

$ nid TARGET=/ dbname=dev setname=no

DBNEWID: Release 19.0.0.0.0 – Production on Thu Dec 14 16:07:41 2023

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

Connected to database ORADB (DBID=2903811275)

Connected to server version 19.3.0

Control Files in database:

/u01/app/oracle/oradata/ORADB/controlfile/o1_mf_llytgvbb_.ctl

/u01/app/oracle/fast_recovery_area/ORADB/controlfile/o1_mf_llytgvd3_.ctl

Change database ID and database name ORADB to DEV? (Y/[N]) => y

— chọn y để tiến hành đổi

Instance shut down

Database name changed to DEV.

Modify parameter file and generate a new password file before restarting.

Database ID for database DEV changed to 4233870541.

All previous backups and archived redo logs for this database are unusable.

Database is not aware of previous backups and archived logs in Recovery Area.

Database has been shutdown, open database with RESETLOGS option.

Succesfully changed database name and ID.

DBNEWID – Completed succesfully.

— login vào sqlplus sửa tạo pfile và sửa thông tin pfile thành db mới sau đó apply ngược lại DB

SQL> create pfile from spfile

File created.

— Tìm dòng có oradb. và tiến hành xoá hết đi

— Tìm dòng *.db_name=’oradb’ và đổi thành *.db_name=’dev’

— Lưu lại và thoát ra

— Tạo lại spfile từ pfile bên trên

SQL> create spfile from pfile;

File created.

— Start DB và kiểm tra thông tin

SQL> startup

ORACLE instance started.

Total System Global Area 1509946304 bytes

Fixed Size 9135040 bytes

Variable Size 872415232 bytes

Database Buffers 620756992 bytes

Redo Buffers 7639040 bytes

Database mounted.

ORA-01589: must use RESETLOGS or NORESETLOGS option for database open

SQL> alter database open RESETLOGS;

Database altered.

SQL> select name, open_mode from v$database;

NAME OPEN_MODE

——— ——————–

DEV READ WRITE

— Đổi tên isntanece

— Kiểm tra thông tin instance, mặc dù db name đã thay đổi nhưng instance chưa đổi

SQL> select instance_name from v$instance;

INSTANCE_NAME

—————-

oradb

SQL> select instance from v$thread;

INSTANCE

——————————————————————————–

oradb

— Tắt DB

SQL> shut immediate

Database closed.

Database dismounted.

ORACLE instance shut down.

— Thay đổi thông tin trong bash file

$ cd

$ vi .bash_profile

— Tìm ORACLE_SID và sửa thông tin thành dev (cũ là oradb)

ORACLE_SID=dev

— Vào thư mục dbs oracle_home đổi tên pfile

$ cd $ORACLE_HOME/dbs

$ mv initoradb.ora initdev.ora

— Tạo password file

$ orapwd file=orapwdev password=duong123@

— Chạy biến môi trường mới và tạo lại spfile từ pfile mới (dev)

$ cd

$ . .bash_profile

SQL> sqlplus / as sysdba

SQL> create spfile from pfile;

File created.

— Start DB và kiểm tra thông tin

SQL> startup

ORACLE instance started.

Total System Global Area 1509946304 bytes

Fixed Size 9135040 bytes

Variable Size 872415232 bytes

Database Buffers 620756992 bytes

Redo Buffers 7639040 bytes

Database mounted.

Database opened.

SQL> select name, open_mode, dbid from v$database;

NAME OPEN_MODE DBID

——— ——————– ———-

DEV READ WRITE 4233870541

— Kiểm tra đường dẫn datafile thì vẫn là theo tên cũ, có thể để nguyên hoặc đổi tên và đường dẫn mới tuỳ thích

— controlfile cung van theo duong dan cu => muon doi la thi doi nhe !!!

SQL> select name from v$datafile;

/u01/app/oracle/oradata/ORADB/datafile/o1_mf_system_llytcrx4_.dbf

/u01/app/oracle/oradata/ORADB/datafile/o1_mf_sysaux_llytdw3z_.dbf

/u01/app/oracle/oradata/ORADB/datafile/o1_mf_undotbs1_llytfobw_.dbf

/u01/app/oracle/oradata/ORADB/datafile/o1_mf_system_llytssq5_.dbf

/u01/app/oracle/oradata/ORADB/datafile/o1_mf_sysaux_llytssq8_.dbf

— Đã xong !!!

 

Datalinks.vn

Hello các bạn, tôi là Dương Nguyễn (DuoDBA), là người đang tập tành viết lách trên blog này. Mong muốn được chia sẻ kiến thức và kinh nghiệm về cơ sở dữ liệu với những người đam mê và quan tâm đến lĩnh vực này. #Tôi có tổ chức các khoá Coaching về #OracleDatabase và luyện thi #OCP thường xuyên, các bạn cần người đồng hành thì alo tôi nhé. Call/Zalo: 0765 871 888. Thanks you !.....
0 0 đánh giá
Đánh giá bài viết
Theo dõi
Thông báo của
guest

0 Góp ý
Phản hồi nội tuyến
Xem tất cả bình luận