【MV】實現跨庫可更新物化檢視
物化檢視較為常見的一種用法是,遠端資料庫中存放的基表資料作為本地資料庫的更新資料來源,以便實現多個資料庫與同一個資料來源進行同步。這便是一種資料分發的表現形式。
這裡給出這種實現這種跨庫的可更新的物化檢視的方法。要求在secdb資料庫例項上建立可更新的物化檢視mv_t,物化檢視對應的基表資料存放在另外一套資料庫例項secgc中。
1.首先在secgc資料庫例項上建立基表T
secdb@secdb1 /home/oracle$ export ORACLE_SID=secgc
secgc@secdb1 /home/oracle$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Fri May 20 20:24:43 2011
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> create user user_secgc identified by user_secgc;
User created.
SQL> grant connect,resource to user_secgc;
Grant succeeded.
SQL> conn user_secgc/user_secgc
Connected.
SQL> create table t (x varchar2(10));
Table created.
SQL> insert into t values ('secooler');
1 row created.
SQL> commit;
Commit complete.
SQL> select * from t;
X
----------
secooler
2.在T表所在例項secgc上建立物化檢視日誌
SQL> create materialized view log on t with rowid;
Materialized view log created.
3.在物化檢視所在例項secdb上建立database link
secgc@secdb1 /home/oracle$ export ORACLE_SID=secdb
1)調整global_names引數為FALSE
此步驟是為了防止在使用database link時報ORA-02085錯誤。關於ORA-02085錯誤請參考文章《【DBLINK】“ORA-02085: database link %s connects to %s”故障排查及處理策略兩則》(http://space.itpub.net/519536/viewspace-695851)。
secdb@secdb1 /home/oracle$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Fri May 20 20:31:06 2011
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> show parameter global_names
NAME TYPE VALUE
------------------------------------ ----------- -------------
global_names boolean TRUE
SQL> alter system set global_names=FALSE;
System altered.
SQL> show parameter global_names
NAME TYPE VALUE
------------------------------------ ----------- -------------
global_names boolean FALSE
2)建立連線到secgc例項的database link
(1)在本地secdb例項上建立到secgc例項的連線串
secdb@secdb1 /home/oracle$ vi $ORACLE_HOME/network/admin/tnsnames.ora
SECGC =
(DESCRIPTION =
(address = (protocol = tcp)(host = secdb1)(port = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = secgc)
)
)
(2)建立database link
SQL> create public database link dblink_to_secgc connect to user_secgc identified by user_secgc using 'SECGC';
Database link created.
4.在secdb例項上使用者user_secdb下建立物化檢視
SQL> create user user_secdb identified by user_secdb;
User created.
SQL> grant connect,resource to user_secdb;
Grant succeeded.
SQL> conn user_secdb/user_secdb
Connected.
SQL> create materialized view mv_t refresh fast with rowid as select * from t@dblink_to_secgc;
Materialized view created.
5.對物化檢視進行快速重新整理和完全重新整理
1)快速重新整理方法
SQL> exec dbms_mview.refresh('mv_t','f');
PL/SQL procedure successfully completed.
2)完全重新整理方法
SQL> exec dbms_mview.refresh('mv_t','c');
PL/SQL procedure successfully completed.
6.測試物化檢視重新整理效果
1)在基表T中插入一條資料
secdb@secdb1 /home/oracle$ export ORACLE_SID=secgc
secgc@secdb1 /home/oracle$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Fri May 20 21:09:03 2011
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> conn user_secgc/user_secgc
Connected.
SQL> select * from t;
X
----------
secooler
SQL> insert into t values ('Andy');
1 row created.
SQL> commit;
Commit complete.
SQL> select * from t;
X
----------
secooler
Andy
2)對物化檢視進行快速重新整理(或完全重新整理)前資料
SQL> select * from mv_t;
X
----------
secooler
3)對物化檢視進行快速重新整理(或完全重新整理)後資料
SQL> exec dbms_mview.refresh('mv_t','f');
PL/SQL procedure successfully completed.
SQL> select * from mv_t;
X
----------
secooler
Andy
物化檢視建立成功。
7.小結
透過一系列配置,我們便實現了跨庫可更新物化檢視。這裡我們使用Database Link技術達到了“跨庫”這個目的。
Good luck.
secooler
11.05.20
-- The End --
這裡給出這種實現這種跨庫的可更新的物化檢視的方法。要求在secdb資料庫例項上建立可更新的物化檢視mv_t,物化檢視對應的基表資料存放在另外一套資料庫例項secgc中。
1.首先在secgc資料庫例項上建立基表T
secdb@secdb1 /home/oracle$ export ORACLE_SID=secgc
secgc@secdb1 /home/oracle$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Fri May 20 20:24:43 2011
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> create user user_secgc identified by user_secgc;
User created.
SQL> grant connect,resource to user_secgc;
Grant succeeded.
SQL> conn user_secgc/user_secgc
Connected.
SQL> create table t (x varchar2(10));
Table created.
SQL> insert into t values ('secooler');
1 row created.
SQL> commit;
Commit complete.
SQL> select * from t;
X
----------
secooler
2.在T表所在例項secgc上建立物化檢視日誌
SQL> create materialized view log on t with rowid;
Materialized view log created.
3.在物化檢視所在例項secdb上建立database link
secgc@secdb1 /home/oracle$ export ORACLE_SID=secdb
1)調整global_names引數為FALSE
此步驟是為了防止在使用database link時報ORA-02085錯誤。關於ORA-02085錯誤請參考文章《【DBLINK】“ORA-02085: database link %s connects to %s”故障排查及處理策略兩則》(http://space.itpub.net/519536/viewspace-695851)。
secdb@secdb1 /home/oracle$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Fri May 20 20:31:06 2011
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> show parameter global_names
NAME TYPE VALUE
------------------------------------ ----------- -------------
global_names boolean TRUE
SQL> alter system set global_names=FALSE;
System altered.
SQL> show parameter global_names
NAME TYPE VALUE
------------------------------------ ----------- -------------
global_names boolean FALSE
2)建立連線到secgc例項的database link
(1)在本地secdb例項上建立到secgc例項的連線串
secdb@secdb1 /home/oracle$ vi $ORACLE_HOME/network/admin/tnsnames.ora
SECGC =
(DESCRIPTION =
(address = (protocol = tcp)(host = secdb1)(port = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = secgc)
)
)
(2)建立database link
SQL> create public database link dblink_to_secgc connect to user_secgc identified by user_secgc using 'SECGC';
Database link created.
4.在secdb例項上使用者user_secdb下建立物化檢視
SQL> create user user_secdb identified by user_secdb;
User created.
SQL> grant connect,resource to user_secdb;
Grant succeeded.
SQL> conn user_secdb/user_secdb
Connected.
SQL> create materialized view mv_t refresh fast with rowid as select * from t@dblink_to_secgc;
Materialized view created.
5.對物化檢視進行快速重新整理和完全重新整理
1)快速重新整理方法
SQL> exec dbms_mview.refresh('mv_t','f');
PL/SQL procedure successfully completed.
2)完全重新整理方法
SQL> exec dbms_mview.refresh('mv_t','c');
PL/SQL procedure successfully completed.
6.測試物化檢視重新整理效果
1)在基表T中插入一條資料
secdb@secdb1 /home/oracle$ export ORACLE_SID=secgc
secgc@secdb1 /home/oracle$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Fri May 20 21:09:03 2011
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> conn user_secgc/user_secgc
Connected.
SQL> select * from t;
X
----------
secooler
SQL> insert into t values ('Andy');
1 row created.
SQL> commit;
Commit complete.
SQL> select * from t;
X
----------
secooler
Andy
2)對物化檢視進行快速重新整理(或完全重新整理)前資料
SQL> select * from mv_t;
X
----------
secooler
3)對物化檢視進行快速重新整理(或完全重新整理)後資料
SQL> exec dbms_mview.refresh('mv_t','f');
PL/SQL procedure successfully completed.
SQL> select * from mv_t;
X
----------
secooler
Andy
物化檢視建立成功。
7.小結
透過一系列配置,我們便實現了跨庫可更新物化檢視。這裡我們使用Database Link技術達到了“跨庫”這個目的。
Good luck.
secooler
11.05.20
-- The End --
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/519536/viewspace-695888/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 實現跨庫可更新物化檢視
- Oracle物化檢視3 - Prebuilt MVOracleUI
- 建立物化檢視MV ( Materialized View )ZedView
- 【MV】物化檢視查詢重寫
- MV (Materialed View) 物化檢視的重新整理組View
- 物化檢視基礎概念、mview跨庫遷移表View
- 物化檢視實現資料庫倉庫主從複製(1)資料庫
- 物化檢視實現資料庫倉庫主從複製(2)資料庫
- 汽車之家基於 Apache Flink 的跨資料庫實時物化檢視探索Apache資料庫
- 資料庫的物化檢視資料庫
- 物化檢視妙用__表同步使用物化檢視方法
- 【物化檢視】幾種物化檢視日誌分析
- 【物化檢視】根據物化檢視日誌快速重新整理物化檢視的過程
- oracle物化檢視Oracle
- 【MV】group by查詢子句是否包含count(*)對物化檢視重新整理的影響
- [zt]prebuilt 物化檢視遷移資料庫UI資料庫
- 物化檢視詳解
- oracle 建立物化檢視Oracle
- Oracle 物化檢視建立Oracle
- materialized view (物化檢視)ZedView
- 物化檢視 on commitMIT
- 物化檢視日誌表被DROP後建立物化檢視報錯
- DB2資料庫物化檢視:MQT物化查詢表的使用DB2資料庫MQQT
- Oracle如何根據物化檢視日誌快速重新整理物化檢視Oracle
- 物化檢視的快速重新整理測試與物化檢視日誌
- Oracle資料庫中物化檢視的原理剖析Oracle資料庫
- 普通檢視和物化檢視的區別
- calcite物化檢視詳解
- Oracle物化檢視詳解Oracle
- ORACLE物化檢視測試Oracle
- Oracle 物化檢視案例分享Oracle
- 物化檢視梳理總結
- ZT 物化檢視詳解
- Oracle物化檢視語法Oracle
- ORACLE物化檢視入門Oracle
- 物化檢視-學習篇
- 刷物化檢視並行並行
- oracle物化檢視系列(二)Oracle