THE WORLD DISCUSSES #PYTHIAN ON TWITTER. HAVE A QUESTION? USE OUR HASHTAG AND ASK AWAY.

Oracle Data Pump Schema Export and Public Synonyms

While testing a migration today with one of our clients, I figured out that schema export using Data Pump doesn’t capture public synonyms on the objects in this schema. This behavior is different from the older Export utility which includes public synonyms with schema objects. Update: This is actually the same behavior as old Export utility.

I can think of two workarounds:

  • Use Data Pump to export/import public schema including only synonyms but I couldn’t think of an easy way to filter only public synonyms on objects in specified schemas.
  • Generate a script that creates public synonyms. You can run the following on the source database, for example:
SELECT 'CREATE PUBLIC SYNONYM ' || synonym_name || ' FOR '
|| table_owner || '.' || table_name || ';' cmd
FROM dba_synonyms
WHERE TABLE_OWNER IN ([list of schemas]) AND owner='PUBLIC';

Does anyone know how to make Data Pump include public synonyms with schema export?

Updated:
Thanks to Paul for Export behavior correction. Also see below Andrew’s more complete version of the query including database links.

Concerned which objects are exported by Data Pump on full, schema, and table levels? Check views – DATABASE_EXPORT_OBJECTS, SCHEMA_EXPORT_OBJECTS, and TABLE_EXPORT_OBJECTS.

I still couldn’t get Data Pump filter out only synonyms I need. So far the best I’ve come up with:
INCLUDE=SYNONYM:"IN (SELECT synonym_name FROM dba_synonyms WHERE table_owner='TEST')"
However, this also captures private synonyms that happen to have the same name.

4 Responses

  1. Paul Muller says:

    Good point!
    However, just to clarify, EXP only captures public synonyms in full export mode (full=y), not schema-level, or table level mode.

  2. andrew says:

    Don’t forget about DB links…

    select ‘CREATE ‘|| decode(owner,’PUBLIC’,'PUBLIC ‘,null) ||
    ‘SYNONYM ‘ || decode(owner,’PUBLIC’,null, owner || ‘.’) ||
    lower(synonym_name) || ‘ FOR ‘ || lower(table_owner) ||
    ‘.’ || lower(table_name) ||
    decode(db_link,null,null,’@'||db_link) || ‘;’
    from sys.dba_synonyms
    where table_owner != ‘SYS’
    order by owner
    /

  3. Thanks andrew,
    Good catch about DB links. Isn’t this a beauty of sharing your experience?
    The more you share about what you do and come up with, the stronger your procedures and knowedge are. Amazing paradox. Huh?

    Paul,
    I guess there is no difference to Data Pump then! :-) Both, old Export and Data Pump, do not process public synonyms on schema export.
    Hurray! I just tested it again becuase I did a small test earlier prior this post to make sure I didn’t miss something and you know what? I did miss one thing. I gazed quickly on “. exporting PUBLIC type synonyms” line and mistakenly took it for confirmation that public synonyms are handled by old Export. On the second look only I noticed that it’s talking about public types.

  4. Updated the original post with that.

Leave a Reply

Start NowWith Pythian - database design, management and emergency handling capabilities...

Live Updates

pythian: RT @sheeri: #confoo talk "Bending Queries to your Will with EXPLAIN" slides http://bit.ly/explainslides & handout
more



Testimonials

  • Serge Racine

    DBA, Brookfield Energy

    We are very satisfied by the service given to us by Andre and Shakir in support of our recent data quality and reorganization initiative.... more