ndufrane / oracle_fdw_snapshot

Automatically creates oracle foreign data wrapper tables and allows materialized view snapshots

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

This set of functions is for creating materialized view snapshots on PostgreSQL from an Oracle database using the Oracle Foreign Data Wrapper (http://oracle-fdw.projects.postgresql.org). Note that it now requires oracle_fdw v0.9.6 at minimum since LONG types are now supported.

This was made to replace a replication system currently in place using dbi_link between an old Oracle 8i system and PostgreSQL 9.1. The Oracle setup file is only known for certain to work with 8i. If anyone else can supply setup files (or confirm this file works) for more modern versions of Oracle, that would be appreciated.

NOTE: You will have to edit setup_pg.sql to set the FDW server name and the schema where the oracle view is located for your systems. Also, the oracle setup file is using the ALL_TAB_COLUMNS system view. This only shows columns for tables that are accessible to the Oracle user you are using. If you want to be able to see all columns for all tables, you can try DBA_TAB_COLUMNS instead, but you'll need special permissions set for the Oracle user.

create_oracle_fdw_table('OWNER.TABLENAME', 'SNAP') - Function for creating an FDW table. The second parameter is for telling the function whether you want to actually use the foreign table for a snap job. Passing 'SNAP' will check to ensure local schemas exist and insert the necessary data into the translation table. Passing anything else (ex 'noSNAP'), will cause it to just create the foreign table and nothing else. Useful if you just want access to an Oracle table, but don't need the data locally.

perform_snapshot('OWNER.TABLENAME') - Grabs the most recent data from Oracle. Will automatically create the needed snap tables and view if they don't exist yet.

snapshot_maker('OWNER.TABLENAME') - Automatically create an FDW table, create both snap tables & create the view all in one command. 

snapshot_destroyer('OWNER.TABLENAME', 'ARCHIVE') - Remove a set of snap tables & remove the FDW table. Send the 'ARCHIVE' option if you'd like to make a permanent table on PostgreSQL with the same name as the view before. Send anything else (ex, 'noARCHIVE') to remove everything including data.

About

Automatically creates oracle foreign data wrapper tables and allows materialized view snapshots


Languages

Language:PLpgSQL 100.0%