Thursday, 3 December 2026

To put some load on Oracle26ai - I use these scripts.

 TL;DR: There are many good load generaters or benchmark tools out there. But I still use my own, very very simple, scripts a lot.


Image: Piling loads of stuff onto a moped. I will pile some load on a database, just to see how it reacts under stress.


Background: Why do I have load-generating scripts ?

The Agile-DevOps adage is to move-fast and break things (and me? well, I can at least "break things").

I have a few scripts and tricks to make an RDBMS (mostly, Oracle) work hard. Why? Sometime you want to know how fast the underlying CPU is, sometimes you want to get a feel for the (overloaded, stresssed) IO channels, sometimes, you want the server to "explode with PGA". But mostly, I just want to verify that I am looking at the relevant information.

There are lots of load-generator and "benchmarks" out there, some of them as old as my own scripts, from before y2k. I'll mention a few:

SLOB, from Kevin Closson. Simple, Elegant. Will stress the IO system by using the database. Requires a very small cache-setting.

Orion and its successor, Calibrate_IO (link to Oracle-Base, as Tim always provides easy-runnable examples). Orion runs "outside" of the RDBMS. Calibrate_io needs you to connect to the CDB as sys, and it is vaguely licensed. I would not risk that on a cstmr in a potentially audited environment. Otherwise: Quite Useful, as it spits out numbers straight away and saves them in a view.

HammerDB (formerly HamerORA by Steve Shaw).Very Useful. And still actively maintained. But it takes time + resources to set up.

Swingbench by Dominic Giles, Possibly the Golden Standard for testing Oracle RDBMS. But still takes some setup-activity.

That list above is just to show I am not ignorant. Nor am I a complete luddite. But there are always several reasons why those above do not fit into an existing cstmr/production situation. Different Stories, some other time.

All this intro to confess that I still have my own very basic, primitive, testing-scripts. Since way back before y2k even. Although they have been modified a lot over time, the main principles have remained: Simple, Easy to run, easy to understand, easy to adapt.


Main usage: Casual Confirmation of the Correct Procedures.

The scripts presented below are by no means a proper benchmark, and should not be use in systematic evaluation of capacity or performance of systems. They are purely for "first look".

The main reason I use these are to "confirm" what we are looking at. Whenever I get to observe a system via OEM, AWR, sar, iostat, taskmgr, statspack, cloudwatch, or some some other tool, I want to double-check what I am looking at. I want to establish that I am looking at the correct system and the relevant information. 

[small rant] Probably 50% of times I got an AWR or sp-report, or screenshot of some observation-tool mailed, or when I was given a screen or prompt to "look at the system", that information was from the Wrong Database or the wrong time-interval, or on the wrong system. Hence, others and myself still, often, make the mistake of looking at the wrong data. This is why my checklist includes a verification for database-names, service-names, and timestamps in the information. We have to always firmly establish that this is indeed the "problem system" that has to be investigated. [/rant over].

At this point, I am reminded of a legendary cult-movie-quote from the 90s.. 

If you havn't seen the tremors-movies yet, start with the original from 1990.

Anyway, by creating a few minutes of CPU or IO-load on a system, you can show to yourself and your co-workers that the observation-system you are using is indeed looking at the correct system, and at the correct time. Furthermore, you are ensuring that you or your local colleagues can connect and query exactly that system. And you also get a first impression on how it will react to additional load.

Hence one of my reasons to keep these scripts around.


Load up the CPUs, and how many CPUs do we actually have...?

My first script is spin.sql. It is meant to occupy 1 CPU or one Thread, for a given number of seconds. Running it looks like this:

It takes 1 argument, the nr of seconds you want the spin to run. And the output of loops/sec will give you an idea of how fast the underlying CPU will serve this RDBMS. 

In the performance-screen of OEM (and other similar tools) this will show up as Green. Every running instance of this script will cause a horizontal green area, representing 1 CPU.

The actual script is a PL/SQL block that does ... Nothing. Check for yourself with the link to script. It runs a loop until time is up. If the PL/SQL processor ever becomes Really Clever it may just refuse to do anyting, or it may decide that it can replace the loop by a sleep and report out a random number at the end. That would be a good joke by Oracle on us actually.

Tip: try running more spin-sessions and observe your (sysstat) sar-output, or a similar metric. Then increase the nr of spins to your cpu_count parameter, or even to the actual nr of CPUs provisioned for that machine. See how it reacts.

[Anecdote:] I cherish this script. It was particularly fun back in 2007, at a customer who had purchased a brand-new machine with 24 CPUs (that was still a sizeable machine, and expen$ive hardware back then). We tried running spin.sql with 4, 8, 12, 16, ... many sessions spinning on the first database on that machine. The sar-output showed that idle-time didnt decrease as much as we had anticipated. The sysadmin went back to investigate and got all excited when he found out that the actual box contained more (activated-) CPUs than the 24 we paid for. And it was able to use them properly. We informed our teamleader, showed him the proof and he then told us to not speak too much about that. That machine went on to contain 100+ databases for dev/test/acc/regress/perf... (The sysadmin was called Martin, and he was once photographed by the google-camera while standing at "smokers corner" outside the office. He is still visible on the old streetview. Good Memories..) [/anecdote]


Logical IO - Cartesian product to provoke (mostly) CPU-ticks.

For a while I used some LIO-scripts as well. But LIO is actually (mostly) just CPU-work. And if you just want to see your CPU spin, you can do even more simple than my script, just give the RDBMS a carthesian product on two large sets. I could invite you to copy/past the following, and sit back:

SQL > select count (*) from all_source, all_tab_columns ;

That will take a bit of time and is guaranteed to be 99% CPU effort. If you want longer runing SQL, just add tables or views and leave out any join-conditions.

The problem with queries like this is that they can and will run for an undetermined time. Hence. you often end up doing a kill-session, a Control-C, or a kill-minus-nine. All of which is un-elegant and sometimes messy. Hence I reverted to the original spin.sql which attempts to do "purely CPU work".

But thought I'd put down this shortcut to an easy-to-type carthesian product anyway. Just in case someone is in a real hurry.


Some real (Physical) disk_reads, hoping for actual IO from disk.

Yaya yaaah, I know, "hope is not a strategy".. and I full well realize the shortcomings of my script here. I still present it. This script is best used on non-Exadata systems. But I actually also use it on Exadata systems sometimes, even just to compliment spin.sql with a more diverse load. It has a few "features".

The script was built to try and provoke disk-reads, showing up as blue-time in the OEM screen, and it is called spin_pio.sql:

Notice how I ask it to spin for 45sec, but it actually spends 51sec? 

This script does a union-query of All_tables and All_views, and will try to count(*)  all of them, until it hits the specified time from arg1 (the &1 for the SQL*Plus and SQLcl folks).

However this script also could easily go "runaway" when it was busy doing a select-full-count-star query on a large table. Hence the risk of this script is (was) that it would run for many minutes or more past its intended time when it hit large tables. For that reasons, I had to build in a condition for "rownum <= some_number".

