Data replication between Oracle and Postgres - oracle

Is there a way to replicate data(like triggers or jobs) from oracle tables to postgres tables and vice versa(for different set of tables) without using external tools? Just one way replication for both the scenarios.

Just a hint:
You can think of create a DB link from Oracle to Postgres which is called heterogeneous connectivity which makes it possible to select data from Postgres with a select statement in Oracle.
Then use materialized views to schedule and store the results of those selects.
As you don't want to use any external tool otherwise the solution should have been much simpler

for 20 tables I need to replicate data from oracle to postgres. For 40 different tables, I need to replicate from postgres to oracle.
I could imagine the following setup:
For the Oracles tables that need to be accessible from Postgres, simply create foreign tables inside the Postgres server. They appear to be "local" tables in the Postgres server, but the FDW ("foreign data wrapper") will forward any request to the Oracle server. So no replication required. Whether or not this will be fast enough depends on how you access the tables. Some operations (WHERE clause, ORDER BY etc) can be pushed down to the Oracle server, some will be done by the Postgres server after all the rows have been fechted.
For the Postgres tables that need to be replicated to Oracle you could have a similar setup: create a foreign table that points to the target table in Oracle. Then create triggers on the Postgres table that will update the foreign table, thus sending the changes to Oracle.
This could all be managed on the Postgres side.

Related

Ora2Pg - copy selected partition data for a specific table

I need to migrate the Oracle database to PostgreSQL.
tables in Oracle are partitioned. I need to migrate data from a partial list of partitions of specific tables.
Is this supported by Ora2Pg?
Thanks.

oracle synchronize 2 tables

I have the following scenario and need to solve it in ORACLE:
Table A is on a DB-server
Table B is on a different server
Table A will be populated with data.
Whenever something is inserted to Table A, i want to copy it to Table B.
Table B nearly has similar columns, but sometimes I just want to get
the content from 2 columns from tableA and concatenate it and save it to
Table B.
I am not very familiar with ORACLE, but after researching on GOOGLE
some say that you can do it with TRIGGERS or VIEWS, how would you do it?
So in general, there is a table which will be populated and its content
should be copien to a different table.
This is the solution I came up so far
create public database link
other_db
connect to
user
identified by
pw
using 'tns-entry';
CREATE TRIGGER modify_remote_my_table
AFTER INSERT ON my_table
BEGIN INSERT INTO ....?
END;
/
How can I select the latest row that was inserted?
If the databases of these two tables are in two different servers, then you will need a database link (db-link) to be created in Table A schema so that it can access(read/write) the Table B data using db-link.
Step 1: Create a database link in Table A server db pointing to Table B server DB
Step 2: Create a trigger for Table A, which helps in inserting data to the table B using database link. You can customize ( concatenate the values) inside the trigger before inserting it into table B.
This link should help you
http://searchoracle.techtarget.com/tip/How-to-create-a-database-link-in-Oracle
Yes you can do this with triggers. But there may be a few disadvantages.
What if database B is not available? -> Exception handling in you trigger.
What if database B was not available for 2h? You inserted data into database A which is now missing in database B. -> Do crazy things with temporarily inserting it into a cache table in database A.
Performance. Well, the performance for inserting a lot of data will be ugly. Each time you insert data, Oracle will start the PL/SQL engine to insert the data into the remote database.
Maybe you could think about using MViews (Materialized Views) to replicate the data via database link. Later you can build your queries so that they access tables from database B and add the required data from database A by joining the MViews.
You can also use fast refresh to replicate the data (almost) realtime.
From perspective of an Oracle Database Admin this would make a lot more sense than the trigger approach.
try this code
database links are considered rather insecure and oracle own options are having licences associated these days, some of the other options are deprecated as well.
https://gist.github.com/anonymous/e3051239ba401e416565cdd912e0de8c
uses ora_rowscn to sync tables across two different oracle databases.

Cache table on one side of datalink in Oracle

I would like to create a cached copy of a table via dblink in oracle. The story is the following:
I have two tables (employee, work) which are joined via a third table (emloyee_work) in a remote database. The reason for that is to decouple the connection between the two entities so that they are not able to be connected directly.
To handle the data easily we have a view that connects the tables via the join table. One can argue that this is the same as having the join table in the same database as the other two but that in not the point right now.
On a new site, the db link latency is very high which causes a major drop in performance since for every select the view is built and a select is executed for each employee through the db link.
The structure has relative high read count and low write count.
The question is whether there is a possibility to "mirror" or copy the remote join table to the local database? This copy should be temporary and should not be persisted.
This way the view would be executed on the local copy.
EDIT: Oracle version is 11gR2
You could use refreshed on demand materialized views.
See also this link where they talk about implementing a materialized view over a dblink.
Since you are using Oracle 11g, you may create an ad-hoc, RAM-based Materialized View.

Oracle Trigger that will update tables in a different DSN

During update or insert on 1 table, is there a way to update a table that is on a different DSN? I want to interface 2 systems that are using different databases and would like to have a trigger that could do such updates. Thanks.
You can create a database link from one Oracle database to the other one. This gives you access to reference remote tables from within your trigger.
This solution has a the merits of simplicity but is not the most efficient (consider bulk updates) or robust (consider downtime of the remote database).
Oracle Replication is a full-on solution that allows you to trade-off consistency, availability , performance, etc.

Possible to link to another database link?

We have an existing database link in an Oracle database that links to data in a Sql Server database. Now, a 2nd Oracle database needs to use that same data. Due to security setup, the 2nd Oracle database cannot "see" the Sql Server database, but it can see the 1st Oracle database.
If we create a database link in the 2nd Oracle database that points to the 1st Oracle database, will we be able to query data from the Sql Server database in the 2nd Oracle database by going through 2 database links? Would the query syntax look like this:
SELECT * FROM myTable#2ndLink#1stLink
Has anyone done something like this before?
Vincent's solution will work, and another solution is to create a synonym instead of a view.
DB1:
CREATE SYNONYM X FOR MyTable#sqlServerDB
DB2:
(assumes db link to DB1 connects as owner of synonym)
SELECT * from X#DB1
I'm not sure this synthax would work (although it would be interesting to test it I can not do it right now). However, even if it doesn't work, you can still create a view in Database 1 that points to a table in your SQL Server Database. From Database 2, you could then query:
SELECT * FROM myView#db1
That would point to the correct table.

Resources