I need to replicate a table from an external db to an internal db for performance reasons. Several apps will use this local db to do joins and compare data. I only need to replicate every hour or so but if there is a performance solution, I would prefer to replicate every 5 to 10 minutes.
What would be the best way to replicate? The first thing that comes to mind is DROP and then CREATE:
DROP TABLE clonedTable;
CREATE TABLE clonedTable AS SELECT * from foo.extern@data.sourceTable;
There has to be a better way right? Hopefully an atomic solution to avoid the fraction of a second where the table doesn’t exist but someone might try to query it.
The simplest possible solution would be a materialized view that is set to refresh every hour.
This will delete all the data currently in
mv_cloned_table, insert all the data from the table in the external database, and then schedule itself to run again an hour after it finishes (so it will actually be 1 hour + however long it takes to refresh between refreshes).There are lots of ways to optimize this.
TRUNCATEfollowed by a direct-pathINSERTrather than aDELETEand conventional pathINSERT. The former will be much more efficient but will mean that the table appears empty when you’re doing joins and data comparisons on the local server which seems unlikely to be appropriate in this situation.If you want to go down the path of having the source side create a materialized view log so that you can do an incremental refresh, on the source side, assuming the source table has a primary key, you’d ask them to
The materialized view that you would create would then be