Another quirk when trying to run multiple of those spin_pio script was that the 2nd and subsequent runs would hit cache, rather than disk-reads. To this end I had a clone-script that would inverse the order of the objects it would query. 

I did not build in the "flush buffer_cache", because that could ruin the day if anyone ran it on a Production system. But you can still do that flush by hand if you want to.

At some point, I also built in a /* watermark */ in the select-queries, which allowed me to follow it by looking at V$SQLAREA and to point out the queries to others if they were interested. Here is a sample from a running database:

Can you spot the watermark in the selects? It "displays" the nr of loops done by that script, and it contains the start time of that particular SQL. Just another one of my ways to keep track of what is going on.

And from re-visiting this script to write about it, a lot of the old ideas come back: I should really use v$mystats and v$events to count + time the IO caused by the session that is reading. And I could use it as an informal benchmark, like I did for the loop-count on CPU speed.

But the problems with generating "Disk Reads" are multiple. Let me mention two of them:

. Problem a) Caching. The buffer-cache will try to hold all data, and prevent disk reads. And if not the buffer-cache, there is also caching at the levels of filers or storage arrays. This can lead to the following situation:

Notice how two runs of 10sec each lead to a very different nr of "executes" ? On the second run, the nr is much higher, notably due to Caching effect, possibly other factors as well.

. Problem b) Engineered systems. Exadata will tell you "cell physical IO...", in which case you may be reading from disk, or from cell-cache, or some "smart cache" out there.

Note: My spin_pio.sql  script pre-dates Exadata by at least 10yrs, and I never had the need to really dig into cell-IO. Hence, I still fail at generating Truly Physical Reads in an Exadata system. But I can try to scan as many blocks as I can. 

Yes, this particular script is in for a serious overhaul to create an Exadata version. but in all the years, I have not yet had the need to measure or "benchmark" an Exadata. Exa-machines are simply good at processing a lot of data, and I also found that most Exadata machines are silently running "small" databases which easily fit in SGA or cell-based cache memory.


About Transactions and Redo-generation - a Teaser.

[Edited - some of this content got removed or postponed] 

I have experimented with similar spin-scripts to generate excessive redo (and log-switches) and to generate an excessive nr of commits/second. 

This can lead to a wait-event-graph looking like this:

The result of a spin_redo of 60sec. There is a lot to investigate here, and a long list of caveats on redo-files, db-parameters, server-parameters and more angles to discuss than I can currently fit in a readable paragraph.

Suffice to say that commit-frequency, commit-parameters, tx-size and redo-generation can really make your wait-event-screen look colorful (green, blue, red, brown ... ). But those scripts are both more complicated and not yet as mature as the ones discussed so far. Hence I'm skipping that for now. Maybe later.

And a similar reasoning is valid for "spin_pga", where I tried to (over)load the PGA with a number of processes and data to try and "break things". Later.

[/edited]


Inspiration to improve (but beware of complexity!)

You can Always Improve code, scripts, systems. We used to call it CTD (link to Tim, 2009...). 

Just from writing this blogpost and revisiting the scripts, I already got some old ideas surfacing and some new ideas popping up. Here is a list of ideas for myself, or anyone who wants to hack the code.

Idea 1) More numbers reporting. Print out more info on looping and timings. For example, the PIO script can also count total-row-processed. Looking at generally helps. Over time you will get a feeling for "how fast" a system or its components are. Like I did from the loop-count of the original spin.sql for CPU speed.

Idea 2) Keep Results. Always spool results, preferably to a file name : spin_cpu_<Service_name>_yyyymmdd_hh24mi.lst. And (idea 2.1) possibly in a format that you can import easily into some repostitory with benchmarks (e.g. generate easy-loadable csv-data, or even insert-stmnts).

Idea 3) Add some Exa-specific metrics. The scripts work OK on and Exadata, but I would like to provoke some of the specific Exa-events.

Idea 4) Add arg2, arg3 to the scripts. Notably for spin_io: add the max-rows, arg2, as a parameter. For "Larger" systems, the default is nowadays too small. Simlarly, the looping could read the tables in reverse-alphabetical order, arg3. This would prevent multiple-scripts to read the same, cached, data shortly after eachother.

