Thứ Năm, 8 tháng 6, 2023

Chuyển đổi Single Instance Oracle Database sang Oracle RAC

Mục đích: Cách chuyển đổi Cơ sở dữ liệu Oracle một phiên bản sang Oracle RAC

Đôi khi bạn cần phải chuyển single instance  thành Oracle RAC.

Để chuyển đổi cơ sở dữ liệu Oracle từ single instance sang Oracle RAC, bạn phải có Oracle RAC, Nếu bạn muốn cài đặt Oracle RAC, bạn có thể đọc bài viết sau để biết cách cài đặt Oracle 19c RAC tại đây

Bây giờ nếu bạn đã cài đặt phần mềm Oracle RAC, thì bạn có thể bắt đầu chuyển đổi single instance sang Oracle RAC.

Các bước chuyển đổi single instance sang Oracle RAC 

Bạn nên thực hiện các bước sau để chuyển đổi single instance sang Oracle RAC.

  1.  Tạo mới Undo tablespace cho node thứ hai
  2.  Thêm Logfile cho các node thứ hai
  3.  Kích hoạt thread thứ hai.
  4.  Thêm các tham số RAC mới vào file tham số (Pfile)
  5.  Sửa đổi bash profile  và tệp tham số trên hai node.
  6.  Thêm Cơ sở dữ liệu và Instance vào Clusterware, sau đó là khởi động instance
Chi tiết thực hiện như sau:

1. Tạo mới Undo tablespace cho node thứ hai

Bạn nên tạo Undo tablespace  mới cho node thứ hai, bởi vì mỗi Oracle Instance cần Undo tablespace riêng. Bạn có thể tạo Undo tablespace như sau.

create undo tablespace UNDOTBS2 datafile '+DATATEST' size 4096M;


SQL> create undo tablespace UNDOTBS2 datafile '+DATATEST' size 4096M;

Tablespace created.

2. Thêm Logfile cho node thứ hai

Bạn nên thêm logfile mới cho node thứ hai (thread 2), vì mỗi Oracle Instance cần Online log file riêng của nó. Bạn có thể tạo logfile như sau:

alter database add logfile thread 2 group 13 ('+DATATEST') size 50m reuse;


[MSDBA]/home/oracle $ sqlplus / as sysdba

SQL*Plus: Release 19.0.0.0.0 - Production on Sun Nov 1 19:02:24 2020
Version 19.8.0.0.0

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


Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.8.0.0.0

SQL> alter database add logfile thread 2 group 13 ('+DATATEST') size 50m reuse;

Database altered.

SQL> alter database add logfile thread 2 group 14 ('+DATATEST') size 50m reuse;

Database altered.

SQL> alter database add logfile thread 2 group 15 ('+DATATEST') size 50m reuse;

Database altered.

SQL>

3. Kích hoạt Thread thứ hai

Bạn nên kích hoạt thread thứ hai và Instance thứ hai cho cùng một cơ sở dữ liệu Oracle như sau.

SQL> alter database enable public thread 2;

Database altered.

SQL>

Tham số Oracle RAC – cluster_database, instance_number,thread,remote_listener

4. Thêm các tham số RAC mới vào Tệp tham số (Pfile)

Thông thường, nếu bạn đang sử dụng Single Instance, thì tham số cluster_database là False theo mặc định. 

Để chuyển đổi cơ sở dữ liệu Oracle Single sang Oracle RAC và nhiều Instance, bạn cần sử dụng cluster_database=true . 

Và các thông số Cluster khác như bên dưới. Bạn nên thay đổi theo Instance_NAME của mình. Trong ví dụ của chúng tôi, MSDBA là db_name của tôi, vì vậy Instance Name đầu tiên sẽ là MSDBA1 và tên Instance thứ hai sẽ là MSDBA2.

Tạo pfile từ spfile, sau đó thêm các dòng sau vào pfile (tệp tham số) 

SQL> create pfile='/home/oracle/pfileMSDBA.ora' from spfile;

[MSDBA]/home/oracle $ vi pfileMSDBA.ora

 

*.cluster_database=true
*.remote_listener='msdb-scan:1521'
MSDBA1.instance_number=1
MSDBA2.instance_number=2
MSDBA1.thread=1
MSDBA2.thread=2
MSDBA1.undo_tablespace='UNDOTBS1'
MSDBA2.undo_tablespace='UNDOTBS2'

5. Sửa đổi Bash Profile và tệp tham số (pfile) trên hai node

Khi bạn đã thêm các tham số Cluster ở trên, sau đó lưu pfile mới và khởi động Oracle Instance với pfile mới như sau.

[MSDBA]/home/oracle $ sqlplus / as sysdba
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.8.0.0.0

SQL> shu immediate
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> 
SQL> 
[MSDBA]/home/oracle $ vi bash_profile_msdba 
[MSDBA]/home/oracle $ 
[MSDBA]/home/oracle $ 
[MSDBA]/home/oracle $ . bash_profile_msdba 
[MSDBA2]/home/oracle $ 
[MSDBA2]/home/oracle $ 
[MSDBA2]/home/oracle $ sqlplus / as sysdba

