Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

DBMS_DATAPUMP.METADATA_FILTER No Longer Working In 23AI

BethWDec 25 2024

I have a PL/SQL package ‘OCI_BACKUP_UTILS’ which contains a public procedure ‘EXPORT_SCHEMA’. The export_schema procedure uses DBMS_DATAPUMP to export all objects for one Oracle schema. The database resides on Oracle OCI as a version 23AI database. The basic steps of the export_schema procedure are: 1) Open the job 2) Add the export output file to the job. 3) Add the log file to the job. 4) Apply a metadata filter to export the given schema. 5) Run the job.

I have an OCI admin account in the database. The admin account owns the OCI_BACKUP_UTILS package. I also execute the export_schema procedure from the admin account. The admin account has access read/write to the Oracle directory used by DBMS_DATAPUMP. The export_schema procedure was working when exporting other schemas in the database prior to 23AI. This is the first time I have tried to run in 23AI. The step to apply the metadata filter is failing with:

Error starting at line : 1 in command -
BEGIN oci_backup_utils.export_schema('some_schema'); END;
Error report -
ORA-31631: privileges are required
ORA-06512: at "SYS.DBMS_SYS_ERROR", line 79
ORA-06512: at "SYS.DBMS_DATAPUMP", line 5038
ORA-06512: at "SYS.DBMS_DATAPUMP", line 6506
ORA-06512: at "ADMIN.OCI_BACKUP_UTILS", line 247
ORA-06512: at line 1
31631. 00000 - "privileges are required"
*Cause: The necessary privileges are not available for operations such
as: restarting a job on behalf of another owner, using a device
as a member of the dump file set, or ommiting a directory
object associated with any of the various output files.
Refer to any following error messages for additional information.
*Action: Select a different job to restart, try a different operation, or
contact a database administrator to acquire the needed privileges.

When the error occurs, the job is in DBA_DATAPUMP_JOBS in defining state.

I am not able to determine the cause of the above error, has the DBMS_DATAPUMP changed from 19c to 23ai? If not, does anyone know the cause of the error?

The applicable code is below:

   PROCEDURE export_schema (
      p_schema_name IN VARCHAR2,
      p_filename IN VARCHAR2 DEFAULT NULL
   )
   IS

      lc_job_completed CONSTANT VARCHAR2(25) := 'COMPLETED';
      lc_job_stopped CONSTANT VARCHAR2(25) := 'STOPPED';

      l_dp_handle NUMBER;
      l_current_date VARCHAR2(50);
      l_job_state VARCHAR2(50);
      l_filename VARCHAR2(500);
      l_dump_filename VARCHAR2(500);
      l_log_filename VARCHAR2(500);

   BEGIN
   
      -- Get current date/time
      l_current_date := TO_CHAR(SYSDATE, 'YYYYMMDD_HH24MI');

      -- Open the schema export job
      l_dp_handle := DBMS_DATAPUMP.open (
         operation => 'EXPORT',
         job_mode => 'SCHEMA',
         remote_link => NULL,
         job_name => UPPER(p_schema_name) || '_EXPORT_' || l_current_date,
         version => 'LATEST'
      );

      -- If filename was not provided, generate the export filename
      IF p_filename IS NULL
      THEN
         l_filename := UPPER(p_schema_name) ||
                       '_EXPORT_' ||
                       l_current_date;
      ELSE
         l_filename := p_filename;
      END IF;

      l_dump_filename := l_filename || '.exp';
      l_log_filename := l_filename || '.log';

      -- Specify the dump file
      DBMS_DATAPUMP.add_file (
         handle => l_dp_handle,
         filename => l_dump_filename,
         directory => gc_directory_name,
         filetype => DBMS_DATAPUMP.ku$_file_type_dump_file
      );

      -- Specify the log file
      DBMS_DATAPUMP.add_file (
         handle => l_dp_handle,
         filename => l_log_filename,
         directory => gc_directory_name,
         filetype => DBMS_DATAPUMP.ku$_file_type_log_file
      );

      -- Specify the schema to be exported
      DBMS_DATAPUMP.metadata_filter (               ---- ERROR OCCURS HERE
         handle => l_dp_handle,
         name => 'SCHEMA_EXPR',
         value => '= ''' || p_schema_name || ''''
      );

      -- Start the data pump job
      DBMS_DATAPUMP.start_job(l_dp_handle);
Comments
Post Details
Added on Dec 25 2024
2 comments
504 views