Idea 5) Flush the buffer-cache. Either as a cmd-option (arg<n>, or by default. This option has been available since at least v11, or even earlier. I think there were some less-document alter-system-events even before that.

As usual, the problems with such improvements are that they complicate the scripts (simple-oracle-dba, remember), and they would require me to "think before I run". SQL*Plus never was friendly in processing &1, &2, etc, and substituting specifics for defaults requires more script stuff. I am not only Simple, I am also lazy.


Conclusion: No shame in building and running your own scripts.

For this blogpost: I is mostly intended as notes-for-myself, and possibly, hopefully, as Inspiration for the reader to "Build your Own".

My scripts are Very Primitive compared to the exising well known tools. And mine will only be of limited use for others. But I am still glad I kept them around. They still serve me.

If you ever come across situations where you need something like these scripts, for a Quick-Look or a Quick-Assessment, feel free to copy them. But you can also, always easily write.your own and learn/discover things in the process.


Other Takeways: Explaining = Learning. And some topics have to wait.

You will always have a better understanding of what you do when you "build and run your own". And as an aside, by "outing" my scripts via this blogpost, I had to re-visit them. And some of them have just received some overdue TLC. 

Also, the spinning and (stress-)testing of redo, commits and PGA will have to wait for another time.

Lastly, maybe a tip for any future #JOELKALLMANDAY writing: You only Really learn stuff if you have to explain it to someone else.

-- -- -- -- -- End of this Blogpost - for now -- -- -- -- -- 

Appendix: links to scripts.

spin.sql  <nr_seconds> :  Utilize one CPU for nr_seconds

spin_pio.sql  <nr_seconds> : attempt to read from disk, for nr_seconds.

-- -- -- -- -- End of this Blogpost - for Real -- -- -- -- -- 

Saturday, 28 November 2026

Tooling just got simpler - using AI to build your tooling to inspect an Oracle Database

 TL;DR: Sometimes you have to "build" your own tools. And nowadays, an AI-assistant is a Surprisingly Good Help at that.


Image: I used an AI-assistant... got me thinking of Robot and Frank. Some 15yrs ago, but still a recommended movie...


Background: I needed to diagnose a "Legacy" system.

There is this customer who runs a relatively small but Critical system with a database on SE2. The system is 25+ years old, and still lovingly maintained and cherished by its users and a small team of Developers.

There are many (100s) of installations of this system around, all on Oracle SE2 on Windows. In most cases, it hummed away quietly in a corner of a dusty datacentre. In some cases, the data had grown to a size that made it more difficult to manage. And a few installations had "irregular proglems" with sluggishness or hiccups.

This being SE2, my first advice was to install Statspack everywhere. But for more ad-hoc troubleshooting, I also felt the need for the screen with OEM wait-statistics. 


Been Living on sql-scripts for years.

Statspack-installation will get under way, through a process of ticket-submission and approval. But getting OEM would be complicated.

And this particular situation was calling for the "wait statistics graph" from OEM.

Ever since the disappearance of Lab128, I have mostly depended on a set of scripts and occasionally on OEM. I already was apt at interrogating ASH and AWR, and the gv$ views and I could manage reasonably well. But here I was on SE2, with a lot less tooling, and I had to revert to queries on SNAP$ tables (my scripts from the 00s, on v9.2, suddenly looked very interesting again).

I know how to get around with scripts, but it takes time, and it takes even more time with SE2 and PERFSTAT. Becasue most of my scripts were by now geared towards EE.

Some 15yrs ago I would have gotten a Lab128 free download, and, whizz-Bang, I would have a view of how a system was running and where the possible fixable items were. The low hanging fruit.

But this is 2026.


So let me try this...

In an inspired moment, I asked claude to get me a viewer, similar to the OEM-performance screen, Lab128.exe, ancient TOra, and quest-spotlight.

The results were surprisingly good.

Here is some of the dialogue:


I am not sure how much claude already knows of me, but its way of thinking on this idea was remarkably similar to my own. 

The result was a zip-file with a python app that I could run, which I did. And Voila, a browser screen showed approximately the output I was hoping for.

Impressive: Only 15 minutes after "the Idea", I had a first version, and Working.

When running v1, I had some remarks, mostly cosmetic. I made some comments. Claude itself had located more information on lab128 and was ready to produce a working version 2. In less than 30min after the Idea. That is Fast for any software-development. 

However, v2 gave me a sql-syntax error, which claude fixed when I pointed it out. 

The fix worked. 

And a few more rounds of dialogue got us to v2.03, which had most of what I wanted, and more. I specifically wanted the ability to connect via either light- or full-client-stack, running muliple screens to different database, and a way to "keep" the data. The options as described in the README.md reflect some of that:

Doesnt that look surprisingly "complete" for 30min of work ? 

Let's have a look at the result.


Looking at some of the information.

My main intention was to have the "wait stats, like OEM". And it delivered: The top of the screen looks like this:

Note that I explicitly put in some SQL activity (green=cpu, blue=io) and a deliberate lock-block-wait (red).

<small> Note to self: I have some script I use for quick-testing and quick-demos: spin.sql, spin_pio.sql, and demo_fklck.sql, possibly worth a future blog. </small>

When scrolling down, below the wait-graph comes a section on Statistics, Events and Top Activity:

I really liked the six smaller running graphs  and the large choice in the picklist for each of them (lab128, anyone?). Any statistic you are interested in: It is There. In my case, one of those is the "logons/s", to detect excessive logon-activity from too-large connection pools...

 And below those graphs and events, there are the top-SQL statements:

You might spot my artificial load, caused by "spin" and count-queries...

The "session" screen surprised me by already providing a Waiters-Blockers tree and click-through possibility on both SQL_ID and SID.  Of course you need those features, but claude seemed to know that all by itself.

I'm a little careful to Shout Out Victory after only about 2 days of usage. But I can already say that this "assistant", claude, is rather impressive.


Improvements - Probably. But not yet.

Do I have more questions?  More goodies to ask for ? Yes. 

But let me explore a bit first. I feel like I have barely discovered all the possibilities of the current version. And for now I have enough to work with.

The first/next thing that comes to mind is this: Drawing ERDs.

For example when I inspect an SQL-stmnt for improvement (or elimination), I often draw an ERD for the tables under the query. And I can probably ask claude to help me create a quick-draw tool here, provided it has enough access to the dictionary of the database in question.

And I suspect some of my friends can come up with more, better and more interesting ideas. So if you are reading, feel free to contact me.


Dependent on the assistant?

A quick mention here about python. I agree with claude that python is a good choice here: it has an ready-to-go oracle-connector, and is Very Powerful in data-handling inside the app. But the resulting code is unreadable for a python-nood like me. Where the SQL generated by claude and copilot is often readable and instructive (you can learn from it!), the python code for oramon is, for me, not very accessible. And that also applies to a lot of the AI-generated python I see from colleagues: they can quickly wrap API-calls in a program, and it often works smoothly. Until it doesnt, and then only the assistant can help... 

This Should be a point for future attention.


Conclusion: This is Powerful stuff. Interesting! 

It is hard to express how Happy + Surprised I was with this "assistant-created tool".

 This can make the (adhoc) creation of tooling much more easy. And with better tools, I can often solve problems faster.

This AI stuff is powerful, and I will be tweaking and playing with this in the near future. At the same time, I feel humbled. I could never have built this myself (which is why I often got lab128). 

At the same time, I know how many ppl (myself included) can get confused by OEM, lab128 and similar tools that provide some quite-geeky information. You still need to interpret it, draw conclusions, and apply the resulting information correctly.

The speed with which claude produced a surprisingly workable program, That was what Impressed me most.

When I inspected the python-code, I had to conclude that it was, on first sight, too complicated for me to mess with. Hence, for further development and maintenance of this tool, I will have to depend on claude. That makes me slightly uneasy as I loose some control there.

It will be Interesting to see how this will develop. 

-- -- -- -- -- End of this blogpost -- -- -- -- -- 

Link to version v203, so you can try:

oramon-v203.zip

Give it a spin, and tell me what you think.

-- -- -- -- -- End of this blogpost, for real (for now)-- -- -- -- -- 


Tuesday, 13 October 2026

Got a Good Idea? Show it with SQL #JoelKallmanday

TL;DR: Always use a SQL-script too demonstrate what you to do. And make it Repeatable, and preferable Self-explaining. That way, anyone can quickly see for themselves what you want to say.


Intro: Always the Database...

But piet, you want to offer a Database Solution for Everything...  !

My reply: Off Course I do. You work with Data.. then the Database can + should Help you. And the database (with SQL) is probably the simplest solution to what you want to achieve...

image: Always have a (demo-)script to run....


Background: How I learned to use SQL(-scripts) to show things.

I have to pay tribute to Tom Kyte (from asktom), Tim Hall (from ora-base), and more recently Connor McDonald (link) for showing me many useful things for my work as an Oracle DBA- and database-plumber and an overall Database-SME (Subject-Matter-Expert...).

The main trick in showing things to colleagues is to Explain what you want them to know and then Show it, Demo it. Preferably with an SQL script. A script that can be copied and re-used as a basis for the program/system/solution/script that you want them to build.

NB: This topic seems a suitable item as my entry for the #JoelKallmanday this year.. Details in the post by Tim Hall (link).


Explain to Colleagues or audience what you want... (and Show it)

In most cases, when I want to show something new, or suggest a database-solution to others: I create a demo-script. You can try endlessly to "explain" a feature or a way to process data in the database (often preferable to any other tool). But to really convince people, to "Win Them Over" you have to demonstrate it.

Example1: the use of ENUM for LoVs (link). I first played with the SQL-statements, wrote a script. Then I started composing the blog and the script together so they would match and provide a readable and runnable combinations.

Example2: Demo "SQL-Assertions" (link) and show some of what what happens underneath (link). Again I started toying with the statements.

Example3: The new feature of SQL-History in Oracle 26ai (link). I wanted to build this into some of the python-programs we used to find "the heavies" in there. But I first I had to demonstrate "why" and "how". And again, starting from pure-SQL was the best way to show what the feature can do. (incidentally: can this SQL-history be back-ported to v19c ?? just asking gently...)

All of those blog were written around one or two files that the reader can download, and run for themselves to replay the demo and see what is happening. And maybe to "build on" for further usage of the feature described.


No Demo = no argument.

Without providing examples, I now tend to come across blogs, vlogs, and other content where someone Loads Praise on a feture (Vectors, LLM, zero-failover, or more weird-Sci-Fi stuff) but does not provide a simple, re-rerunnable, Demo for me to Use. I can understand that some topics require more study, more installing, more work, or even "hardware" before you can use them properly. But without a demo-to-copy, I find it rather damages the credibility of the message.

A Good Example of Doing it Right was Francisco at POUG in 2023, who told us his message and then fearlessly went "This is POUG - Let's Demo!". He showed us that it Really Worked (it was a live-patch with Zero Downtime).

I also recall a very old case (early 2002) where the data-model and the data-usage lend itself to using IOTs (Index Organized Tables, link?). I went out of my way to argue how data-proximity would benefit this system. Storing all descendants of a parent records, would facilitate the retrieval of the sets of "childeren" from a given parent. But in the end, a demo with a sizeable data-set was more convincing than all my argumenting, my talking and my powerpointing. It was at that point that I realised that Tom Kyte was Right: Always have a Demo(-script).

That demo, btw, was later simplified into a a few blogposts and into a presentation that was given 10+ times at various conferences... and still works. Good Memories (link to scripts below - demo_iot/2.sql)


Requirement for demo-scripts: Run without Hassle.

(This is the advice that I probably ignored the most with my own demos)

Whenever you create a scripts for demo-use, Keep It Simple. It should be runnable at just about any promt (provided it is Oracle SQL): SQL*Plus, SQLcl. But also from SQLDeveloper (classic or VSCode), and even from exotics like "the frog" (IYKNY) or DBeaver.

It should also perferably do come explaining by itself. I often include comments and "prompt-statements" to do this. Note that I tend to overdo the echos and prompts, and too many echos and prompts can make the script a bit weird.

Furthermore, try to Minimize any "setup" that is needed. I broke that rule when I requested ppl to install the oracle-supplied demo of scott/tiger/emp/dept for some of my own demos. Normally, I try to prevent that.

Also: Make the demo easily "re-runnable". The outcome of your demo should be identical at every run. The Devops-folks call this "Idempotency" (google it if needed).

And finally : Make it do its own cleanup. Make it drop any created objects and rollback any modified data. (I often break this rule myself as well, but ...), This is mostly a matter of politeness and cleanliness...


It takes some Effort, but it pays off

I realize that building a good, clear, smooth-running, and self-explaning script it not always simple: It Takes Effort. I know that from dire experience: I used to send script to colleagues with comment "this will do it". And in many cases, they failed to grasp the meaning. Or worse: they mis-interpreted and switch the "bad part"  with the "good part" and built exactly the wrong code.

By spending some time to demo stuff, you will a) Learn more and b) Get Re-Usable snippets. In several cases I could go back to years-old scripts and re-demo it, re-use it to show a possible solution in minutes. Some cstmrs are properly impressed when you come up with a solution that quickly (downside is they expect you to solve Everything before the day is over).


