HexaCluster LogoHexaCluster Logo
  • Services
  • Products
  • HexaRocket
  • Blog
  • Resources
  • Company
  • Contact Us
Schedule a Demo
Stay Updated

Subscribe to Newsletters

Be the first to know! Stay updated with the latest insights, database migration benchmarks, and technical updates from HexaCluster.

HexaCluster LogoHexaCluster Logo

Enterprise-grade Database migration, modernization, and tooling for teams moving off legacy databases.

  • One Dundas Street West, Suite 2500, Toronto, Ontario, M5G 1Z3, Canada
  • HexaCluster DMCC, Plot No: JLT-PH2-RET-R6 Jumeirah Lakes Towers, Dubai, UAE
connect@hexacluster.ai+1 (902) 221-5976

Security & Compliance

SOC 2 Type 1 reportSOC 2 Type 2 report, monitored by Comp AIGDPR compliantISO 27001AICPA SOC for Service Organizations

Products

  • DMAT
  • HexaRocket
  • HexaBridge
  • HexaTranspile
  • MyBatis2Pg
  • HexaReplicate
  • Download Products

HexaRocket

  • Supported Database Migrations
  • Migrate to Yugabyte
  • About HexaRocket
  • Migrate to Oracle
  • Migrate to PostgreSQL
  • Migrate to MariaDB

Services

  • Database Migration to PostgreSQL
  • Application Migration and Modernization
  • AI/ML and MLOps
  • Architectural Health Audit
  • Managed DBA Services
  • Performance Tuning
  • PostgreSQL Development
  • Training for DBAs & Developers
  • 24/7 Support
  • Supported Tools and Extensions

Company

  • Blog
  • Case Studies
  • Webinars
  • Announcements
  • About Us
  • Referral Program
  • Events
  • Contact Us

© HexaCluster 2026. All rights reserved. Privacy PolicyThis site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

HEXACLUSTERHEXACLUSTERHEXACLUSTER

Introducing pg_dbms_metadata in PostgreSQL for Oracle DBMS_METADATA Compatibility

Akhil Reddy Banappagari
Jan 03, 2024
postgresqlpg_dbms_metadata#pg_dbms_metadata#Oracle#PostgreSQL

Introduction: Need for Enhanced DDL Extraction in PostgreSQL like Oracle DBMS_METADATA

In the arena of powerful databases, PostgreSQL stands as a remarkable open-source solution with a wealth of features. Yet, amidst its excellence, a crucial enhancement is awaiting - PostgreSQL is seeking a streamlined solution for programmatically extracting DDL for database objects like DBMS_METADATA in Oracle. This inspired us to create pg_dbms_metadata, a solution designed to enhance your PostgreSQL experience and bridge this gap. We are excited to introduce pg_dbms_metadata, a PostgreSQL Extension for Oracle DBMS_METADATA Compatibility.

image


What is pg_dbms_metadata ?

This extension is designed to give compatibility to Oracle's DBMS_METADATA package. This facilitates a seamless transition for customers migrating from Oracle to PostgreSQL and provides a systematic approach for effortlessly retrieving DDL programmatically. During the migration from Oracle to PostgreSQL, this extension can help us get easily integrated into the existing workflows, making DDL extraction smoother.

🧠 Fine-tune Your PostgreSQL

A quick Architecture Audit can save hours of troubleshooting later.

Try it Now!

🚀 Planning a Database Migration?

Let HexaRocket simplify it - migrate smarter, faster, and stress-free.

Contact us Today!

🚀 Try HexaRocket

HexaRocket performs end-to-end database migrations and replication seamlessly between Oracle, SQL Server, MySQL, MariaDB, and PostgreSQL.

Try Today!

Challenges with Traditional Approaches for DDL extraction in PostgreSQL: A Look at pg_dump

Traditionally, PostgreSQL users have relied on tools like pg_dump to extract DDL for their database objects. Or sometimes, custom scripts or pgAdmin like tools to extract the DDL. While all of these solutions are effective, these approaches lack the flexibility and ease of programmatic extraction. Developers and database administrators often find themselves searching for a more seamless solution that integrates into their existing workflows.

Key Features of pg_dbms_metadata:

Following are some of the key features of pg_dbms_metadata.
Multi-Purpose Functionality
The extension not only provides alignment with the Oracle DBMS_METADATA package but also establishes a systematic approach to retrieve DDL programmatically.
Flexible Extraction
Users can generate DDL for an object using a plain SQL query or PL/pgSQL code, providing flexibility and adaptability to different user preferences.
Client-Agnostic Extraction
Unlike traditional methods like pg_dump, the extension : pg_dbms_metadata allows DDL extraction using any client capable of executing plain SQL queries. This opens up new possibilities for integration into various workflows.
Schema Flexibility
Similar to Oracle, users can omit the schema when extracting DDL, leveraging the search_path to locate the object and retrieve the required DDL.
Granular DDL Extraction
The extension provides three essential functions such as following -

GET_DDL(): Extracts DDL for a specified object. GET_DEPENDENT_DDL(): Extracts DDL for all dependent objects of a specified type for a base object. GET_GRANTED_DDL(): Extracts SQL statements to recreate granted privileges and roles for a specified grantee.

Configuration Control
Users can customize DDL through session-level transformation parameters using the SET_TRANSFORM_PARAM() procedure.

Usage Examples of pg_dbms_metadata

Following are a few examples demonstrating the usage of the extension.
GET_DDL():
This function extracts DDL of specified database objects.

SELECT dbms_metadata.get_ddl('TABLE','employees','gdmmm');
GET_DEPENDENT_DDL():
This function extracts DDL of all dependent objects of the specified object type for a specified base object.


SELECT dbms_metadata.get_dependent_ddl('CONSTRAINT','employees','gdmmm');
GET_GRANTED_DDL():
This function extracts the SQL statements to recreate granted privileges and roles for a specified grantee.


SELECT dbms_metadata.get_granted_ddl('ROLE_GRANT','user_test');
SET_TRANSFORM_PARAM():
This procedure is used to configure session-level transform params, with which we can customize the DDL of objects.
CALL dbms_metadata.set_transform_param('SQLTERMINATOR',true);

Conclusion:

In summary, "pg_dbms_metadata" elevates PostgreSQL's DDL extraction capabilities, offering Oracle compatibility, flexible extraction methods, and granular control over configurations. This extension streamlines workflows, providing a comprehensive solution for seamless migration and enhanced database management in PostgreSQL.


Authors

Akhil Reddy Banappagari

Akhil Reddy Banappagari

Senior Development Manager

Akhil is a Senior Development Manager at HexaCluster with expertise in architecting and developing enterprise applications using Java Spring Boot, Golang, Python, and other modern technologies. He has worked extensively with Oracle, PostgreSQL, SQL Server, MySQL, Snowflake, and various other databases, and is highly experienced in complex database and application migrations.

Start your migration journey 🚀

start your migration journey with our expert team

Products

DMAT

Database & Application Migration Assessment Tool

HexaRocket

End-to-End Database Migration & Modernization Tool

HexaTranspile

Database Code Object Conversion to PostgreSQL

MyBatis2Pg

MyBatis Mapper Conversion to PostgreSQL

HexaReplicate

Enterprise Data Replication & Live CDC

HexaBridge

Oracle Compatibility Layer for PostgreSQL

HexaRocket 🚀

Oracle to PostgreSQLSQL Server to PostgreSQLMySQL to PostgreSQLMariaDB to PostgreSQLAny to Any databases

Migration Services

Database MigrationsApplication Modernization

PostgreSQL Consulting

Architectural AuditsPerformance TuningTraining & Support