SQL*Plus: Release 19.0.0.0.0 - Production on Sun Nov 1 19:08:34 2020
Version 19.8.0.0.0

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

Connected to an idle instance.

SQL> startup nomount pfile=pfileMSDBA.ora
ORACLE instance started.

Total System Global Area 1.0771E+10 bytes
Fixed Size 12446800 bytes
Variable Size 3321888768 bytes
Database Buffers 7348420608 bytes
Redo Buffers 88215552 bytes
SQL>

 Bây giờ tạo spfile từ pfile cho cả Instance (Global Spfile), sau đó bạn có thể khởi động mọi Instance.

SQL> create spfile='+DATATEST/MSDBA/spfileMSDBABA.ora' from pfile='/home/oracle/pfileMSDBA.ora';

File created.

SQL> shu immediate
ORA-01507: database not mounted


ORACLE instance shut down.
SQL> 
SQL> 
SQL> exit
Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.8.0.0.0
[MSDBA2]/home/oracle $

 Thay đổi tên pfile thành tên pfile mới từ initMSDBA.ora thành initMSDBA2.ora.

[MSDBA2]/home/oracle $ cd $ORACLE_HOME
[MSDBA2]/u01/app/oracle/product/19.0.0/dbhome_1/dbs $ mv initMSDBA.ora initMSDBA2.ora
[MSDBA2]/u01/app/oracle/product/19.0.0/dbhome_1/dbs $
[MSDBA2]/u01/app/oracle/product/19.0.0/dbhome_1/dbs $

 Bây giờ hãy xóa các tham số cũ trong tệp tham số (pfile) và chỉ ghi địa chỉ spfile như sau.

spfile='+DATATEST/MSDBA/spfileMSDBA.ora' 

 Thêm các dòng trên vào initMSDBA2.ora và lưu nó lại:

[MSDBA2]/u01/app/oracle/product/19.0.0/dbhome_1/dbs $ vi initMSDBA2.ora
[MSDBA2]/u01/app/oracle/product/19.0.0/dbhome_1/dbs $

 Bây giờ bạn có thể khởi động node thứ hai như sau:

[MSDBA2]/u01/app/oracle/product/19.0.0/dbhome_1/dbs $ 
[MSDBA2]/u01/app/oracle/product/19.0.0/dbhome_1/dbs $ sqlplus / as sysdba

SQL*Plus: Release 19.0.0.0.0 - Production on Sun Nov 1 19:28:12 2020
Version 19.8.0.0.0

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

Connected to an idle instance.

SQL> startup
ORACLE instance started.

Total System Global Area 1.0771E+10 bytes
Fixed Size 12446800 bytes
Variable Size 3321888768 bytes
Database Buffers 7348420608 bytes
Redo Buffers 88215552 bytes
Database mounted.
Database opened.
SQL> exit
Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.8.0.0.0


[MSDBA2]/u01/app/oracle/product/19.0.0/dbhome_1/dbs $

 Chuyển pfile và bash profile sang node đầu tiên.

[MSDBA2]/u01/app/oracle/product/19.0.0/dbhome_1/dbs $ scp initMSDBA2.ora msdbadm01:/u01/app/oracle/product/19.0.0/dbhome_1/dbs/initMSDBA1.ora
initMSDBA2.ora 100% 41 81.1KB/s 00:00 
[MSDBA2]/u01/app/oracle/product/19.0.0/dbhome_1/dbs $ 
[MSDBA2]/u01/app/oracle/product/19.0.0/dbhome_1/dbs $ 
[MSDBA2]/u01/app/oracle/product/19.0.0/dbhome_1/dbs $ cd
[MSDBA2]/home/oracle $ 
[MSDBA2]/home/oracle $ scp bash_profile_msdba msdbadm01:/home/oracle/
bash_profile_msdba 100% 333 742.3KB/s 00:00 
[MSDBA2]/home/oracle $ 
[MSDBA2]/home/oracle $

 Bây giờ, hãy chuyển đến nút đầu tiên và chỉ thay đổi Instance name và tên pfile bằng Instance Name mới.

[MSDBA2]/home/oracle $ ssh msdbadm01

 Đổi tên Oracle Sid từ MSDBA thành MSDBA1 trong bash profile:

[MSDBA]/home/oracle $ vi bash_profile_msdba

 Chạy cấu hình Bash profile mới:

[MSDBA]/home/oracle $ . bash_profile_msdba
[MSDBA1]/home/oracle $
[MSDBA1]/home/oracle $

 Bây giờ bạn cũng có thể khởi động node đầu tiên như sau.

[MSDBA1]/home/oracle $ sqlplus / as sysdba

SQL*Plus: Release 19.0.0.0.0 - Production on Sun Nov 1 19:30:51 2020
Version 19.8.0.0.0

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

Connected to an idle instance.

SQL> startup
ORACLE instance started.

Total System Global Area 1.0771E+10 bytes
Fixed Size 12446800 bytes
Variable Size 3321888768 bytes
Database Buffers 7348420608 bytes
Redo Buffers 88215552 bytes
Database mounted.
Database opened.
SQL> exit
Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.8.0.0.0
[MSDBA1]/home/oracle $

 Bây giờ hai node (instance) đang chạy cho cùng một cơ sở dữ liệu.

