Updatable materialized view
Can someone help with this scenario:
Say I have a master site 1 that has two tables T1A and T1B. I would like to have these tables viewable and updatable on another site 2. Site 1 is on a ship and site 2 is on a shore. Site2 will have access to Site 1 on port 1521.
I have read some on "materialized view" but I'm still not clear how to push the updates made on Site 2 back to Site1.
Can someone provide sample scripts to make replication happens between the two sites?
Thank you.
hi,
try goin thru this online documentation by oracle for details =>
http://download-west.oracle.com/docs/cd/B14117_01/server.101/b10732/toc.htm
and for step by step setup of an updatable MV replication =>
http://download-west.oracle.com/docs/cd/B14117_01/server.101/b10733/toc.htm
Similar Messages
-
Updatable Materialized View and Master Table on same database
Hi all,
My first question - Is it possible to have an Updatable Materialized View and the associated Master Table located on the same database?
This is the requirement scenario:
One unique database D exists.
A is a batch table. Only inserts are allowed on Table A.
M is an updatable materialized view on Table A (Master). Only updates are allowed on M (no insert or delete).
Requirement is to push updates/changes from M to A periodically and then get the new inserted records from A into M via a refresh.
Is this possible? What other approaches are applicable here?John,
My question is related to the implementation and setup of the environment as explained in the above example. How can I achieve this considering that I have created an updatable m-view?
If possible, how do I push changes made to an updatable m-view back to it's master table when/before I execute DBMS_MVIEW.REFRESH on the m-view? What is the procedure to do this if both table and mview exist on the same database? Do I need to create master groups, materialized view refresh groups, etc.?
One more thing.. Is there a way to retain changes to the m-view during refresh? In this case, only newly inserted/updated records in the associated table would get inserted into m-view. Whereas changes made to m-view records would stay as-is.
Hope my question is directed well. Thanks for your help.
- Ankit -
Scheduling updatable materialized view
Hi everybody,
As you may know I have a solution in which I have 5 sites .One master site with 4 updatable materialized view sites.
I want to know that is it correct if I dont set up schedule push to run periodically and set it up to do continuous push ?
I want in at least 2 minutes all sites become update and I have to mention that at first I tried multimaster but our client doesn't want that because they want if one special site becomes unavailable they others can not transfer data to eachother.
I appreciate your help in advance.Your requirements are a bit unclear...
1) In general, if you are looking to have sites updated within a minute or two of the original transaction being committed, you are better off looking at something like Streams rather than using materialized views.
2) Architecturally, when you set up multi-master replication (which it sounds like you are attempting to do here), you need to choose between synchronous and asynchronous replication. Synchronous replication means that a transaction cannot commit until it has been pushed to all the other nodes, which is great for latency but horrible for performance, scalability, and availability. Very, very few people really want synchronous replication. That leaves asynchronous replication, which would require you to schedule jobs to replicate changes. Some folks who think they want asnychronous replication really want another technology entirely (i.e. DataGuard, RAC, etc).
3) Are you sure about the requirement "they want if one special site becomes unavailable they others can not transfer data to each other"? That says that if one site fails, they want all transactions everywhere to fail. That pretty much defeats the purpose of setting up multi-master replication. If the system is only available as long as every node is available, and you're going to incur the overhead of synchronous replication on every change, you would be far better served consolidating everything into a single data center and potentially using RAC to create a multi-node cluster to spread the work among nodes. There would be very little benefit to offset the complexity of configuring and maintaining a multi-master replication environment if you didn't want the nodes to be able to continue in the event that one of them failed.
Justin -
Updatable materialized view- error with CREATE_SNAPSHOT_REPGROUP
I'm trying to create an updatable materialized view from the replication administrators account (REPADMIN). I use the assistant and in the third step (after creating the replication group and the materialized view), when the materialized view is going to be added to the group, I got this error:
ERROR in line 1:
ORA-01403: No data found
ORA-06512: in "SYS.DBMS_REPCAT_SNA_UTL", line 5927
ORA-06512: in "SYS.DBMS_REPCAT_SNA", line 82
ORA-06512: in "SYS.DBMS_REPCAT", line 1332
ORA-06512: in "SYS.DBMS_REPCAT", line 1307
ORA-06512: in line 2
I have also tried to use the command file that the assistant generates (I add below), and the error is triggered within the CREATE_SNAPSHOT_REPOBJECT procedure.
Has anybody any idea to resolve the problem?
Thanks in advance
BEGIN
DBMS_REPCAT.CREATE_SNAPSHOT_REPGROUP(
gname => '"MYGROUP"',
master => 'DB.DOMAIN.COM',
propagation_mode => 'ASYNCHRONOUS');
END;
CREATE SNAPSHOT "MYUSER"."MYTABLE"
REFRESH COMPLETE WITH ROWID
FOR UPDATE
AS SELECT "COD", "NAME" FROM
"MYUSER"."MYTABLE"@DB.DOMAIN.COM c
BEGIN
DBMS_REFRESH.ADD(
name => '"MYUSER"."REF3"',
list => '"MYUSER"."MYTABLE"',
lax => TRUE);
END;
BEGIN
DBMS_REPCAT.CREATE_SNAPSHOT_REPOBJECT(
gname => '"MYGROUP"',
sname => '"MYUSER"',
oname => '"MYTABLE"',
type => 'SNAPSHOT',
min_communication => FALSE);
END;Hello,
These days I have had some problems with my forum-account and I haven't been able to connect and reply.
Regarding to your doubt, the name of refresh group was correct, and as I see, the problem can't be related to the refresh group.
While the problem with my account was resolved, I created two new databases (*) and the problem within the materialized view process is disappeared. I suppose that my first original databases were degraded, but I don't know where.
(*) of course, I could do that because I use Oracle in an academy institution, not for production, thank God
Anyway, for now I will give up here. Thanks for your help.
Regards, -
Updatable materialized views.
Hi ,
I am using sqlplus.
Please can anyone share a simple example to update a base table using a updatable materialized view.
Thanksusera :- Contains the base table tab1.
userb:- Contains the materialized view
materialized view create query in userb:-
CREATE MATERIALIZED VIEW MV_UPDATETAB1
REFRESH on demand
FOR UPDATE
AS
SELECT * FROMĀ USERA.TAB1
MView created.
Tab1 has 4 rows existing.
I added one more row to the mview.
select * from mview shows 5 rows. (base table 4 rows)
Then I refreshed the mview :-
exec DBMS_MVIEW.REFRESH('mv_updatetab1','c')
successfully executed.
Base table still has 4 rows.
The mview alos has 4 rows and the newly added is not present in the table and mview either.
Any thoughts and suggestions -
Oracle Streams vs. Updatable Materialized View
Does anyone have an idea in which cases Oracle Streams is better than Updatable MV or visa verse?
Are you really talking about Updatable Materialized Views? Or multi-master replication? Personally, I'm rather hard-pressed to come up with a situation where updatable materialized views would be useful unless you're taking the next step and doing multi-master replication.
In general, Streams is going to put less load on the source system than materialized views and is going to replicate data more quickly. The downside tends to be that it's a relatively new technology, so it's not appropriate for environments that have older versions of Oracle. Going along with that, you'll find a lot more people/ organizations/ setups using materialized views than Streams, which can be a good thing if you need to hire new staff/ get support from a local user group/ etc. Streams also tends to be more flexible, which can be a good thing, but also tends to make things a bit more complicated.
If you can outline the particular problem you're trying to solve, we can probably be a lot more specific...
Justin -
Updatable Materialized View with Union ALL
(please don't ask about db structure)
DB: 11gR2
create table table_1 (
id number primary key,
val varchar2(100)
create table table_2 (
id number primary key,
val varchar2(100)
insert into table_1(id) values (0);
insert into table_1(id) values (2);
insert into table_1(id) values (3);
insert into table_1(id) values (4);
insert into table_1(id) values (5);
insert into table_2(id) values (10);
insert into table_2(id) values (12);
insert into table_2(id) values (13);
insert into table_2(id) values (14);
insert into table_2(id) values (15);
update table_1 set val='Table1 val:'||id;
update table_2 set val='Table2 val:'||id;
create view v_table_all as
select * from table_1
view V_TABLE_ALL created.
select * from v_table_all;
ID VAL
0 Table1 val:0
2 Table1 val:2
3 Table1 val:3
4 Table1 val:4
5 Table1 val:5
select column_name, updatable, insertable, deletable
from user_updatable_columns
where table_name = 'V_TABLE_ALL'
COLUMN_NAME UPDATABLE INSERTABLE DELETABLE
ID YES YES YES
VAL YES YES YES
update v_table_all set val='XXX changed' where id = 3;
1 row updated.
select * from table_1;
ID VAL
0 Table1 val:0
2 Table1 val:2
3 XXX changed
4 Table1 val:4
5 Table1 val:5
rollback;
select * from table_1;
ID VAL
0 Table1 val:0
2 Table1 val:2
3 Table1 val:3
4 Table1 val:4
5 Table1 val:5
create or replace view v_table_all as
select * from table_1
union select * from table_2;
view V_TABLE_ALL created.
select * from v_table_all;
ID VAL
0 Table1 val:0
2 Table1 val:2
3 Table1 val:3
4 Table1 val:4
5 Table1 val:5
10 Table2 val:10
12 Table2 val:12
13 Table2 val:13
14 Table2 val:14
15 Table2 val:15
select column_name, updatable, insertable, deletable
from user_updatable_columns
where table_name = 'V_TABLE_ALL'
COLUMN_NAME UPDATABLE INSERTABLE DELETABLE
ID NO NO NO
VAL NO NO NO
trying update:
update v_table_all set val='XXX changed' where id = 3;
SQL-Fehler: ORA-01732: Datenmanipulationsoperation auf dieser View nicht zulässig
01732. 00000 - "data manipulation operation not legal on this view"
*Cause:
*Action:
drop view v_table_all;
view V_TABLE_ALL dropped.all is ok before this point.
now we want create a new materialized view with some query
create materialized view v_table_all
as
select * from table_1
union all select * from table_2 ;
materialized view V_TABLE_ALL created.
select column_name, updatable, insertable, deletable
from user_updatable_columns
where table_name = 'V_TABLE_ALL'
COLUMN_NAME UPDATABLE INSERTABLE DELETABLE
ID YES YES YES
VAL YES YES YES it seems to be ok with update.
but...
update v_table_all set val='XXX changed' where id = 3;
SQL-Fehler: ORA-01732: Datenmanipulationsoperation auf dieser View nicht zulässig
01732. 00000 - "data manipulation operation not legal on this view"
*Cause:
*Action:How can solve this issue??
Any suggestionLooks like user_updatable_columns sort of thinks the MV is just a table - I don't know about that...
An MV on a single table can be updated - I tried that and it works:
create materialized view mv_table_1 for update
as
select * from table_1;I noticed [url http://download.oracle.com/docs/cd/E11882_01/server.112/e16579/advmv.htm#sthref294]examples stating the UNION ALL needs a "marker" so Oracle can know from the data which source table a row in the MV originates from - like this:
create materialized view v_table_all for update
as
select 'T1' tab_id, table_1.* from table_1
union all
select 'T2' tab_id, table_2.* from table_2 ;But that also fails (the "marker" requirement was specifically for FAST REFRESH, so it was just a long shot ;-) )
What are you planning to do?
<li>Create the MV.
<li>Update records in the MV - which then is no longer consistent with the source data.
<li>Schedule a complete refresh once in a while - thereby overwriting/losing the updates in the MV.
If that is the case, I suggest using a true table rather than an MV.
<li>Create table t_table_all as select ... .
<li>Update records in the table - which then is no longer consistent with the source data.
<li>Schedule a job to delete table and insert into table select ... once in a while - thereby overwriting/losing the updates in the table.
In other words a kind of "do it yourself MV".
I cannot see another way at the moment? But perhaps try in the data warehousing forum - the people there may have greater experience with MV's ;-) -
Hi,
I am running a database on 10.2g version. I am new to Oracle Databases/SQL, so I need to know the possibility of updating the materialized views through a scheduler? Can I find any link where all the steps are described in order to update/refresh the materialized views (probably on a daily basis or on a weekly basis)? Any help would be appreciated.
Thanks,
VipulShort answer: MVs can be refreshed automatically as specified at creation time (in this case this is handled internally by a DBMS_JOB job) or on demand: in this case you can try to use DBMS_SCHEDULER to create and schedule a job to call DBMS_MVIEW.REFRESH.
Long answer: http://download.oracle.com/docs/cd/B19306_01/server.102/b14223/refresh.htm#sthref826 -
Database replication with updatable materialized view in oracle 10gR2
I neet to set up 1 central server and two local databases ....the local database will hold materialized view....now how to replicate data...in this scenario...please help as soon as possible...i am in rush.....
the database i use is oracle 10g Release 2
Edited by: user9932019 on Sep 4, 2009 2:25 AMIt's not a process that can be explained in a forums posting. You have to understand the steps.
Here are some other examples :
http://www.orafaq.com/wiki/Scripts#Oracle_Advanced_Replication_Scripts -
Updatable materialized view site - replication
Hi all,
I have a shared instance database (with multiple schemas) hosting different applications for different customers. I'm now going to move out one of the application - the materialized view site to another database in new server. (as per request by customer to another data center) by using schema level import/export. The master site will remain untouched.
As i'm rather new in replication, I would like your advise in which data dictionary tables where I can find which are the schemas having the below privileges. As this is a legacy database handed over to us long back, i need to dig out all the info to plan for the migratiion. I need to identify which schema is taking part in the snapshot replication in the mview site as there are 20 over schemas in the database. Can anyone advise me? Kindly provide addtional info if u think it helps.
grant_admin_any_schema
privilege_type => 'proxy_snapadmin'
privilege_type => 'receiver'
privilege_type => 'propagator'
thanksdba_sys_privs
-
Updatable Materialized View Example
Hello,
I am using Oracle 11.2.0.1 on Windows OS. I am looking an example of updatable MV something like this :
Table1
id
col1
col2
col3
col4
Table2
id
col2
col3
Table3
id
c1
c4
c5
I need an updatable MV which joins all these 3 tables based upon ID column something like this :
id,table1.col2,table1.col4,table2.col3,table3.c4,table3.c5
id,mvcol1,mvcol2,mvcol3,mvcol4,mvcol5
and if user says :
update MV set mvcol2=somevalue, it should also be updated in the parent table(s). Is it possible please?
if user says :
insert into mv values (....), new rows should be in the parent table, and if user says delete mv where id=some value, then all rows from parent table should be deleted.
Thanks.user12050217 wrote:
Hello,
I am using Oracle 11.2.0.1 on Windows OS. I am looking an example of updatable MV something like this :
Table1
id
col1
col2
col3
col4
Table2
id
col2
col3
Table3
id
c1
c4
c5
I need an updatable MV which joins all these 3 tables based upon ID column something like this :
id,table1.col2,table1.col4,table2.col3,table3.c4,table3.c5
id,mvcol1,mvcol2,mvcol3,mvcol4,mvcol5
and if user says :
update MV set mvcol2=somevalue, it should also be updated in the parent table(s). Is it possible please?
if user says :
insert into mv values (....), new rows should be in the parent table, and if user says delete mv where id=some value, then all rows from parent table should be deleted.
Thanks.You can create a writable or updateable MV by using the FOR UPDATE clause when you create it - but changes will not be replicated back to the source table(s). It is up to the developer to figure out how to do this. One way to do this is to manually update the source items along with the MV. Another possibility is to use triggers to copy the changes back to the source table. -
Problem with Materialized Views in 10g
Hi All,
I am creating a Materialized View like
CREATE MATERIALIZED VIEW mvname TABLESPACE SYSTEM BUILD IMMEDIATE REFRESH WITH ROWID FOR UPDATE AS ( SELECT a,b,c FROM table_a,table_b,table_c WHERE cond );
I am getting an error
SQL Error: ORA-12013: updatable materialized views must be simple enough to do fast refresh.
Can anyone tell what is the problem?
I have included rowid of all three tables in select clause.Hi,
From Oracle Docs:
ORA-12013: updatable materialized views must be simple enough to do fast refresh
Cause: The updatable materialized view query contained a join, subquery, union, connect by, order by, or group by caluse.
Action: Make the materialized view simpler. If a join is really needed, make multiple simple materialized views then put a view on top of them.
Regards
K.Rajkumar -
Constratints in materialized view
hi everybody,
after I created materialized view I find out that it inherited primary key constraint directly from the base table in master site.
But it didn't inherit foreign key and unique key constraint from the base table .Should I make them my self,how?Is there any method that when we create
created materialized these 2 kinds of constraint also create automatically from base table as well?
Thank you for your concern.thanks for your response.
I have 2 table test1 and test2 and an index on my test2 foreign key in my master site.These 3 are in my master group named hr_repg
create table test1(test1_id number not null,
test1_name varchar2(10) ,
constraint test1_pk primary key(test1_id)
create table test2(test2_id number not null,
test1_id number not null,
test2_name varchar2(10) ,
constraint test2_pk primary key(test2_id),
constraint test2_fk foreign key (test1_id) references test1(test1_id),
constraint test2_unique unique(test2_name) )
CREATE INDEX FK_test2
ON test2 (test1_id)
TABLESPACE USERS
I want to replicate these 2 tables to the materialized view site i wrote the below script in the materialized view site:
BEGIN
DBMS_REPCAT.CREATE_MVIEW_REPGROUP (
gname => 'hr_repg',
master => 'orc1.world',
propagation_mode => 'ASYNCHRONOUS');
END;
BEGIN
DBMS_REFRESH.MAKE (
name => 'mviewadmin.hr_refg',
list => '',
next_date => SYSDATE,
interval => 'SYSDATE + 1/1440',
implicit_destroy => FALSE,
rollback_seg => '',
push_deferred_rpc => TRUE,
refresh_after_errors => FALSE);
END;
CREATE MATERIALIZED VIEW hr.test1
REFRESH FAST WITH PRIMARY KEY FOR UPDATE
AS SELECT * FROM [email protected]
CREATE MATERIALIZED VIEW hr.test2
REFRESH FAST WITH PRIMARY KEY FOR UPDATE
AS SELECT * FROM [email protected]
BEGIN
DBMS_REPCAT.CREATE_MVIEW_REPOBJECT (
gname => 'hr_repg',
sname => 'hr',
oname => 'test1',
type => 'snapshot',
min_communication => TRUE);
END;
BEGIN
DBMS_REPCAT.CREATE_MVIEW_REPOBJECT (
gname => 'hr_repg',
sname => 'hr',
oname => 'test2',
type => 'snapshot',
min_communication => TRUE);
END;
BEGIN
DBMS_REPCAT.CREATE_MVIEW_REPOBJECT (
gname => 'hr_repg',
sname => 'hr',
oname => 'FK_test2',
type => 'index',
min_communication => TRUE);
END;
As you see table test2 in my master site has a primary key ,_unique constraint_ and also foreign key constraint.
But after i ran above scripts in materialized view site and checked table test2 in there unique constraint and also foreign key constraint have not been created on table test2.
so when i insert a row in the updatable materialized view it does not check unique constraint and referential integrity of test2.
Is there any idea why they have not been created?because link http://download.oracle.com/docs/cd/B19306_01/server.102/b14226/repmaster.htm#i38780
said
"Any index that is used to enforce a constraint in a table is automatically created at the remote destination sites when a table is selected for replication and created at the remote site"
So I can not understand why these 2 have not been created
Should I make them manually?
Thanks -
DML operations on Materialized view
Hi,
I want to know can we perform DML operations like insert/update on a materialized view?
Thanks
DeepakThanks Michaels. I'm able to update/insert into materialized view.
But I'm having another problem.
My materialized view is selecting rows on group by condition, but to create a MV as updatable, it should be simple.
SQL> create materialized view mv_utr_Link
2 build immediate
3 refresh force on demand
4 for update
5 enable query rewrite
6 as
7 select link_id,booking_date
8 from t_utr
9 where link_id=246229
10 group by link_id,booking_date
11 /
from t_utr
ERROR at line 8:
ORA-12013: updatable materialized views must be simple enough to do fast
refresh
If I remove the group by clause, its allowing me to create MV, but that won't solve my problem.
any workaround on that?
Thanks
Deepak -
Hi all,
I am reading about materialized view from 9i documentation. In this it is mentioned that for updatable materialized views one needs to have updatable materialized view log, but it is not given the log has to be created by us like the materialized view log used for fast refresh or is it automatically created. Also in types of materialized view I can see primary key materialized view and row id materialized view and in materialized view log creation I can see that two type of log creation is possible, one is primary kep MV log and rowid MV log. If mmy understanding is correct then Primary key MV can have only primary key log created. Am I right? One more fact is that one cant import MV from one schema to other by mentioning fromuser to user parameter in 9i, but when I tried doing it in 11g it got imported fine. So is it a new feature too?
Thanks
Kris.When you create a materialized view you should be able to set the refresh interval. Using that, you can refresh the M view based on your needs. Below example has the sytanx:
CREATE MATERIALIZED VIEW mv_emp_pk
REFRESH FAST START WITH SYSDATE
NEXT SYSDATE + 1/48
WITH PRIMARY KEY
AS SELECT * FROM emp@remote_db;
Maybe you are looking for
-
How to determine the creation date/time for a file?
The important operating systems maintain both a creation date/time and last modified date/time for files. But in the File class there is only a lastModified() method. How does one determine the creation date/time for a file?
-
Cloud service with iTunes - how does it work?
May I use "cloud" service to storage my podcasts? (http://selectel.ru/services/cloud-storage/) iTunes doesn't see the link (Bad http error 502)
-
Process to find out tables & functional module
Hi, I would like to know the process to find out tables for configured objects not the master data objects and also the process for finding a functional module for particular application like action. regards Srinath
-
Hi Is it right place to ask regarding oracle spacial data replication using goldengate? I posted message goldengate thread but now one is replying to that...
-
Problem regarding updation of Z-table through maintenance view
hi , I m facing problem in updation of Z-table through maintenance view (SM30). The scenario is that I have one customizing field in my Z-table which is checkbox. Now I need to populate 2 fields in Z-table on tick of this checkbox and clicking of SAV