Chris and I will be at OpenWorld next month, so our session details are below, but you can also click on the links below to add entries to your calendar to make sure you don’t miss us. Don’t forget to use the official Schedule Builder to make sure you have booked your spot at our sessions!
If you can’t get to our sessions, you might catch us wandering the halls or at The Hub. Feel free to come and say Hello and talk tech!
See you at OpenWorld!
Addenda: See the slides from my talks here
Calendar ICS files
Tune ANY SQL in 20 minutes (.ics)
Fast Lane to Database Success (.ics)
Developers – Don’t Be The Person That Discombobulates Your Database (.ics)
18 Things Developers Will Love About Database 18c (.ics)
Why Isn’t My Query Using An Index (.ics)
Last year, I flexed my technology muscles by building on the fine ground work of Lucas Jellema in using some Node, some REST, and some JSON to extract the full Oracle Openworld speaker catalogue, and then added some JSON parsing in the database, some SQL and slapped a nice helping on Application Express on top of it all, to end up with an Application Express rendition of the Oracle Openworld speaker catalogue.
So it is that time of year again, and whilst some of the bits and pieces have changed, I’ve managed to stumble my way through all of the difference pieces once again, and made some enhancements along the way to give you the new and improved 2018 version!
It’s waiting there on apex.oracle.com for you to explore.
Whilst the ever increasing speed of storage and servers, and features likes In-memory are decreasing the need for large numbers of materialized views in databases, there are still plenty of use cases where they can be a useful performance or integrity tool.
But what if that materialized view takes minutes or hours to build? Then even if it is fast refresh enabled, than fast refresh is no of use if we have to rebuild the entire materialized view from scratch due to an structural change in the underlying table.
For example, let’s say I have a table and a simple fast refresh materialized view on that table as below:
SQL> create table t(x number(8) primary key); Table created. SQL> insert into t values(55); 1 row created. SQL> create materialized view log on t with primary key, rowid; Materialized view log created. SQL> create materialized view mv 2 build immediate 3 refresh fast on demand as 4 select * from t; Materialized view created. SQL> SQL> select * from t; X ---------- 55 1 row selected. SQL> select * from mv; X ---------- 55 1 row selected. SQL> insert into t values (10); 1 row created. SQL> insert into t values (20); 1 row created. SQL> commit; Commit complete. SQL> select * from t; X ---------- 10 20 55 3 rows selected. SQL> select * from mv; X ---------- 55 1 row selected. SQL> SQL> exec dbms_mview.refresh('mv'); PL/SQL procedure successfully completed. SQL> select * from mv; X ---------- 10 20 55 3 rows selected.
For the sake of this discussion, let’s assume the build of materialized takes hours. Naturally we want to avoid having to a rebuild (or do a complete refresh) of that materialized view. But then…the inevitable happens. We need to change the table T. In this case, the values for column X now exceed the limits of the definition.
SQL> insert into t values (123123123); insert into t values (123123123) * ERROR at line 1: ORA-01438: value larger than specified precision allowed for this column
Obviously, this is a trivial fix for the table. We simply alter the column to make it larger (which does not require any downtime or reorganization of the data).
SQL> alter table t modify x number(10);
But all is not well…Having a materialized view means that either the materialized view log, or the materialized view itself may have replicas of that column, so they remain “broken”
SQL> insert into t values (123123123); insert into t values (123123123) * ERROR at line 1: ORA-12096: error in materialized view log on "MCDONAC"."T" ORA-01438: value larger than specified precision allowed for this column
Notice the subtle difference in the error message. It is not an error on table T, but an error on the materialized view log. You might have the urge to simply jump and run the alter commands on the materialized view log and the materialized view. And you might even find that this approach works. But please note – this approach is not supported, and thus we can’t guarantee that it will (a) work, or (b) not create problems later down the track when you attempt to refresh the view or perform other operations.
But if direct alteration is not support, how do we solve the problem without having to rebuild the entire materialized view from scratch?
The solution here is the option to preserve the materialized view as a standalone table. We can drop the definition of the materialized view but hold on to the table that supports it. Now that it is a standalone table, we can alter the column definition so that it matches our source table T. Notice that before I drop the definition, I perform a final refresh to make sure the materialized is totally up to date – so there is a little bit of coordination required here to make sure that you do not lose any changes that occur to table T during the process.
SQL> exec dbms_mview.refresh('mv'); PL/SQL procedure successfully completed. SQL> drop materialized view mv preserve table; Materialized view dropped. SQL> drop materialized view log on t ; Materialized view log dropped. SQL> SQL> alter table t modify x number(10); Table altered. SQL> alter table mv modify x number(10); Table altered.
We still don’t have our materialized view back though. But we can recreate it without needing a full build cycle, using the PREBUILT table clause.
SQL> create materialized view log on t with PRIMARY KEY, rowid; Materialized view log created. SQL> SQL> create materialized view mv 2 on prebuilt table 3 refresh fast on demand as 4 select * from t; Materialized view created.
And we are done! An easy and supported means of altering the materialized view structure without a full rebuild of the data.
Just a quick post today that arose from an AskTOM question a little while back. Over the years and across the evolution of various versions of the Oracle database, the amount of “power” you could pack into a CREATE TABLE statement as grown. For example, I can do a CREATE-TABLE-AS-SELECT, along with a partitioning clause, including an explicit CREATE INDEX command and add constraints all in one atomic operation.
SQL> create table t 2 (id1, 3 id2, 4 owner, 5 object_name, 6 constraint t_pk primary key ( id1) using index 7 ( create index t_pk on t ( id1, owner) ) 8 ) 9 partition by range ( id2 ) 10 ( 11 partition p1 values less than ( 100000 ), 12 partition p2 values less than ( 200000 ) 13 ) 14 as 15 select 16 object_id id1, 17 object_id id2, 18 owner, 19 object_name 20 from dba_objects 21 where object_id is not null; Table created.
That’s pretty cool, but one of the most common times you will be writing DDL that includes a “select * from” as part of the DDL definition, is during the creation of materialized views, because the view text naturally will contain a select statement. Unfortunately, we are not quite as “generous” when it comes to accepting all of the various physical implementation options when it comes to DDL for materialized views. Trying to create a materialized view that matches our table T above is a struggle.
SQL> create materialized view t_mv 2 (id1, 3 id2, 4 owner, 5 object_name, 6 constraint t_mv_pk primary key ( id1) using index 7 ( create index t_mv_pk on t_mv ( id1, owner) ) 8 ) 9 partition by range ( id2 ) 10 ( 11 partition p1 values less than ( 100000 ), 12 partition p2 values less than ( 200000 ) 13 ) 14 refresh complete on demand 15 as 16 select 17 id1, 18 id2, 19 owner, 20 object_name 21 from t; constraint t_mv_pk primary key ( id1) using index * ERROR at line 6: ORA-00907: missing right parenthesis SQL> SQL> create materialized view t_mv 2 (id1, 3 id2, 4 owner, 5 object_name, 6 constraint t_mv_pk primary key ( id1) using index 7 ( create index t_mv_pk on t_mv ( id1, owner) ) 8 ) 9 refresh complete on demand 10 partition by range ( id2 ) 11 ( 12 partition p1 values less than ( 100000 ), 13 partition p2 values less than ( 200000 ) 14 ) 15 as 16 select 17 id1, 18 id2, 19 owner, 20 object_name 21 from t; constraint t_mv_pk primary key ( id1) using index * ERROR at line 6: ORA-00907: missing right parenthesis
When you encounter this limitation, don’t forget that one of the nice things you can do with materialized view creation is pre-create the underlying table with all of its flexibility:
SQL> create table t_mv 2 (id1, 3 id2, 4 owner, 5 object_name, 6 constraint t_mv_pk primary key ( id1) using index 7 ( create index t_mv_pk on t_mv ( id1, owner) ) 8 ) 9 partition by range ( id2 ) 10 ( 11 partition p1 values less than ( 100000 ), 12 partition p2 values less than ( 200000 ) 13 ) 14 as 15 select 16 id1, 17 id2, 18 owner, 19 object_name 20 from t; Table created.
And then once that it done, you can use the PREBUILT TABLE clause to create your materialized view which will now satisfy all of the underlying physical structure elements you desired.
SQL> create materialized view t_mv 2 on prebuilt table 3 refresh complete on demand 4 as select 5 id1, 6 id2, 7 owner, 8 object_name 9 from t; Materialized view created. SQL> SQL>
Hopefully you’ve followed my very simple and easy guide to downloading the 18c database software for Windows. But of course, software on its own is not much use – we need a database! So let’s get cracking and create one. Using the Start menu like I’ve done below, or using the Windows panels, locate the Database Configuration assistant and start it.
After a few seconds the initial screen will ask what you want to do. Choose “Create Database”.
If you like you could just go with “Typical Configuration” and you’ll be done in just a couple of clicks, but I always prefer to opt for the “Advanced Configuration” for two reasons. Firstly, even if you accept all of the defaults, it gives you a better idea of what options are going to be installed, where the files will be stored etc. And secondly…well…we all like to think of ourselves as advanced don’t we
For just research and exploration on your own Windows machine, you’ll probably want to opt for just a single instance database. RAC takes a bit more setup and complexity. For a faster install, choose one of the options that has the datafiles included. This way, the installer will just copy some existing files and seed them as your database, rather then building the entire instance from scratch.
Now choose a unique and memorable name for your database. I’ve reached into the depths of my imagination and come up with “db18” for my version 18 database. Go figure . I’d also recommend you go with a container database configuration, because that is the strategic direction for Oracle going forward, so if you are going to have a database to skill up on, it makes sense for that database to be a container database.
To keep things simple, I’m just nominating 1 single location for all of my database files. It can be anywhere but a common convention is that wherever you house them, you’ll have a folder called “oradata” and then a folder for each database you create under that.
I’m skipping the fast recovery area and archiving at this stage. If I start to get serious with testing things like backup and recovery, then I would revisit this after database creation to enable at least archiving so that I can explore all the goodies that RMAN has to offer.
On a brand new installation, it is likely you will not have a pre-existing listener to choose from. (If you had a previous installation, or had run the Network Configuration Assistant already, then you would see a listener to use).
I’m creating one called LISTENER18. The default port is normally 1521, but I’ve opted for 1518 just to align it with the version I’m using.
I’m skipping Data Vault and Label Security, but hopefully you can now see why it’s cool to go with the “Advanced Configuration” – you get to see all the potential functionality areas of the database that you might want to explore.
Now you choose how much of your server/desktop/laptop you’re going to allow this database to grab. My machine has plenty of RAM, but it also has a stack of other database versions running on it to handle my AskTOM daily tasks. So I’ll keep this dude at around 6G.
Now we’ll flick across the other tabs on this screen to see if there anything of note. The default for processes seems to have gone up in this version (I think it used to be around 300 in 12c) but in any event, that’s more than enough for me on this machine.
I have simple rule for character sets – UTF all the way. Single byte charactersets are soooo last century. We live in a global village, so you should be able to handle characters from all over the world!
And for the last tab, I’m going to opt for the sample schemas, so that when my database is created I’m not just left with an empty database shell. I want some sample data there so I can jump straight in and start experimenting with this release.
If I’m a DBA, I might go for some EM management to see how that all works, but for now, I’m skipping that.
Being a sandbox for experimenting, I’m setting all the passwords to a common value. Naturally this will not what you’ll be doing for your production databases!
So now I’m ready to go. I always tick the “Generate Scripts” option because it lets me see what is actually occurring when the creation assistant is doing its job. Even so, the scripts are probably not what I would use to automate a database install, since the ‘dbca’ command has nice command line option nowadays, along with the ‘-silent’ option so you can create an entire database with just a single command.
I finally get a summary of what is about to occur, and we’re off! Database creation is go for launch!
The total time to create your database will depending on your hardware, in particular how fast your storage is. I’ve done a few creations now using both flash storage and conventional hard drives, and unsurprisingly the flash storage is faster. You’re probably looking at around 10 minutes to complete.
When your database creation is complete, you’ll get the standard summary screen and you are ready to go.
And here it is – the finished product! My 18c database on Windows is ready to go. By default, the underlying Windows service will have a Start status of “Automatic” which means your database will start every time Windows starts. If you are short on memory, or do not want the database started unless you explicitly want it to, you can set this to Manual via “services.msc”
You can watch the video version of this installation here
Enjoy your 18c Windows database !
If you’re a Windows enterprise, or you want to run your 18c database on your Windows laptop/desktop for research and education, then there has been some good news this week. The software is now available to you on the OTN network page. Here’s a walk through of the software installation process
Head to the standard database downloads page
Accept the license agreement and choose the Windows version to download
Note – if you want to see all of the various Windows 18c components (grid, client, examples, etc), you can get that here
Once you have downloaded the software, note that when you unzip it, you are unzipping it directly into place, not into a staging area. So unzip to a folder that you intend to be your ORACLE_HOME location.
Once the unzip has been completed, in the base directory where you unzipped the files, there will be a setup.exe file. Double click on that to launch the installer
The familiar java based software installer will appear. For this blog post, I opted to solely go with software configuration – I’ll cover database creation in a separate post.
For my use, I’m just using a home laptop, so single instance for me. If you do want RAC, you’ll be needing to download more components anyway (eg Grid)
You’ll then get the standard pre-installation checks on your machine. For reference, the machine I’m installing the software on – its a 32G RAM machine on Windows 10, and I did not get any warnings.
I nominated my existing ORACLE_BASE location as the target for this ORACLE_HOME as well
and went with the default option of using a virtual Windows account to own the software:
Note: The first time I did this install, I went with the Windows Built-In account because I had an old 11g database installation under the same ORACLE_BASE, and I thought at least it would be consistent. Whilst the installation and subsequent use of 18c worked fine, and my 11g instance was fine, it totally hosed by 12c installation which was also under the same ORACLE_BASE. The 12c installation had been done with the default virtual account, and it appears the subsequent addition of 18c using the built-in Windows SYSTEM account reset the permissions on the critial diagnostic directory paths. From that point on, my 12c installation could not start and got “permission denied” errors when trying to access various destinations.
So my advice would be – adopt a consistent approach for any software under a common ORACLE_BASE.
Next you choose the edition you want to install. Enterprise for me naturally
And then you are ready to install. Just hit the Install button, sit back and relax.
You will see the familiar progress dialog box, and like all progress boxes from any vendor, the percentage complete will typically have no true bearing on how long the process will take For the record, my installation took around 8-10mins at this stage, most of it configuring the central inventory.
All things going well, you finally get the confirmation screen, and voila! You’re 18c database software is installed!
Here’s an (accelerated) video showing the above steps as they were performed on my machine.
Enjoy 18c on Windows!
In an Office Hours session a couple of months back, I covered an important change that comes to regular expressions once you upgrade to 12c Release 2. You can see the video covering the issue here:
but for the TL;DR brigade reading this post: Regular expressions are not deterministic when you take NLS settings into account and thus cannot be used in constraints and/or function-based indexes.
This is just a post to quickly revisit the topic for anyone thinking of upgrading from an earlier release to 12c Release 2. An AskTOM question came in asking what would happen to such constraints during the upgrade process.
The sad answer is … nothing. For example, if you successfully (and by strict definition, incorrectly) created a constraint with a regular expression in 11g, then after the upgrade, that constraint will still be present in your new 12c Release 2 system. It will continue to work as it did in 11g, and even if you disable/enable it, or put it through a validate command to exercise the data, it will work as it did before.
To be honest, I do not like this, because it can become what I call a “sleeper” problem. If, 6 months after you upgrade, you happen to drop and recreate that constraint you’ll be most distressed to find that it cannot be added, and you will have most probably long forgotten that it was caused by an event that occurred 6 months ago, namely the upgrade. And perhaps worse, you now have an index or constraint that could potentially be corrupted by innocent tinkering with session NLS settings.
So before you upgrade, definitely take a cursory glance through your constraint definitions and take remedial action if needed.