Tuesday, August 22, 2023

Cause and solution to ORA-00058: DB_BLOCK_SIZE must be 8192 to mount this database (not 16384)

You attempt to execute dbca silently, using a response file, as shown below:
dbca -createDatabase -responsefile mydb01.rsp -silent
But it errors out with the error:
[WARNING] ORA-00058: DB_BLOCK_SIZE must be 8192 to mount this database (not 16384)
and the instance is left running, with an unmounted database.

Cause:

This means you are using a pre-defined template for dbca that includes datafiles.

When you do this, you cannot change the db_block_size. It is set to 8K, and carved in stone.

Solution:

Create your own, customized template and refer to that instead.

Remember that templates ending with the extension .dbc contains database files, so they will be significantly faster to use, than custom made templates ending with the extension .dbt - the latter will have to go through the "CREATE DATABASE" statements from scratch.

Templates that do not contain datafiles have the extension .dbt

What you can do in order to have your cake and eat it, too, is to first create a database with a non-confirming db_block_size, then create a dbca template based on this new database, including its datafiles.

I will see if I have time to write a blog post about how to do extactly this.

Tuesday, August 15, 2023

Simple PL/SQL script to alter parameter in database

At my current workplace, we use emcli for mass-updates of database parameters in groups of databases.

Below is a simple PL/SQL script that can be used to change parameter if needed. If the parameter is already set, nothing happens.

In my case, it was the parameter "recyclebin" that was needed to be switched from OFF to ON for some databases, but it could be any parameter.

Surely there are many ways to solve such a problem, this was how I solved it with very little effort :-)
set serveroutput on
set feedback off
set echo off
set verify off

DECLARE

 v_db_name v$database.name%%TYPE;
 v_rb v$system_parameter.name%%TYPE;


BEGIN
 execute immediate 'alter session set nls_language=''american''';
 select name
 into v_db_name
 from v$database;

 select value
 into v_rb
 from v$system_parameter
 where name = 'recyclebin';
 
--dbms_output.put_line('v_db_name: ' || v_db_name);
--dbms_output.put_line('v_rb:      ' || v_rb);

CASE
   WHEN v_rb = 'ON' THEN
    dbms_output.put_line('Database ' || v_db_name || ': recyclebin already enabled.');
   ELSE
    dbms_output.put_line('Database ' || v_db_name || ': recyclebin is currently disabled. Turning it on now...');
    execute immediate 'alter system set recyclebin=ON scope=spfile';
     dbms_output.put_line('Database ' || v_db_name || ' now has recyclebin=ON in spfile. Database must be bounced in in order to enable the setting');
   END CASE;
END;
/
exit
When we execute the script through emcli, the syntax comes to:
emcli execute_sql -sql="FILE" -iemcli execute_sql -sql="FILE" -input_file="FILE:/scripts/chk_and_alter_param.sql" -targets="TEST_DBS:composite"

Friday, August 4, 2023

How to trace the dbca tool

These notes are taken directly from MOS, and jotted down here so I have it readily available for the future.

To trace the DBCA, we need to perform the following.

1. Do a copy of the original dbca file in $ORACLE_HOME/bin. For example:
cp $ORACLE_HOME/bin/dbca $ORACLE_HOME/bin/dbca.ori
2. vi the dbca file in the $ORACLE_HOME/bin directory.

3. At the end of the file, look for the following line:
# Run DBCA
$JRE_DIR/bin/jre -DORACLE_HOME=$OH -DJDBC_PROTOCOL=thin -mx64m -classpath $CLASSPATH oracle.sysman.assistants.dbca.Dbca $ARGUMENTS
4. Add the following just before the -classpath in the '$JRE_DIR' line:
-DTRACING.ENABLED=true -DTRACING.LEVEL=2
5. At the end of the dbca file, the string should now look like this:
# Run DBCA
$JRE_DIR/bin/jre -DORACLE_HOME=$OH -DJDBC_PROTOCOL=thin -mx64m -DTRACING.ENABLED=true -DTRACING.LEVEL=2 -classpath $CLASSPATH oracle.sysman.assistants.dbca.Dbca $ARGUMENTS
6. To trace, run:
[host]/u01/home/usupport> dbca > dbca.out >
The output will be written to the dbca.out file.

