Trên Oracle 19c có tính năng hữu ích đó là DML redirection, chúng ta có thể thực thi lệnh DML trên một Standby database, điều này là cần thiết và rất hữu ích trong khi máy chủ Primary có thể tạm thời gặp sự cố mà chúng ta không thể thực hiện được các lệnh DML hoặc là Primary đang bị quá tải hay chúng ta cần thiết san tải sang máy chủ khác.
Logic làm việc của DML redirection như sau:
1) DML thực thi trên Standby
2) DML chuyển hướng tới Primary
3) DML thực thi trên Primary
4) Data thay đổi trên Primary được redo log apply sang Standby
5) Data display tới App hoặc Client
THÔNG TIN CHI TIẾT 2 NODE:
Items | Primary – SRV1 | Standby – SRV2 |
hostname | srv1 | srv2 |
ip | 192.168.1.11 | 192.168.1.12 |
db name | binhdb | binhdb |
instance_name | binhdb | stand |
db_unique_name | binhdb | stand |
version DB | 19.3 | 19.3 |
DB_HOME | /u01/app/oracle/ product/19.3.0/dbhome_1 | /u01/app/oracle/ product/19.3.0/dbhome_1 |
DB_BASE | /u01/app/oracle | /u01/app/oracle |
global database name | srv1.localdomain | srv2.localdomain |
SRV1 – server tôi đặt là Primary
SRV2 – server tôi đặt là Standby
Kiểm tra thông tin database:
Check thông tin 2 DB:
select status,instance_name,database_role,protection_mode from v$database,v$instance;
DB prim:
SQL> select status,instance_name,database_role,protection_mode from v$database,v$instance;
STATUS INSTANCE_NAME DATABASE_ROLE PROTECTION_MODE
———— —————- —————- ——————–
OPEN binhdbPRIMARY MAXIMUM AVAILABILITY
DB standby:
SQL> select status,instance_name,database_role,protection_mode from v$database,v$instance;
STATUS INSTANCE_NAME DATABASE_ROLE PROTECTION_MODE
———— —————- —————- ——————–
OPEN stand PHYSICAL STANDBY MAXIMUM PERFORMANCE
Primary + Standby: Kích hoặc tính năng DML redirection:
show parameter adg_redirect_dml alter system set adg_redirect_dml=true scope=both; show parameter adg_redirect_dml
SQL> show parameter adg_redirect_dml
NAME TYPE VALUE
———————————— ———– ——————————
adg_redirect_dml boolean FALSE
SQL> alter system set adg_redirect_dml=true scope=both;
System altered.
SQL> show parameter adg_redirect_dml
NAME TYPE VALUE
———————————— ———– ——————————
adg_redirect_dml boolean TRUE
Primary + Standby: Test kết quả DML redirection:
Tạo user và table trên Primary, sau đó vào trong Standby kiểm tra xem có dữ liệu chưa, rồi tiến hành xoá data đi => kiểm tra trên Primary xem còn dữ liệu hay không?
Primary:
create table binh_tab (name varchar(20), date_binh date); insert into binh_tab values ('binh binh',sysdate); commit; select * from binh_tab;
SQL> create table binh_tab (name varchar(20), date_binh date);
Table created.
SQL> insert into binh_tab values (‘binh binh’,sysdate);
1 row created.
SQL> commit;
Commit complete.
SQL> select * from binh_tab;
NAME DATE_DUON
——————– ———
binh binh 06-MAY-24
Standby: check dữ liệu vừa tạo bên Primary
Lưu ý: để thực thi được DML trên Standby thì chúng ta phải exit sqlplus và login lại với username/pass chi tiết: sqlplus sys/oracle@stand as sysdba, sử dụng sqlplus / as sysdba sẽ không thực thi được và có lỗi xuất hiện)
exit
sqlplus sys/oracle@stand as sysdba
select status,instance_name,database_role,protection_mode from v$database,v$instance;
SELECT database_role, open_mode FROM v$database;
select * from binh_tab;
delete from binh_tab;
commit;
SQL> exit
Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 – Production
Version 19.3.0.0.0
[oracle@srv2 ~]$ sqlplus sys/oracle@STAND as sysdba
SQL*Plus: Release 19.0.0.0.0 – Production on Mon May 6 16:32:09 2024
Version 19.3.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.3.0.0.0
SQL> select status,instance_name,database_role,protection_mode from v$database,v$instance;
STATUS INSTANCE_NAME DATABASE_ROLE PROTECTION_MODE
———— —————- —————- ——————–
OPEN stand PHYSICAL STANDBY MAXIMUM PERFORMANCE
SQL> SELECT database_role, open_mode FROM v$database;
DATABASE_ROLE OPEN_MODE
—————- ——————–
PHYSICAL STANDBY READ ONLY WITH APPLY
SQL> select * from binh_tab;
NAME DATE_DUON
——————– ———
duong duong 06-MAY-24
SQL> delete from binh_tab;
1 row deleted.
SQL> commit;
Commit complete.
Primary: quay trở lại check xem còn dữ liệu không? => check trên cả 2 node thì data đã không còn nữa sau khi delete rồi.
select * from binh_tab;
SQL> select * from duong_tab;
no rows selected
Chúc các bạn thành công.
Website không chứa bất kỳ quảng cáo nào, mọi đóng góp để duy trì phát triển cho website (donation) xin vui lòng gửi về STK 90.2142.8888 - Ngân hàng Vietcombank Thăng Long - TRAN VAN BINH
=============================
Nếu bạn không muốn bị AI thay thế và tiết kiệm 3-5 NĂM trên con đường trở thành DBA chuyên nghiệp hay làm chủ Database thì hãy đăng ký ngay KHOÁ HỌC ORACLE DATABASE A-Z ENTERPRISE, được Coaching trực tiếp từ tôi với toàn bộ bí kíp thực chiến, thủ tục, quy trình của gần 20 năm kinh nghiệm (mà bạn sẽ KHÔNG THỂ tìm kiếm trên Internet/Google) từ đó giúp bạn dễ dàng quản trị mọi hệ thống Core tại Việt Nam và trên thế giới, đỗ OCP.
- 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
=============================
2 khóa học online qua video giúp bạn nhanh chóng có những kiến thức nền tảng về Linux, Oracle, học mọi nơi, chỉ cần có Internet/4G:
- Oracle cơ bản: https://bit.ly/admin_1200
- Linux: https://bit.ly/linux_1200
=============================
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
=============================
cở sở dữ liệu, cơ sở dữ liệu quốc gia, database, AI, trí tuệ nhân tạo, artificial intelligence, machine learning, deep learning, LLM, ChatGPT, DeepSeek, Grok, 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/21c/23c/23ai, 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, ms sql server tutorial, nosql, mongodb tutorial, oci, cloud, middleware tutorial, docker, k8s, micro service, hoc solaris tutorial, hoc linux tutorial, hoc aix tutorial, unix tutorial, securecrt, xshell, mobaxterm, putty