Another Example: Oracle-Base dot com...

Good SQL-runnable Examples, This is exactly why the site Oracle-base.com from Tim Hall is so popular: Every page has the same pattern : It explains what he wants to say, and then contains Ready-to-Run code-examples.  And of course you can copy the statements from the examples for your own use.


Final Example: mk_rerun.sql...

(did I ever blog about this one ? , Actually, Yes..)

https://simpleoracledba.blogspot.com/2023/07/find-and-use-bind-variables-from-sql.html

This script will take an SQL_ID, and generate a (nearly) re-runnable script for it. It pickes the statement from v$, it tries to find the latest bind-vars from v$, and it puts it all together in a file you you can edit to make it runnable. It has a lot of caveats, notably around variable-types (dates were problematic to define as as bind-vars...).

The Script... (link)

This post is partly created bcse I recently used this script again at a cstmr to show how certain values of input-values (assingned to the bind-vars) could send a query off into the sunset.


Concluding: Scripted SQL-demos are Worth it.

By spending some time to demo stuff, you will a) Learn more and b) Get Re-Usable snippets. In several cases I could go back to years-old scripts and re-demo it, re-use it to show a possible solution in minutes. Some cstmrs are properly impressed when you come up with a solution that quickly (downside is they expect you to solve Everything before the day is over).

But I think the idea is clear: A good database-story should have some good, runnable, Demo-Scripts. I did many done presentations with good  (and some less-good) SQL-scripts to go with them. I think we should make that point to new presenters as well.


And about that Database Solution...

To come back to "Always a Database Solution" .. Sure, there is more than just SQL. And yes, I have looked beyond the database. 

But because most Information is Data, in many cases a Database Solution should be your first call. And if you Demo your ideas properly, you may actually convince some colleagues.

-- -- -- -- -- End of this Blog, for now -- -- -- -- 

Links to demo-script mentioned:

demo_iot.sql : first part of the demo, going back to 2009 or so, still valid.

demo_iot2.sql : 2nd part of the demo.

mk_rerun.sql : if you ever need to re-run an SQL from command prompt.

-- -- -- -- End of this blog-entry, For Real -- -- -- --


Saturday, 22 August 2026

Creating an Oracle 26ai database from a Single Script - Cool.

TL;DR: The One Script you will Ever Need to create an Oracle 26ai Database. And for you to configure, should you want to.

After a remark from a colleague, I created this un-necessary, but Very Satisfying script: All-In-One. And I added some "minor" checks and improvements to the previous (multi-script) versions.

You can use this single script to create your CDB database and/or add PDBs. You can also review, adjust, and configure the various parts before running them. Hence you can create Any Oracle 23ai database, on Any (linux) Server with minimal effort.

Why? Partly from hobby, partly from a challenge by a critic, partly bcse it was just Fun to Do.

However....

First I ended up with too many components, too many scripts... 

Hence, after some hard scripting-work...


Now I just carry one file to do the job.


-- Background: "Too many scripts" ?

(you can skip "background" + "why" if you are in a hurry)

I've written this many times: I want Simple, Portable, Readable, universally Usable scripts. And to Create a database, I took inspiration from the DBCA, but I amended (simplified) the generated scripts a bit. See Earlier Blogs (link to start of series).

And then a colleague @ cstmr said: Why do I need to download so many files? And your generic-script-system fails if just one of those files is missing....

Note: at this cstmr they tend to either request access to some schema or they just pull the free-version from gvenzl (link) and run their own. Creating a database by yourself from scratch is considered a bit last decade...

Of course I have a git-repo with my own scripts as well, but it contains even more scripts. That repo is such a chaos that I didnt even want readers to clone it as I tend to keep older verions of my experiments available as well.