Thursday, August 3, 2023

Script to check the services in a multitenant container databaser

A simple script to check services running out of a specific PDB, or for all PDBs if the root container is selected:
column pdb_name format a20
column status format a20
prompt
prompt List of PDBs available on this server:
prompt
select p.pdb_name
from dba_pdbs p join v$pdbs v
on (p.pdb_id = v.con_id)
where open_mode='READ WRITE'
/

accept pdb_name DEFAULT 'CDB$ROOT' prompt 'Select a PDB (default=root container): '
alter session set container=&&pdb_name;
col con_name format a40
set lines 200
select 'You are connected to: ' || sys_context('USERENV','CON_NAME') "con_name"
from dual;

col name format a20
col global format a20
col pdb format a20
col con_name format a20
col network_name format a20
col creation_Date format a20
prompt V$SERVICES
select name,global,pdb,network_name from v$services
/

prompt V$ACTIVE_SERVICES
select name,global,con_name,network_name from v$active_services
/

prompt DBA_SERVICES
select service_id,name,network_name,creation_date,pdb
from dba_services
/

prompt CDB_SERVICES
select service_id,name,network_name,creation_date,pdb
from cdb_services
/
exit

Wednesday, August 2, 2023

What are the DST time zone files ?

What are the Oracle Time Zone files?
The Oracle Database time zone files contain the valid time zone names. The following information is also included for each time zone:

* Offset from Coordinated Universal Time (UTC)
* Transition times for Daylight Saving Time
* Abbreviations for standard time and Daylight Saving Time
Where do these timezone files exist?
The time zone files are stored in the $ORACLE_HOME/oracore/zoneinfo directory.  

Oracle Database supplies multiple versions of time zone files, and there are two types of file associated with each version:

* a large file, which contains all the time zones defined in the database
* a small file, which contains only the most commonly used time zones. 

The large version files are named as timezlrg_version_number.dat and the small version files are named as timezone_version_number.dat, where version_number is the version number of the time zone file. 
What is the default timezone file?
The default time zone file is a large time zone file having the highest version number [ that was delivered when the Oracle software was installed].
For Oracle 19c, the default is DST32:
In Oracle Database 19c, the default time zone file is $ORACLE_HOME/oracore/zoneinfo/timezlrg_32.dat.
How do I determine what timezone files that are in use in my database?
select * from V$TIMEZONE_FILE;

FILENAME                VERSION     CON_ID
-------------------- ---------- ----------
timezlrg_32.dat              32          0
How do I find the database time zone?
SELECT dbtimezone FROM DUAL;

DBTIME
------
+00:00
When is the database time zone set?
Set the database time zone when the database is created by using the SET TIME_ZONE clause of the CREATE DATABASE statement. 
If you do not set the database time zone, then it defaults to the time zone of the server's operating system.

The time zone may be set to a named region or an absolute offset from UTC. 

To set the time zone to a named region, use a statement similar to the following example:

CREATE DATABASE db01
...
SET TIME_ZONE='Europe/London';

To set the time zone to an offset from UTC, use a statement similar to the following example:

CREATE DATABASE db01
...
SET TIME_ZONE='-05:00';
What operations are affected by the database time zone?
The database time zone is relevant only for TIMESTAMP WITH LOCAL TIME ZONE columns. Oracle recommends that you set the database time zone to UTC (0:00) to avoid data conversion and improve performance when data is transferred among databases. This is especially important for distributed databases, replication, and exporting and importing.

If you do NOT use NAMED Timezone information in your application(s) you are not using the Oracle DST information and Oracle DST patches have simply no impact on your system.
You may apply Oracle DST patches, but the Oracle DST information is simply not used.
Will the time zone files be updated during quarterly patching?
Starting with Oracle Database 19c RU 19.18.0, all available DST patches are installed with the RU, and deployed into the Oracle_home/oracore/zoneinfo directory. 
Installing DST patches does not affect database operation.
How are the time zone files delivered?
Each Oracle Database release includes a time zone file that is current at the time of the release and a number of older version files. 

The time zone files that are supplied with the Oracle Database are updated periodically to reflect changes in transition rules for various time zone regions.
Between Oracle Database releases, new time zone file versions may be provided in patch sets or individual patches to reflect the changes in transition rules for various time zone regions. 
Older time zone file versions allow you to run upgraded databases without a need to immediately upgrade the time zone file to the most current version.
Is the update of the DST time zone files absolutely necessary? In many cases, not at all.

