TL;DR: I've got generated scripts from DBCA (see previous blogs), and I experiment with them. First I morf the initial Create-statement and script into something that is easy to test+repeat. I learn to clean up my own mess. And then I discuss the actual "create database".
image: Creating, Testing, and cleaning up the pieces.
I needed a thorough cleanup-routine to really delete all artifacts of a database for repeat of various tests (and it is not perfect yet...)
-- Background: Got scripts from DBCA, now tweak and re-use them.
My end-goal is still to obtain scripts that can create a fresh database. Scripts that I can take to any (linux) system where oracle is installed, and Create a Database.
It is still a "Hobby Project" and I would not (yet) recommend to take this to your PRODuction system. But anyone should be able to take the scripts and modify them without too much hassle wherever they see fit.
I will use a base-set generated from the DBCA, under the assumption that those are "complete and usable". I already have created a database from them. I will now morf the scripts into something that I can easily re-use.
For portable, generic, scripts, I want first to avoid hard-coded paths. Furthermore, I want "minimalistic" parameters, minimal code, and use defaults wherever I can.
Of course I want scripts that I can quickly adapt to different CDB-names, add PDB-additions, and modify them for various "purpose databbases".
And dont forget: I need a cleanup-system in case my tests need repeating or go horribly wrong: some easy way to "wipe clean". On containers, I can always just re-create the container, but on actual servers I may need to do a cleanup.
-- The Create script: define ORACLE_SID and make it re-runnable.
My first attempts worked OK, and I was able make the very basic statement work:
SQL > Create Database C001;
See previous blogs (link) for the story. But I needed more.
To obtain a complete, usable database with all the required components, I asked for the help of the DataBase Create Assistant. With the proper choices the DBCA from v26ai was able to generate the scripts. And those scripts created a brand new database, including all the "components". Report in Previous blogs on how to generate - (link to generate) and my initial comments on the generated scripts (link to remarks).
Those scripts can still be fetched from the tar file, link below.
In this blogpost, I will use the generated "create" script, and experiment with the very start of the process: the Create itself. Slowly, I'm developing a more generic, less "hardcoded", more portable version of the scripts.
Originally, the DBCA provided a script that calls everything: C003.sh. I've re-worked that to a sh-script where the base-name is the SID. I expect to "test" this a lot, so I better make it easily-runnable and re-runnable.
I came up with C004.sh as a main-controlling script for my next database:
This way I grab the SID, upper and lowercase to access the subdirs in diagnostic-dest. And I will consider to define items like DATA_DEST, BASE, HOME, and others as well at the top of the script.
Next is the "editing" of the init-ora file. This can happen inside the sh-script to allow the DB_NAME and a few other parameters to be set. Let's use an <<EOF for that:
I'll just create the init file on the fly, from the same script. Keep everything in one place for now. A more detailed discussion of the init-file contents will have to wait. Maybe later.
-- The actual Create Database, adjusted from the DBCA.
After just a little formatting, I inserted the statement from CreateDB.sql in my script:
This statement is still the same one as generated by DBCA, but it uses the ${ORACLE_SID} instead of the hardcoded value. Otherwise it is un-altered (as of yet). I have used this in various tests to try some variations.
Once I could easily re-run this statement, I started experimenting with some modifications.
-- Initial sizing of datafiles and logfiles.
From looking at the previously created C003 (previous blog), I know that the nr of "Resize operations" during create was 200+. Mostly because the initial fileSIZE and the NEXT specifications were too small, especially on the SEED-datafiles. I'll add larger values to the next version of the create-statement. Check C005.sh linked below.
For the redo-log files, I preferred 500M size or even larger to reduce log-switches during busy times. I think there is very little downside to Large redo files. If you worry about delay between log-switches, or delay in archive-generation: use an archive_lag_target and re-think your backup- or DG-settings. Maybe Discuss some other time.
I also managed to include size-specifications for the SEED: system and sysaux, both to eliminate the resize-ops during the running of catalog and other scripts, and to allow future sizes should someone want that. All for the next version of the script.
The qualification: Extent Management Local: if I leave that out, the SYSTEM tablespace becomes DICTIONARY managed. Not a big problem, but rather old-skool. If you want to have your SYSTEM tablespace as LMT, you have to specify this explicitly.
I suspect I know the reason why the default for SYSTEM is still Dictionary: If you have older databases with Dict-magaged tablespaces that you want to plug in, you need the SYSTEM of the CDB to be Dictionary managed as well (note: maybe check this, Dict-managed is really old...).
-- Various MAX-values, affecting the Controlfile - Let's test.
I was slightly worried when I noticed the MAX-parameters in the generated script. You can find them via V$CONTROLFILE_RECORD_SECTION. In older versions, those MAX-values used to be imposed as "Limits" and sometimes bit you when you didnt expect. Anyone who ever had to "re-create a controlfile" under stress will remember. Nowadays, they mainly determine the space that gets "reserved" in the controlfile, and the space will "expand" automatically when needed.
I did a quick test:
First I re-created a database with no MAX values specified and I checked the values in V$CONTROLFILE_RECORD_SECTION using the script chk_ctlrecords.sql (link below).
Those initial, default values look a little low to me. Could that pose a problem?
(Anyone spot the anomaly? something to look into? Maybe Later)
So I created a shell-scrpt to add redo-files, add threads and add tablespaces (e.g. datafiles). I tried to "cross those limits" and see what happened with this test: add_files.sh (link to script below).
And after adding a load of files, I re-check the values:
The values have simply gone up. No problems encountered. That looks Good to me.
Actually, if you have run the catalog script, the alert-log will contain a few messages about expanding the ctlfile:
From reading the RTFM, you may want to keep the MAXLOGHISTORY if you are running RAC. Maybe something for another test.
My first conclusion is: Those MAX values are there for information, but they dont seem to pose a problem anymore. And I will remove them to simplify my create-statement a little further.
-- Leave out some more options...? Maybe Not.
Since I like "minimal scripts", I have considered to also leave out the spec of SYS and SYSTEM passwords, and the Character-sets.
When I left out the Char-set spec, I ended up with US7ASCII. Not a good idea.
I found I could leave out the National Character set as it seems to defaults to AL16UTF16 anyway, but I decided to keep it in as reference. Feel free to change those at your convenience...
You could also leave out the SYS and SYSTEM IDENTIFIED BY. But the RTFM says you will then revert to the very old and well known defaults. To make it look good to your CISO and SecOps ppl, just specify them.
In my case, I usually have the passwords defined in a file that I name "accpwds.sql". During create-time: it mimics the sqlplus-accept command to define the pwds. Just dont upload that file to any git-repo, and dont stick with those values for too long. Hmm, Maybe I'll also mention in a later blog that some of the scripts still can display the pwd-value in the proces-listing, try "ps -ef" to check for yourself.
-- Cleanup, because of all the failed or insufficient (test-) runs...
While building and testing the scripts, and experimenting with the rest of the generated scripts, I often ran into error where files already existed (example:.... ).
Hence I needed a (semi-automatic) cleanup-script as well. This is slightly risky to have laying around: if you accidentally execute that script, it Wipes your Database. Hence semi- and not totally automatic.
The cleanup scripts, an -.sh and an -.sql, find all possible files from the v$ views (the dba_% views only come in after the catalog is created), and generate the rm-commands. They also try to clean up the diag-dest and other file-destinations. Links below.
Feel free to re-use, but be careful. This is not something you want to happen by accident (yes, this happened to me once, in summer of 1996. And I still remember 30yrs later, colleagues HenkG and YuriB, and some customer-ppl will also remember....).
-- Some Questions for Oracle...
Non-critical, but out of curiousity, I will probably try to ask Oracle-folks at some time about the following Items...
1. LMT/Dictionary: Why is the dflt for SYSTEM tablespace still DICTIONARY ? (presumably for compatibility with Really Old tablespaces that need to be plugged in?)
2. Sizing: Why are the initial tablespaces (SYSTEM, SYSAUX, TEMP, and SYS_UNDO) created with such small values for SIZE and NEXT? They are Very Small on the "naked" create-statement (see previous blog, link) but even on the generated-scripts the values are still low and generate a lot of "resize" events in the alert-log?.
3. Controle-file contents: Why are the MAX-values still specified when these are (probably) no obstacles to a growing databases anymore ? Leaving them out, at least in the generated scripts, would make the create-stmnt more simple, elegant?
More questions ? dflt charsets? dflt-passwords? maybe later...
Round up, my Create Database is somewhat improved (simplified)
Quite Happy with the new script: it works for me. Have a look at C005.sh (link below)
I have the init.ora and the create-statement in One Single place. I can now easily create databases with other ORACLE_SID-values. And I can add all the other items from the DBCA-generated code such as catalog, scripts for the various components, and the creation of pluggable-databases. Stay tuned as I continue exploring.
The "cleanup" script to remove files is a little risky, but has proven very useful.
I also know now that some of the definitions at create-time are not Set in Stone (maxfiles...), and I feel confident that I can run with the defaults, rather than having to enter defensively large values at Create-Time. If needed, Oracle will automatically "increase the max" of some of them and the alert-file will show the expand-messages.
Next episode, I want to add the Catalog and run all the other scripts that the DBCA listed. I will try to simplify them a little. Notably to remove some of the hardcoded setting like SID and PATHs.
-- -- -- -- -- End of this blogpost, for now -- -- -- -- --
Appendix 1: Links to scripts and files.
C001.sh : my first example, a single, self-contained script to create a database.
C003_omf2.tar : the generated script from DBCA (with fix for the missing arguments to context.sql...)
C004.sh : a shell script with my "first improvements", runnable. test-able
chk_ctlrecords.sql : list part of the v$contrlfile_record_section.
add_files.sql : Add redo-files, redo-threads and tablespaces to expand controlfile.
mk_rmall.sh : generate rm-script and shutdown-abort the instance.
mk_rmall.sql : sql-file is needed by the mk_rm_all.sh script (for now...)
C005.sh : my "final" create-statement (for now)
-- -- -- -- -- End of this blogpost, for Real -- -- -- -- --













































