1.617.682.4508

Pythian Blog

The world discusses #Pythian on Twitter. Have a question? Use our hashtag and ask away.

Emergency

24x7 Support

Not a Pythian client but need help now? No problem. Click here.

Are you aware of an existing DBA opening or consulting requirement in your organization? Enter your email for a chance to win one year's access to Safari Books.

  

Oracle Data Pump Schema Export and Public Synonyms

By: Alex Gorbachev

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...

Pythian Blog

Connecting to Oracle with SQL Server 2005 x64
The quirks of connecting to Oracle from SQL 2005 64
more



Live Updates

pythian: Pythian is now official members of the Microsoft Partner Program. Thanks Peter
more



RSSTestimonials

  • Casey Dyke

    Database Team Manager Service Delivery and Applications , Telstra

    Pythian were recently engaged to take a lead role in a high end infrastructure build project at Telstra. Our requirements were a combination of... more