All while doing real-life work-stuff, that remark about a Single Script stuck with me. And I got thinking about Why + How. Here is the Result...


-- Scripts: Why again...

I was +/- succesful after my experiments with the "minimalistic create database", I ended up with a collection of portable scripts for the various sub-tasks. And creating separate scripts made sense to me. I created separate scripts for the following reasons:

- To eliminate hard-coded references to names and paths - Achieved.

- To eliminate repeating pieces of code - Mostly Achieved.

- To use as helper-scripts (accpwd, lock_accounts, and 4_crdb_pdb) - Achieved.

- To monitor, to check state and timing (chk_xzy.sql, sec_cre.sql) - Achieved.

And the additional reason why I appreciate separate these script is something I would call Compartmentalization and Transparency. Each script has its own function, a Specific Job to do. From 1_create via 2_catalog and 3_components to 4_pdbs... 

Also, I can examine and adjust the individual scrips at will.

I especially wanted to maintain that capability for "Inspection and Tweaking", and at first I did not want to complicate life by rolling it all into one script. But the "Idea" was planted. 

Also, in the process of writing those blogs/notes, I had created probably about 100 databases with various versions of the scripts (over a period of months...). With all those "test runs" I had come up with quite a list of notes, mostly included in the comments of the scripts. Some of those notes also merited attention. You will find that there are at least three ToDo lists inside the script still...


-- First part: Generate the scripts, and offer them for Review.

So I went ahead and crafted the One Script anyway and here is the result: C009.sh. (I'm open to suggestions for a better name, but the numbering suits me for now...)

This means you now only need one script to download. That One Script will generate the others.

But with a twist: No Overwriting. If a certain script (filename) already exists, it will be left untouched. This allows you to put your own edits and configs in the scripts and keep those.

And once the main script has detected or generated all the components (a matter of seconds), you can stop it to review the parts before you run them. You can thus edit any of the generated components. And the next run from the same directory will preserve your modifications (unless you removed the generated file...).

Once you are happy with all the components, you can make it "run the lot" and have them create your database.

This "trick" has several benefits:

1) Only one single script to use, but

2) Review and Edit of pieces is possible before the actual run. And

3) The SQL scripts remain separate.

It may seem trivial, but having the SQL-scripts separate keeps them more readable because there is no need to "escape \$" and the set-echo works as expected. This seems like Details. Some ancient SQL-script kids will understand. For me turned out to be very practical.


-- Let's demo...

To start the create-database actions, I rename the script C009.sh to NEWCDB.sh. This rename is the only place where I have to "edit" the new SID name.

I then run the script to let it start the magic....

First the script will tell me about its intentions: It wants to create a database and displays BASE, HOME, SID, host and a timestamp. I can hit enter...

In the example above, the necessary files are already present from an earlier run, located in $ORACLE_BASE/admin/$ORACLE_SID/scripts. The "ls -l" will show me how old these files are, and I pressed "nope <enter>" to allow myself to inspect + edit them.

For example, when not running on the FREE version, I can increase the memory-parameters to claim more memory (and thus run a little faster). Or I can adjust the file-destinations where my data will be placed. See comment in the init.ora.

Once I was happy with the sripts, I re-ran the NEWCDB.sh to start the actual create and I gave it the <enter> to go ahead and create the database.

It started up the instance, using the (generated, edited) init.ora. And then it could proceed with the Real Work:

I still like to see that "Database created" ...  This one took 31 sec.

Once you let it to run.. It will take a while depending on your hardware, but in the end you will end up with a CDB and (by my script-default) two PBs. The end should look similar to this, when the (generated!) script chk_crdb1.sql lists some items:

Notice how I created two PDBs: FREEPDB1 and ORCL.

At then end (total create-process can take a while..) the script does a final query to show the installed components: 

select comp_id, status from dba_registry;

In most cases, all components except RAC will be installed. Note that on the "slim" version of the FREE-containers, some of the create-scripts for java component is missing. When using the "slim" image, you should probably only use the pre-installed (running) database and refrain from creating your own.


-- why so "complicated" ?

I had a few alternatives to take the scripts back into "one main script". 

Firstly, I could execute all commands sequentially. This would lead to a very long script, with a lot of repeated parts. And it would also mean to escape some shell-variables and a lot of v$views with \$VAR and V\$VIEW. Those slashed are not good for readability or maintainability.

Alternatively, I could create functions inside the script and call them to avoid repeating code. Most of those functions would become here-docs, which still meant  careful escaping all kinds of \$VARS and V$VIEWS, still not ideal for readability.

In both cases, the reading and the maintenance of that rather complicated script would become more difficult than keeping the separate scripts that each have a clear task.

So to (more of less) satisfy all parties, I rolled the various scripts into the main one, and then have them Generated when needed, and make them available for "Inspection" before running them.

For myself, I will use the new+improved main script (currently C009.sh) to "generate" the parts and I will probably tweak them. And every now and then, I will roll some of my tweaks and edits back into the main script.


-- Minor improvement: Detect "SID already running"

Sort of speaks for itself. Prevents a lot of messy errors, and prevents possible corruption of existing database. Minor issue. Yeah. Sure.


-- Minor improvement:  Use proper, separated, admin-directories.

Up to now I didnt care about the location of my scripts and files, as most of my tests were hobby/evolving/throw-away runs. But I started to realize that the scripts and the create-logs Do Merit a private directory so the files from different databases remain separate (and do not overwrite eachother ;-) ).

You will now find the essentials after each run in their proper location:

$ORACLE_BASE/admin/$ORACLE_SID/scripts/

In some next version, I should probably also change my current use of /tmp for the output of catcon and catctl. At the time I just wanted to get rid of that huge load of stdout from those programs.


-- "Minor" improvement: ORACLE_SID in UPPERCASE.

When trying out the scripts, I re-discovered that it is just Impractical to have a lowercase SID. I also remember wrestling with that years ago as well. I dont want to go into the details, but at some point I just decided to get it over with and specify Mandatory UPPERCASE for the SID.  

For example (in v26ai):

select * from global name;  Yep, always Upper.

select sys_context ('userenv', 'DB_NAME') from dual;  hmm, lowercase if so specified...

select name for v$database;  Again, always Upper.

Select instance_name from v$instance;  Surprise, lower if so specified.

And there are a number of other places where I found the upper/lower to be inconsistent or confusing.  Maybe a topic for future-blog, or future beer with an Oracle-Veteran: Why didnt Oracle just Force Upper Case as well...?

For PDBs, the issue is already fixed: Uppercase. And I can recommend reading this short blog by Daniel, as he tell you to not push your luck when it comes to naming...

If you feel adventurous: Tweak the script and try the following SIDs on a single machine: ORCL, Orcl, orcl. Then add OrcL and a few other combinations. Enjoy. Thank me later.

To avoid future confusion for now: I just forced UPPER.


-- Remaining lists of "Things ToDo" : Many.

If you look inside the script, you will find many ToDo remarks, some of them still scattered throughout. Those will have to wait. Or remain for others to fix if they feel the need. 

Hence feel free to send me comments, suggestions or criticism.