Srvctl Add Database | Srvctl add instance

6. Thêm Cơ sở dữ liệu và Instance vào Clusterware, sau đó là khởi động các Instance

Bạn thêm cơ sở dữ liệu và các instance vào Clusterware bằng các lệnh Srvctl như sau.

[MSDBA1]/home/oracle $ srvctl add database -d MSDBA -o /u01/app/oracle/product/19.0.0/dbhome_1
[MSDBA1]/home/oracle $ srvctl add instance -d MSDBA -i MSDBA1 -n msdbadm01
[MSDBA1]/home/oracle $ srvctl add instance -d MSDBA -i MSDBA2 -n msdbadm02
[MSDBA1]/home/oracle $
Srvctl stop database | srvctl start database

Bây giờ bạn có thể thử tắt cả hai instance bằng lệnh srvctl stop database như sau, sau đó bạn có thể khởi động cả hai instance bằng lệnh srvctl start database như sau.

[MSDBA1]/home/oracle $ . bash_profile_msdba
[MSDBA1]/home/oracle $ 
[MSDBA1]/home/oracle $ 
[MSDBA1]/home/oracle $ srvctl stop database -d MSDBA
PRCC-1016 : MSDBA was already stopped
[MSDBA1]/home/oracle $ 
[MSDBA1]/home/oracle $ 
[MSDBA1]/home/oracle $ srvctl start database -d MSDBA 
[MSDBA1]/home/oracle $
Hy vọng hữu ích cho bạn.
=============================
* KHOÁ HỌC ORACLE DATABASE A-Z ENTERPRISE trực tiếp từ tôi giúp bạn bước đầu trở thành những chuyên gia DBA, đủ kinh nghiệm đi thi chứng chỉ OA/OCP, đặc biệt là rất nhiều kinh nghiệm, bí kíp thực chiến trên các hệ thống Core tại VN chỉ sau 1 khoá học.
* CÁCH ĐĂNG KÝ: Gõ (.) hoặc để lại số điện thoại hoặc inbox https://m.me/tranvanbinh.vn hoặc Hotline/Zalo 090.29.12.888
* Chi tiết tham khảo:
https://bit.ly/oaz_w
=============================
KẾT NỐI VỚI CHUYÊN GIA TRẦN VĂN BÌNH:
📧 Mail: binhoracle@gmail.com
☎️ Mobile/Zalo: 0902912888
👨 Facebook: https://www.facebook.com/BinhOracleMaster
👨 Inbox Messenger: https://m.me/101036604657441 (profile)
👨 Fanpage: https://www.facebook.com/tranvanbinh.vn
👨 Inbox Fanpage: https://m.me/tranvanbinh.vn
👨👩 Group FB: https://www.facebook.com/groups/DBAVietNam
👨 Website: https://www.tranvanbinh.vn
👨 Blogger: https://tranvanbinhmaster.blogspot.com
🎬 Youtube: https://www.youtube.com/@binhguru
👨 Tiktok: https://www.tiktok.com/@binhguru
👨 Linkin: https://www.linkedin.com/in/binhoracle
👨 Twitter: https://twitter.com/binhguru
👨 Podcast: https://www.podbean.com/pu/pbblog-eskre-5f82d6
👨 Địa chỉ: Tòa nhà Sun Square - 21 Lê Đức Thọ - Phường Mỹ Đình 1 - Quận Nam Từ Liêm - TP.Hà Nội

=============================
Chuyển đổi Single Instance Oracle Database sang Oracle RAC, oracle tutorial, học oracle database, Tự học Oracle, Tài liệu Oracle 12c tiếng Việt, Hướng dẫn sử dụng Oracle Database, Oracle SQL cơ bản, Oracle SQL là gì, Khóa học Oracle Hà Nội, Học chứng chỉ Oracle ở đầu, Khóa học Oracle online,sql tutorial, khóa học pl/sql tutorial, học dba, học dba ở việt nam, khóa học dba, khóa học dba sql, tài liệu học dba oracle, Khóa học Oracle online, học oracle sql, học oracle ở đâu tphcm, học oracle bắt đầu từ đâu, học oracle ở hà nội, oracle database tutorial, oracle database 12c, oracle database là gì, oracle database 11g, oracle download, oracle database 19c, oracle dba tutorial, oracle tunning, sql tunning , oracle 12c, oracle multitenant, Container Databases (CDB), Pluggable Databases (PDB), oracle cloud, oracle security, oracle fga, audit_trail,oracle RAC, ASM, oracle dataguard, oracle goldengate, mview, oracle exadata, oracle oca, oracle ocp, oracle ocm , oracle weblogic, postgresql tutorial, mysql tutorial, mariadb tutorial, sql server tutorial, nosql, mongodb tutorial, oci, cloud, middleware tutorial, hoc solaris tutorial, hoc linux tutorial, hoc aix tutorial, unix tutorial, securecrt, xshell, mobaxterm, putty

ĐỌC NHIỀU

Trần Văn Bình - Oracle Database Master