Over the last months, our team has been working hard to finish the next evolution of AutoUpgrade which will make patching Oracle Database much easier. Evolution is a big word, but I really think this is a giant leap forward.
We promise you one-button patching of your Oracle Database (except that there’s no button to push, but rather just one command 😀).
Imagine you want to patch your Oracle Database. You run one command:
Patch the Oracle Database
That sounds interesting, right? You can learn much in our next webinar on Thursday, 24 October, 14:00 CEST. SIGN UP NOW!
What If?
I know some of you are already thinking:
What if my database is not connected to the internet?
Don’t worry – we thought about that and a lot more. If you have any questions, I promise that we won’t end the webinar until all questions are answered.
VIEWS_AS_TABLES is a neat feature in Oracle Data Pump that allows you to export the contents of a view and import them as tables.
The idea is to export a view as if it were a table. The dump file contains a table definition:
With the same name as the view
With the same columns as the view
With the same data as the view
Show Me
In the source database, you create a view, or you can use an existing view:
SQL> create view sales as select * from all_objects;
Next, you export that view as a table:
$ expdp ... views_as_tables=sales
In the target database, you import:
$ impdp ...
The view is now a table:
SQL> select object_type from all_objects where object_name='SALES';
OBJECT_TYPE
-----------
TABLE
When To Use It
Faster import of data over a database link when using the QUERY parameter.
Normally, the predicate in the QUERY parameter is evaluated on the target database, so during a Data Pump import over a database link, all rows are retrieved from the source database. Then, the QUERY parameter is applied to filter the rows. This is inefficient if you select a smaller portion of a larger table. By using VIEWS_AS_TABLES the filtering happens on the source database and might speed up the import dramatically.
Customized data export.
Another case I worked on involved a system where the user must be able to extract certain data in a format of their choosing. The user could define a view, export it, and import it into their local database for further processing. The view could:
Include various columns and the user can decide the ordering and column names.
Join tables to create a more complete data set.
Translate columns with domain values to text (like 1 being NEW, 2 being IN PROGRESS and so forth).
De-normalize data to make it more human-readable.
Format dates and numbers according to the user’s NLS settings.
Transform tables are part of a migration.
I’ve also seen some customers perform powerful transformations to data while the data was migrated. There are a lot of transformations already in Data Pump, but in these cases, the customer had more advanced requirements.
The Details
You can use VIEWS_AS_TABLES in all modes: full, tablespace, schema, and table.
The table has the same name as the view. But you can also use the REMAP_TABLE option in Data Pump to give it a new name.
During export, Data Pump:
Creates an empty table with the same structure as the view (select * from <view> where rownum < 1).
Exports the table metadata
Unloads data from the view
Drops the interim table
Data Pump also exports dependent objects, like grants, that are dependent on the view. On import, Data Pump adds those grants to the table.
Conclusion
A powerful feature that might come in handy one day to transform your data or boost the performance of network link imports.
Leave a comment and let me know how you used the feature.
The name must satisfy the requirements listed in “Database Object Naming Rules”. The first character of a PDB name must be an alphabet character. The remaining characters can be alphanumeric or the underscore character (_).
… However, database names, global database names, database link names, disk group names, and pluggable database (PDB) names are always case insensitive and are stored as uppercase. If you specify such names as quoted identifiers, then the quotation marks are silently ignored.
…
Names of disk groups, pluggable databases (PDBs), rollback segments, tablespaces, and tablespace sets are limited to 30 bytes.
So, AutoUpgrade is just playing by the rules.
The Answer
So, the answer is that the database use PDB names in alphanumeric uppercase. AutoUpgrade knows this and automatically converts to uppercase. The customer must accept that PDB names are uppercase.
These are the requirements for the PDB names
First character must be an alphabet character.
The name must be all uppercase.
The name can contain alphanumeric (A-Z) and the underscore (_) characters.
The PDB name must be unique in the CDB, and it must be unique within the scope of all the CDBs whose instances are reached through a specific listener.
Daniel’s Recommendation
I recommend that you use globally unique PDB names. In your entire organization, no PDBs have the same name. That way, you can move PDBs around without worrying about name collisions.
I know one customer that generates a unique number and prefix with P:
P00001
P00002
P00003
They have a database with a simple sequence and a function that returns P concatenated with the sequence number. The expose the function in their entire organization through a REST API using ORDS. Simple and yet elegant.
Final Words
I’ve spent more than 20 years working with computers. I have been burnt by naming issues so many times that I’ve defined a law: Daniel’s law for naming in computer science:
Use only uppercase alphanumeric characters
US characters only (no special Danish characters)
Underscores are fine
Never use spaces
Don’t try to push your luck when it comes to names :-)
If you want to save time during a Data Pump import, you can transform constraints to NOT VALIDATED.
Regardless of the constraint state in the source database, Data Pump will create the constraint using the novalidate keyword.
This can dramatically reduce the time it takes to import. But be aware of the drawbacks.
The Problem
Here is an example from a big import:
01-JAN-24 08:19:00.257: W-38 Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/CONSTRAINT
01-JAN-24 18:39:54.225: W-122 Completed 767 CONSTRAINT objects in 37253 seconds
01-JAN-24 18:39:54.225: W-122 Completed by worker 1 767 CONSTRAINT objects in 37253 seconds
There is only one worker processing constraints, and it took more than 10 hours to add 767 constraints. Ouch!
A Word About Constraints
Luckily, most databases use constraints extensively to enforce data quality. A constraint can be:
VALIDATED
All data in the table obeys the constraint.
The database guarantees that data is good.
NOT VALIDATED
All data in the table may or may not obey the constraint.
The database does not know if the data is good.
When you create a new constraint using the VALIDATE keyword (which is also the default), the database recursively full scans the entire table to ensure existing data is good. If you add more constraints, the database full scans each time. Since full table scans rarely make it into the buffer cache, each new constraint causes a lot of physical reads.
How Does Data Pump Add Constraints
Data Pump adds the constraints in the same state as in the source. As mentioned above, the constraints are most likely VALIDATED.
During import, Data Pump:
Creates an empty table
Loads data
Adds dependent objects, like constraints
It could look like this in a simplified manner:
For each of the alter table ... add constraint commands will trigger a full table scan because of the validate keyword. For a large database, this really hurts, especially because the full scan does not go parallel.
The Solution
The idea is to add the constraints as NOT VALIDATED but still ENABLED.
NOT VALIDATED means the database doesn’t check the existing data
ENABLED means the database enforces the constraints for new data
In Data Pump, there is a simple transformation:
impdp ... transform=constraint_novalidate:y
Data Pump adds all constraints using the novalidate keyword regardless of the state in the source database.
Instead of a full table scan for each new constraint, the alter table ... add constraint command is instant. It’s just a short write to the data dictionary, and that’s it. No full table scan.
This transformation requires Oracle Database 19c, Release Update 23 with the Data Pump Bundle Patch.
Update: A few ran into the following error when using the feature:
ORA-39001: invalid argument value
ORA-39042: invalid transform name CONSTRAINT_NOVALIDATE
Unfortunately, you need to add patch 37280692 as well. It’s included in 19.27.0 Data Pump Bundle Patch.
Is It Safe To Use?
Yes. There is no chance that this feature corrupts your data. Further, you know that data was good in the source, so it will be good in the target database as well.
However, you should take care when you are changing data on import. The alteration might lead to constraints being unable to validate and you won’t know this until you eventually perform the validation. The data is still perfectly fine, however, the constraint would need to be altered to match the new data.
Imagine the following:
You are importing into a different character set – from singlebyte to Unicode.
One of your constraints checks the length of a text using byte semantics with the function LENGTHB.
After import into the Unicode database, some characters may take up two bytes or more.
The result of the LENGTHB function would change and you would need to update the constraint definition. Either by allowing more bytes or using LENGTH or LENGTHC.
Let me give you an example:
In my singlebyte database (WE8MSWIN1252), I have a table with these two rows:
ABC
ÆØÅ (these are special Danish characters)
In singlebyte all characters take up one byte, so
LENGTHB('ABC') = 3
LENGTHB('ÆØÅ') = 3
I migrate to Unicode and now the special Danish character expand. They take up more space in AL32UTF8:
LENGTHB('ABC') = 3
LENGTHB('ÆØÅ') = 6
If I have a check constraint using the LENGTHB function, I would need to take this into accout. Plus, there are other similar functions that works on bytes instead of chars, like SUBSTRB.
It’s probably rare to see check constraints using byte semantic functions, like LENGTHB and SUBSTRB. But I’ve seen that in some systems that had to integrate with other systems.
You can end up in a similar situation if you:
use the remap_data option to change data
perform other kinds of data transformation
Since the constraint is still enabled, the database still enforces the constraint for new data after the import.
What’s the Catch?
Validated constraints are very useful to the database because it enables the optimizer to perform query rewrite and potentially improve query performance. Also, index access method might become available instead of full table scans with a validated constraint.
You want to get those constraints validated. But you don’t have to do it during the import. Validating an enabled, not validated constraint does not require a lock on the table. Thus, you can postpone the validation to a later time in your maintenance window, and you can perform other activities at the same time (like backup). Perhaps you can validate constraints while users are testing the database. Or wait until the next maintenance window.
Further, Data Pump always adds validated constraints in these circumstances:
On DEFAULT ON NULL columns
Used by a reference partitioned table
Used by a reference partitioned child table
Table with Primary key OID
Used as clustering key on a clustered table
What About Rely
After import, you could manually add the rely clause:
alter table ... modify constraint ... rely;
Rely tells the database that you know the data is good. The optimizer still doesn’t trust you until you set the parameter QUERY_REWRITE_INTEGRITY to TRUSTED. Now, the optimizer can now benefit from some query rewrite options, but not all of them.
Nothing beats a truly validated constraint!
Validate Constraints Using Parallel Query
Since you want to validate the constraints, Connor McDonald made a video showing you can do that efficiently using parallel query:
Changing the default parallel degree (as shown in the video) might be dangerous in a running system.
alter session force parallel query;
alter table ... modify constraint ... enable validate;
The validation happens:
Without table lock
In parallel
And with no cursor invalidation
Nice!
Final Words
If you’re short on time, consider adding constraints as not validated.
The above case with more than 10 hours spent on adding validated constraints; that could have been just a few seconds with novalidate constraints. That’s a huge difference to a time critical migration.
Don’t forget to validate them at one point, because validated constraints are a benefit to the database.
Check my previous blog post for further details on constraint internals.
Appendix
Autonomous Database
The fix is also available in Autonomous Database, both 19c and 23ai.
Zero Downtime Migration
If you import via Zero Downtime Migration (ZDM) you need to add the following to your ZDM response file:
I am speaking at the DOAG 2024 Conference + Exhibition in Nuremberg, Germany, on November 19-22. The organizers told me that the agenda was now live, so I went to check it out.
This is an amazing line-up of world-class speakers, tech geeks, top brass, and everything in between.
Why don’t you finish 2024 by sharpening your knowledge and bringing home a wealth of ideas that can help your business get the most out of Oracle Database?
The Agenda
It is a German conference, and many sessions are in German. However, since there are many international speakers, there are also many sessions in English.
I want upgrade a PDB from Oracle Database 19c to 23ai. It’s in a Base Database Service in OCI. I use the Remote clone feature in the OCI console but it fails with DCS-12300 because IMEDIA component is installed.
The task:
Clone a PDB using the OCI Console Remote clone feature
From a CDB on Oracle Database 19c to another CDB on Oracle Database 23ai
Upgrade the PDB to Oracle Database 23ai
Let’s see what happens when you clone a PDB:
It fails, as explained by the customer.
Let’s dig a little deeper. Connect as root to the target system and check the DCS agent.
$ dbcli list-jobs
ID Description Created Status
---------------------------------------- --------------------------------------------------------------------------- ----------------------------------- ----------
...
6e1fa60c-8572-4e08-ba30-cafb705c195e Remote Pluggable Database:SALES from SALES in db:CDB23 Tuesday, September 24, 2024, 05:04:13 UTC Failure
$ dbcli describe-job -i 6e1fa60c-8572-4e08-ba30-cafb705c195e
Job details
----------------------------------------------------------------
ID: 6e1fa60c-8572-4e08-ba30-cafb705c195e
Description: Remote Pluggable Database:SALES from SALES in db:CDB23
Status: Failure
Created: September 24, 2024 at 5:04:13 AM UTC
Progress: 35%
Message: DCS-12300:Failed to clone PDB SALES from remote PDB SALES. [[FATAL] [DBT-19407] Database option (IMEDIA) is not installed in Local CDB (CDB23).,
CAUSE: The database options installed on the Remote CDB(CDB19_979_fra.sub02121342350.daniel.oraclevcn.com) m
Error Code: DCS-12300
Cause: Error occurred during cloning the remote PDB.
Action: Refer to DCS agent log, DBCA log for more information.
...
What’s Going on?
First, IMEDIA stands for interMedia and is an old name for the Multimedia component. The ID of Multimedia is ORDIM.
Desupport of Oracle Multimedia
Oracle Multimedia is desupported in Oracle Database 19c, and the implementation is removed.
…
Oracle Multimedia objects and packages remain in the database. However, these objects and packages no longer function, and raise exceptions if there is an attempt made to use them.
In the customer’s and my case, the Multimedia component is installed in the source PDB, but not present in the target CDB. The target CDB is on Oracle Database 23ai where this component is completely removed.
If you plug in a PDB that has more components than the CDB, you get a plug-in violation, and that’s causing the error.
Here’s how you can check whether Multimedia is installed:
select con_id, status
from cdb_registry
where comp_id='ORDIM'
order by 1;
Solution 1: AutoUpgrade
The best solution is to use AutoUpgrade. Here’s a blog post with all the details.
AutoUpgrade detects that multimedia is already present in the preupgrade phase. Here’s an extract from the preupgrade log file:
INFORMATION ONLY
================
7. Follow the instructions in the Oracle Multimedia README.txt file in <23
ORACLE_HOME>/ord/im/admin/README.txt, or MOS note 2555923.1 to determine
if Oracle Multimedia is being used. If Oracle Multimedia is being used,
refer to MOS note 2347372.1 for suggestions on replacing Oracle
Multimedia.
Oracle Multimedia component (ORDIM) is installed.
Starting in release 19c, Oracle Multimedia is desupported. Object types
still exist, but methods and procedures will raise an exception. Refer to
23 Oracle Database Upgrade Guide, the Oracle Multimedia README.txt file
in <23 ORACLE_HOME>/ord/im/admin/README.txt, or MOS note 2555923.1 for
more information.
When AutoUpgrade plugs in the PDB with Multimedia, it’ll see the plug-in violation. But AutoUpgrade is smart and knows that Multimedia is special. It knows that during the upgrade, it will execute the Multimedia removal script. So, it disregards the plug-in violation until the situation is resolved.
AutoUpgrade also handles the upgrade, so it’s a done deal. Easy!
Solution 2: Remove Multimedia
You can also manually remove the Multimedia component in the source PDB before cloning.
I grabbed these instructions from Mike Dietrich’s blog. They work for a 19c CDB:
Without the Multimedia component cloning via the cloud tooling works, but you are still left with a PDB that you attend to.
If you’re not using AutoUpgrade, you will use a new feature called replay upgrade. The CDB will see that the PDB is a lower-version and start an automatic upgrade. However, you still have some manual pre- and post-upgrade tasks to do.
One of the reasons I prefer using AutoUpgrade.
Further Reading
For those interested, here are a few links to Mike Dietrich’s blog on components and Multimedia in particular:
If you ever encounter problems with Oracle Data Pump, you can use this recipe to get valuable tracing.
Over the years, I’ve helped many customers with Data Pump issues. The more information you have about a problem, the sooner you can come up with a solution. Here’s my list of things to collect when tracing a Data Pump issue.
If needed, you can later on create AWR reports for a shorter period.
If you are on Multitenant, do so in the root container and in the PDB.
Get the Information
Collect the following information:
The Data Pump log file.
AWR reports – on CDB and PDB level
Data Pump trace files
Stored in the database trace directory
Control process file name: *dm*
Worker process file names: *dw*
This should be a great starting point for diagnosing your Data Pump problem.
What Else
Remember, you can use the Data Pump Log Analyzer to quickly generate an overview and to dig into the details.
Regarding Data Pump parameters metrics=yes and logtime=all. You should always have those in your Data Pump jobs. They add very useful information at no extra cost. In Oracle, we are discussing whether these should be default in a coming version of Data Pump.
Leave a comment and let me know your favorite way of tracing Oracle Data Pump.
Imagine importing a large database using Oracle Data Pump. In the end, Data Pump tells you success/failure and the number of errors/warnings encountered. You decide to have a look at the log file. How big is it?
$ du -h import.log
29M import.log
29 MB! How many lines?
$ wc -l import.log
189931 import.log
Almost 200.000 lines!
How on earth can you digest that information and determine whether you can safely ignore the errors/warnings recorded by Data Pump?
DPLA can summarize the log file into a simple report.
It can give you an overview of each type of error.
It can tell you where Data Pump spent the most time.
It can produce an interactive HTML report.
And so much more. It’s a valuable companion when you use Oracle Data Pump.
Tell Me More
DPLA is not an official Oracle tool.
It is a tool created by Marcus Doeringer. Marcus works for Oracle and is one of our migration superstars. He’s been involved in the biggest and most complicated migrations and knows the pain of digesting a 200.000-line log file.
He decided to create a tool to assist in the analysis of Data Pump log files. He made it available for free on his GitHub repo.
Give It a Try
Next time you have a Data Pump log file, try to use the tool. It’s easy, and instructions come with good examples.
If you like it, be sure to star his repo. ⭐
If you can make it better, I’m sure Marcus would appreciate a pull request.
I can’t believe Oracle CloudWorld is already over. Although it has been very intense, it feels like it has just started. I love being amongst our customers and helping them use the Oracle Database in the best possible way.
I still feel the thrill from the conference, but I know that post-conference blues are soon kicking in.
Slides
I encourage you to look at the slides from our presentations. We did present some new cool enhancements.
Migrating the Beast – It’s always interesting to hear the stories from the trenches. The beast refers to a massive 180 TB database generating a staggering 15 TB/day.
Patch and Upgrade Your Database Like a Hero – We made AutoUpgrade Patching so much cooler. One command to download the recommended patches from My Oracle Support, build a new Oracle home, and patch your database. So simple!