The item high on my list used to be "cleanup". As I created many test-databases over the last months (for this blog-series alone, probably 100+) and thus I got many test-runs of of the create-script(s), I began to feel the need to "Clean Up" properly: remove datafiles, but also admin-files, $OH/dbs-files, auditing, diag- and trace-files... The Lot. 

And if you are like me, dont pay attention to details and set only the absolute minimum parameters, you end up with overlooked files in several locations. That may be worth a blog all by itself (see e.g. info07_files.sql, maybe later).

But also please note: If you have no exotic requirements and/or just want Efficient "test databases", spin up some containers (link to gvenzl/oracle-free). That is much faster.


-- Summary: One Script... Cool.

After a lot more tweaking than I had anticipated (several evenings...), I did end up with a Single Script. Not quite done yet, not as Elegant as I had wanted yet, but already Happy with the results.

If you take the One Script, you wont have to carry around all the other utilities anymore. But you maintain an easy way to tweak the generated scripts, should you want to.

And while creating the "one script", I have included a few minor improvement, notably to prevent the script from running against an in-place database (and potentially making a big mess).

As for the name... maybe some day I'll call it ONE.sh ?


-- -- -- -- -- End of this blogpost, for now -- -- -- -- -- 


Appendix: That One Script...

C009.sh : The One Script You Need. It is not small, but it is One Single Script. And it provides both scripts for reading- and tweaking, and the Ability to (automatically) Execute.

Try it.

Do Examine the generated scripts...

Run the generated scripts...

Let me know what you think.

 -- -- -- -- -- End of this blogpost, for Real -- -- -- -- --

Wednesday, 8 July 2026

Creating an Oracle 26ai database - Parameters and parameter-files.

TL;DR: The minimum amount of parameters for the init.ora when creating an Oracle 26ai database from scripts.

Simple is better: I'll provide just the bare minimum of parameters. The rest is up to you.

Image: looking inside init.ora. I dont really Want to get into too many details, but then sometimes I couldn't resist either.


-- Background : I now have a set of scripts...

It started as a hobby-project: Create a database from "scripts", as opposed to recovering a Template (link). And I want to keep those script as minimalistic and as portable as possible.

So far, I have tested a one-liner create-statement (not ideal, see link), and I have used scripts generated by the DBCA as examples (better, link). I also have re-worked the DBCA-scripts to be more readable, and to be usable on as many (linux-)machines as possible by removing hard-coded references where possible (link to previous post).

Next, I want to examine the init.ora generated from DBCA, and maybe add a few items from myself. 


-- Parameters files: init.ora, spfile.ora, and dont tweak too much.

Any software needs parameters to tell it how to run, where to run, and where to get/put data. For Oracle, that starts with the "parameter file", either an init<SID>.ora or an spfile<SID>.ora. And for a totally fresh database, it will have to be an init.ora, as the spfile.ora can only be created "from pfile" on a running instance. (We can experiment with editing an spfile, but that seems like a pointless, and definitely unsupported way of doing things - Forget it!)

As for how to provide an example of a parameter file, a competing product has the habit of providing a very large, complete, file with All parameters in it. But with the majority commented out so the system will revert to defaults. The administrator can use such a file to inspect the available parameters and uncomment the parameters they like to experiment with.

Years ago, colleagues+me did the same: we provided an init.ora with lots of commented parameters, and hints on what you could do to Set, Tweak and Troubleshoot if you considered that necessary. Such examples did tend to lead to a lot of hobby-tweaking and un-justified obsessions with parameters that supposedly "had worked at previous client".

Hence this post comes with a Warning: Dont Tweak exotic parameters unless you Know What you are Doing.


-- The location of the parameter files.

By default, Oracle looks for the init<SID>.ora file in the directory $ORACLE_HOME/dbs. 

Note: If you opt for a Read-Only Oracle Home (R/O OH), you will have to provide the files in  $ORACLE_BASE_HOME. The container-images I'm using from the Oracle container repository (link) and from Gerald Venzl (the FREE version, link) are equipped to use it.

Both images use links to a dbconfig-directory to provide for databases where the data-files and the accompanying config (init, spfile, pwd) need to be stored on (mounted) volumes outside of the actual container. I've constructed similar setups, way-back-when, to allow VMs and VBox machines to point to files "on the outside".

<small> 

I've been toying with the idea for a R/O OH, or rather the concept of a "golden image" since my early days as a DBA. Partly inspired by the unix/linux concept of FSH (link). Partly because at several customers, we used to deploy images or tarballs, or just "disk clones" rather than run  the installer on every machine. It was  with Oracle18c that our favorite vendor finally started supporting that with roohctl. 

The container-images which I now use both employ symbolic links to place the parameter files "out of oracle home". I might have some comments on both solutions. But that is something for another blog. I must admit that I have not used (tested) an R/O OH in earnest yet. Something else to test/play with. Later.

</small>

For the moment, I'll just use the old-fashioned $ORACLE_HOME/dbs, and pretend not to know that those files are actually at the end of a symbolic link.


-- First contents of the init.ora : db_name and the file-placements.

For the creation of an Oracle database, we have established that the absolute minimum is an init.ora file with the DB_NAME in it, see the very first blog in this series (link).

From my minimalistic point of view, I would prefer to start and run with as little settings as possible in the init.ora. But I found that I need at least to specify some file-destination parameters.

DB_CREATE_FILE_DEST: I consider this one Mandatory. otherwise my files end up in ORACLE_HOME/dbs, as I noticed on my first attempts (link).

DB_RECOVERY_FILE_DEST: When I specify this at create-time, I will get  multiplexed redo-files and controlfiles. (and if you set this: the setting requires a SIZE spec as well, see example below). 

For the CONTROLFILES, I am open to two options: 

a) Explicitly specify, and preferably put them in the create-destination, as shown in the example below. Or...

b) Dont specify, have them as OMF, and even, lazily, multiply them automatically when using the recovery_dest (I like this, the simplest option)

And when I use the OMF option, I have to add them to the init-file just before generating the spfile (for which I got a script, controlfiles_to_init.sql, with the trick copied from the DBCA-generated files, link below...)

The multiplexing is a Good idea, but only if you really need that. For a simple, disposable, test-system, I prefer to heave just a single copy of redo- and controlfiles. I like to squeeze out those extra (milli)seconds of disk-performance for my test-systems which are often containers running on a developer-laptop.

DIAGNOSTIC_DEST is another important parameter. If left out, you diag-data will end up in $ORACLE_HOME/rdbms/log, and I prefer not to have it there. For containers, I have sometimes sent the diag-data to a mounted volume to have it secure when the container dies. At some time I might elaborate on how I create my containers. Maybe Later.

Here is how I create the top-part my init.ora:

You can see how I "cat" everything into a file, starting with the comment for the date+time.

On CONTROL_FILES: If I leave that out (use dflt) the controlfile will end up in the  db_file_create_dest, or in the ORACLE_HOME/dbs. 

For prod- or otherwise important system, you might want to keep at least two copies of redo- and contrlfiles, one of which should be with the datafiles and the other one in the db_recovery_file_dest (really old discussion, still valid).