The MOS note "Primary Note DST FAQ : Updated DST Transitions and New Time Zones in Oracle RDBMS and OJVM Time Zone File Patches (Doc ID 412160.1)" states:
Please DO note that even if you are located in a country that has changed the DST start or end day, in many cases there is no need to "update the Oracle RDBMS DST information".
If your OS has been patched or correctly configured the the "oracle time" (= sysdate) will be correct.
Only if the actual timezone is used in (PL)SQL an "Oracle RDBMS DST" update is needed.
What about multitenant?
  • Each container in a multitenant environment has its own time zone file
  • Oracle allows different containers to have different time zone file versions, so you have the option of upgrading only a subset of containers in a CDB
  • To perform a time zone data upgrade across an entire CDB, you must upgrade the CDB root and each PDB separately.
  • A new PDB is always assigned the time zone version of PDB$SEED.
  • PDB$SEED is always assigned the time zone version at the time of CDB creation.
  • The time zone version of PDB$SEED cannot be changed.
  • Documentation:

  • Choosing a Time Zone File
  • Upgrading the Time Zone File and Timestamp with Time Zone Data
  • All Time Zone Files (DST) Included in Release Updates (RUs)
  • Thursday, July 27, 2023

    How to list the contents of a folder in a tree-like fashion in Linux

    Use the tree command:
    cd /sw/oracle/admin
    tree -L 2
    .
    ├── cdb
    │   ├── adump
    │   ├── dpdump
    │   ├── log
    │   ├── pfile
    │   └── xdb_wallet
    ├── sales
    │   ├── adump
    │   ├── dpdump
    │   ├── pfile
    │   ├── sql
    │   └── xdb_wallet
    └── hr
        ├── adump
        ├── dpdump
        ├── log
        ├── pfile
        ├── scripts
        ├── sql
        └── xdb_wallet
    
    20 directories, 0 files
    
    The -L flag indicates the number of levels you want to display. In my case, if I change the value from 2 to 3, I get the output below instead (abbreviated):
    .
    ├── cdb
    │   ├── adump
    │   │   ├── FE78BD1F8E6730CDE0536709D10AC9C0
    │   │   └── FE7BD04D2DFBE569E0536709D10A3AF0
    │   ├── dpdump
    │   │   ├── dp.log
    │   │   ├── FE78BD1F8E6730CDE0536709D10AC9C0
    │   │   ├── FE7AF28B415262F7E0536709D10A8B2E
    │   │   └── FE7BD04D2DFBE569E0536709D10A3AF0
    │   ├── log
    │   │   ├── 2023-07-11_cdb.2431565
    │   │   ├── 2023-07-12_cdb.2489915
    │   │   ├── 2023-07-12_cdb.2576176
    ├── sales
    │   ├── adump
    │   ├── dpdump
    │   │   └── dp.log
    │   ├── pfile
    │   │   └── init.ora.5192023145034
    │   ├── sql
    │   │   ├── analyze_sales.sh
    │   │   ├── cfgtoollogs
    │   │   ├── config_sales.txt
    │   │   ├── cre_db.sh
    │   │   └── deploy_sales.sh
    
    26 directories, 181 files
    
    The command is not installed by default but is avaible both for RHEL / CentOS / Fedora Linux as well as Debian based Linux distributions like Ubuntu.

    Monday, June 26, 2023

    How to show current utilization of sessions, processes and other important settings for a database

    Example:
    set lines 300
    col RESOURCE_NAME format a30
    select RESOURCE_NAME,CURRENT_UTILIZATION,MAX_UTILIZATION,INITIAL_ALLOCATION,LIMIT_VALUE
    from v$resource_limit
    where resource_name in ('processes','sessions');
    
    RESOURCE_NAME                  CURRENT_UTILIZATION MAX_UTILIZATION INITIAL_ALLOCATION     LIMIT_VALUE
    ------------------------------ ------------------- --------------- ---------------------- ---------------
    processes                                     1498            1500       1500             1500
    sessions                                      1511            1517       2272             2272
    
    Documented for Oracle 19c here