Note: It may be a good idea to specify controlfiles explicitly also to prevent sprawling them all over the place. Sometimes you find a old, lost, ctlfile somewhere and wonder how it got there...

So, when I use a recovery-dest, I prefer to use OMF for the controlfiles: that way they get created and replicated automatically to the correct locations. And I really should use controlfile_to_init.sql (link below) very early to prevent me from losing the file(s).

Edit: I just noticed I forgot the  ${ENVVAR} braces around one of the variables in the example. Will fix in script.


-- Init.ora: Notes on memory, process and cursors.

In the init-file generated by DBCA (link below), I found settings for memory and process, some of which seemed derived from the host-machine and some were values I had somehow directly or indirectly specified.

(Note to self : play with DBCA more, try out, verify... )

This prompted me to include the following in my own init.ora:

SGA_TARGET: Specified at 1500m, mostly. Because that value will fit just inside the limits for the FREE version of the software. Specify higher if you have the need for more and the correct (non-free) software.

PGA_AGGREGATE_TARGET: specified at 512m, because I found that to be adequate for most of my (lab/test-)systems.

PROCESSES: Specified at 200, because the dflt of 680 is rather high (for a lab/test-system). I dont quite know yet why DBCA specified 320. Something to look into.

OPEN_CURSORS: specified at 300, because the dflt of 50 is very low, and will almost certainly cause problems.

That leads me to have the 2nd part of the init-ora defined like this:

You may notice I keep the REMOTE_LOGIN_PASSWORDFILE to allow connections from elsewhere, if only to connect with SQLDeveloper. Your preference may vary, but for (lab-)testing environments I like to have that option.

Just one Note, or rather a Question to Oracle: Why are some of the dflt parameters still at values that remind me of 1999? If I dont specify them, I end up with very low values for SGA, PGA_TARGET and OPEN_CURSORS. Low values that make my create-database steps take longer. And those low values make the system almost unsuitable, even for simple unit-testing of database-activity.

For serious PROD systems, I would of course alway re-evaluate those parameters,  and probably add a raft of others to configure and tweak my system for whatever purpose I was creating it.


-- init.ora: a word on the default undo-tablespace.

I can leave out the parameter for UNDO_TABLESPACE. 

The default for this parameter will be (link): the first available undo-tablespace, by whatever name. When I realized this, I found I could even omit the undo-tablespace from the create-database. If no undo-ts is specified, the create-stmnt will default to SYS_UNDOTS, which will then be detected as the first available. 

When I did leave out the undo-tablespace from the initial Create Database, I found I had better resize that dflt SYS_UNDOTS. Or it would end up very tiny at 15M and would be subject to a lot of re-sizing during the create process. Hence I might as well create it with my desired size from the start.

Note: Nearly Every database I know out there uses "UNDOTBS1". I wont blame anyone for using this most-common value. But as a minimalist, out of principle, I stuck to the default ;-)

(note to self: try a funny name like OOPS_UNDO). 


-- init.ora: the parameters you may want to keep, as reminders.

With the parameter above, I think I have covered the bare minimum. I did leave out a few from the generated set that you may want to keep, even if they are initially set to default:

COMPATIBLE: was set to, and defaults to 23.6.0, in my current version of 23.26.1.

NLS_LANGUAGE and NLS_TERRITORY: they default to american/america on my systems, and I didnt see the need to specify them unless I would want non-dflt values (as many of you may want).

The original as it was generated by DBCA (link below) contained a few more settings. Have look and tell me what you think of it.  I kinda liked the (c) notice and the early date. But I also think it could do with a few more improvements. Maybe later.

For now, I was happy with the defaults, some which where specified in the generated file anyway. In your case, you may want to keep some of the generated entries, as reminders and as "prompts" for setting them.


-- Round up: The Minimalistic init.ora.

At this point I have a minimalistic init.ora. And I have sufficient comments (and some notes and more ideas) to use this as a generic example-init in my bare-bones create script.

The init.ora inside C008.sh, the create-database script v8, covers the Essentials: 

DB_Name, 

File-placement, 

Memory, 

Remote_pwdfile.

I could insert more examples and comments. I have some parameters I Want to Set myself (... obsessively). But it would grow into a too-large file. 

At this point, I will stop, and I want to leave room for colleagues to insert their own essential-items and their hobby-parameters. A long, somewhat old-fashioned discussion on init-parameters is for another time+place (and drinks). But from what I sometimes find as non-default parameters in spfiles, often stemming from the looong history of some of the databases out there, I would recommend any DBA-team to do something like a "Yearly review of Parameters."

For now, the minimum provided in C008.sh should get most systems started, and anyone can expand on it. I'll go over the lot once more - I still have a few ideas for tests/plays/improvements. Maybe later.

Try it for yourself.

Enjoy.

-- -- -- -- -- End of this blogpost, for now -- -- -- -- -- 


Appendix A: the links to files.


C008.sh : my latest version to generate a database. Try it.

To complete the creation of a database with my C008.sh, you need the following files in the same directory:

2_crdb_catalog.sql : run the stmnts from CreateDBCatalog.

3_crdb_comp.sql : run the scripts for various components.

lock_accounts.sql : lock the default accounts.

4_crdb_pdb.sql : add a PDB.


And some helper- or utility-files:

chk_crdb1.sql : Inspect a database, if needed immediately after creation.

chk_early.sql : Inspect a database, tablespaces, files.

sec_cre.sql : show the numer of seconds since creation (of the CDB) - I use this to get an idea of timing on various platforms.

controlfile_to_init.sql : add the controlfiles, just before "create spfile" 

And, as someone remarked, you need a file accpwd.sql, where you define your passwords for SYS, SYSTEM and PDBADMIN for use in the scripts. I was too lazy to type passwords in all the time. And often you want your scripts to run without human intervention.


For the curious:

initC003.ora : Generated from DBCA, used as my starting point.

And a link to the DBCA-generated source, from which all scripts were re-written, as documented in an earlier blog (link), here is :

C003_omf2.tar : the tarball with generated files from DBCA.


Note: To simplify further, I might roll all those scripts into a single one. One sh-script to create Your Database...  Would that be useful, or is that over-doing it?

Additional: It may be interesting to discuss how I create containers when I want data to survive (container-)crashes. I tend to mount external volumes for config, for data, and for diagnostic-destinations.

-- -- -- -- -- End of this blogpost, for Real -- -- -- -- --

Wednesday, 1 July 2026

Create an Oracle 26ai database, scripts to add PDBs.

TL;DR: Creating a fresh Oracle 26ai database from scripts: Adding the PDBs to a CDB, and discuss the generated examples from DBCA.

image: the famous analogy of usb-plugins


-- background: I almost have a Database...

The aim is to create a database purely using SQL-statements and portable, re-usable scripts (link to first blog in series). The most simple attempts resulted in databases that were dimensioned way to small. And I still had to include the various scripts for Catalog, Catproc, and the now mandatory components. I had to ask the DBCA for help.

From the DBCA scripts, I have managed to re-write the generated statements to be more generic, more portable. I already got as far as creating a CDB, including the catalog and the various +/- mandatory components (link to previous blog). 

Now it is time to add some PDBs. 

But I have some remarks about the generated plug-scripts.


-- The generated script: lots of actions ? 

When I asked DBCA to generate scripts for a CDB with two PDBs (link), I got 2 x 2  scripts. For each PDB there is a "plug_PDB" and a "postPDBCreation" script, see the ls -l in the screenshot below. The scripts dont look like they were made for readability, but that is not my only remark.

Here is the first part of the generated script that creates the PDB. The empty lines are added by me for readability...

At the top: Should I remark on that spool command, twice ??

But the Create-pluggable command is straightforward, I like the simplicity. It could be done even shorter. As a minimalist, I got it down to:

SQL > Create pluggable database <PDBNAME> 

    admin user <USER> identified by <PWD>; 

Unfortunately, It seems can I not leave out the admin-user clause. But I can re-use the same admin user for every new PDB.

The PDB is created as MOUNTED, and has to be OPENed explicitly. Also, the script will register the PDB immediately with the listener(s) defined in the init or spfile, rather than wait for the max-60sec interval from LREG to do that.

So far so good.


-- Replace the TEMP-orary tablespace ?

The next statements seemed a bit strange to me: First it connects to the new PDB, and that makes sense. Then it selects the CON_ID for the new PDB, and it checks for the BIGFILE property of the TEMP tablespace of the CDB$ROOT. But it does not use that data in any way ? 

Here is the rest of the code (again with white-lines added by me):

There is a little dance to replace a (possibly) existing TEMP tablespace. It does that by adding another Temporary tablespace, then drops and re-creates the (possibly) existing TEMP tablespace for the PDB. And while doing that, it also does CLOSE, OPEN and "register", twice. 

In the end, the PDB is left with exactly the same TEMP tablespace, but now freshly re-created, hence possibly without any ballast or leftover from CDB or SEED? The name of the intermediate temp-tablespace hints at some ENCryption that needs to be added ?

Note-to-self: Find out Why TEMP is replaced.


-- The postPDB actions - USERS tablespace, datapatch, and ... ?

The postPDBcreation looks like this (part 1, white lines added by me): 

The two main actions I detect are 

1) Adding a default tablespace USERS, and 

2) Running datapatch on the new PDB.

The addition of the USERS tablespace is no longer needed here. When I added the creation of "default tablespace users"  into the initial Create Database statement for the CDB, Oracle automatically added a "USERS" tablespace to the SEED as well. From that point on, every new PDB inherited this default-tablespace from the SEED. Hence I could leave it out. Or I can leave it in, and tolerate the error when it happens, just in case someone forgets to add this default tablespace. You choose...

The use of Opatch-datapatch seems recommended, I'll just keep that. As far as I know, datapatch is idempotent, hence it can be run multiple times without negative consequences.

But then it a little gets confusing. Check part 2 of the postPDB script:

The various statements that follow the opatch/datapatch are more mysterious. They seem to only do several verifications (selects...), but I dont really see Why. There are several re-connects, several alter-sessions, and several identical spool-appends. I'll keep the various selects, as they wont hurt ?

And at the end, there are two identical alter-sessions to re-connect to the CDB$ROOT?  Why?

I found this all a bit confusing. Maybe we should ask Oracle for some additional comments at this point.


-- The simplified script: a compromise

From carefully reading both files, plug_PDB and post_PDB, I created one single sql-file: 4_crdb_pdb.sql (link below). You are invited to have a look...

My main change was to remove hardcoded names, and instead use a parameter for the PDB_NAME. I also removed the repeating spool-commands which I thought were unnecessary. 

As a compromise, I kept most of the other statements, including some of the reconnects, the close-and-reopen, the replacement of TEMP, and the alter-system-register commands. 

And I kept the creation of the USERS tablespace, in case I come across a SEED that doesnt have a USERS tablespace yet. 

I still think there are too many comands in the script though. In a later stage, I might try more extensive testing of a smaller, more simple version, notably to avoid the many re-connects. But how often. do you add a fresh PDB to a CDB? In my practice, in most cases, a "new" PDB is a clone or plug-in taken from an existing PBB anyway.

So far, I'm happy with 4_crdb_pdb.sql as it is. The advantage I now have is that my script can be used to quickly add a PDB to any CDB, should I want that. (provided they use OMF. For non-OMF I still need to provide the file-name-convert. But most of mine use OMF. I'm lazy).

In the latest version of script "to create a database", I've added this :

Two simple calls to add two PDBs. Check the script C007.sh in the link below. Go on, Try it.


-- Some Questions on the creation of PDBs.

Q1: Why does the PDB gets created as "mounted"? I suspect there is a (simpole) reason for this, but I havnt seen it, or I have forgotten. I may have to RTFM on this.

Q2: Why the elaborate replacement of the TEMP tablespace? Even if a replacement is desired for some ENCryption reason, this could be done without the reconnects and queries in between ?  (review this? test this?).

Q3: Why are the new Temporary tablespaces of type SMALLFILE ? Is there a particular reason for that ?  (Note: when unspecified, the new tablespace ends up BIGFILE, supposedly because that is specified a default for this CDB)

And I also have a few less burning questions.

Q42: why the explicit close + open + "resister", twice ?? 

Q43: the select-queries to check for con_id and temp-tablespace do not seem to serve any purpose? And they use an upper ( name ), but the pdb-names used are always uppercase anyway, even if initially specified in lowercase ?

Q44: Has anyone managed to create a PDB with a lowercase name ? I know how to create a TABLE with lowercase name, but a PDB??


-- Conclusions so far: We have a Database.

It worked Well. I could use the generated scripts, and create a single, more generic script with a set of commands to create just-any PDB. And the new script Worked Fine as well.

Links  to scripts in appendix below.

But out of all the scripts that the DBCA produced, the two script to create a PDB are the most confusing of the set. They seem to do more actions than striktly required, and the purpose of those actions is unclear to me, as yet.

Should I go on and experiment with Label Security and DataVault? Or first discuss/experiment some init-parameters ? 


-- -- -- -- -- End of this blogpost, for now -- -- -- -- --


Appendix: links to files.

C007.sh : The main script that does "create database" and calls the others. 

2_crdb_catalog.sql : run the stmnts from CreateDBCatalog.

3_crdb_comp.sql : run the scripts for various components.

lock_accounts.sql : lock the default accounts.

4_crdb_pdb.sql : add a PDB.


Plus some helper-scripts I have used in between, they are still embedded in the main scripts, just to provide some info.

chk_crdb1.sql : Inspect a database, if needed immediately after creation.

chk_early.sql : Inspect a database, tablespaces, files.

sec_cre.sql : show the numer of seconds since creation (of the CDB) - I use this to get an idea of timing on various platforms.


And a link to the DBCA-generated source, from which all scripts were re-written, as documented in an earlier blog (link), here is :

C003_omf2.tar : the tarball with generated files from DBCA.

-- -- -- -- -- End of this blogpost, for Real -- -- -- -- --