Tuesday, September 26, 2023

What are dbca templates and how do they work?

What are dbca templates? 

Database Configuration Assistant (DBCA) templates are XML files that contain information required to create a database.

What are templates used for? 

Templates are used in DBCA to create new databases and duplicate existing databases. 

What information does a template contain?

The information in templates includes database options, initialization parameters, and storage attributes (for data files, tablespaces, control files, and online redo log files). 

Are there different types of templates?

Yes:
Type File extension Includes Data Files Database Structure Configurable?
Seed .dbc Yes
  • contains both the structure and the physical data files of an existing database, referred to as the seed database.
  • The data files for the seed database are stored in compressed RMAN backup format in a file with a .dfb extension.
  • The seed database control file is stored in a file with .ctl extension
  • The .dbc file contains the location of the seed database data files and contains the source database name used to mount the control file.
  • No
    nonseed .dbt No This type of template is used to create a new database. It contains the characteristics of the database to be created.
    Nonseed templates are more flexible than their seed counterparts because all data files and online redo log files are created to your specification, and names, sizes, and other attributes can be changed as required.
    Yes

    Why use templates? 

    Templates can be used just like scripts, but they are more powerful than scripts because you have the option of duplicating a database. Duplication saves time because you copy the files of an existing database, referred to as a seed database, to the correct locations.

    When using templates, beware of the following:

    1. Database options (for example, Data Vault or Spatial) can be configured or modified only for a custom database or nonseed template (.dbt file).
    2. You cannot modify database options for a seed template (includes data file backups).
    3. Using a seed template is a much quicker operation, than using a non-seed template, but less flexible.

    What templates are delivered with a standard Oracle 19c software installation?

    Upon completion of an Oracle 19c software installation, you will find the following files in the directory $ORACLE_HOME/assistants/dbca/templates:

  • New_Database.dbt
  • Seed_Database.dfb
  • Seed_Database.ctl
  • Data_Warehouse.dbc
  • General_Purpose.dbc
  • pdbseed.xml

  • They are used by the different templates:
    Template Workload Files used
    Data warehouse Users perform numerous, complex queries that process large volumes of data. Seed_Database.dbf
    General Purpose or Transaction processing Many concurrent users perform numerous transactions that require rapid access to data. Seed_Database.dbf
    Custom database Allows for maximum flexibility in defining a database; you can change any of the settings for the database being created. New_Database.dbt
    Both the Data_Warehouse.dbc and the General_Purpose.dbc are pointing to the Seed_Database.dbf when they are used, which means they will be create a database for you quickly but you will have to accept the options and standard given by the template


    Documentation:
    2.3.5 Managing Templates with DBCA

    Friday, September 22, 2023

    How to remove the Oracle Workspace Manager component from an Oracle database

    I have installed a database through dbca, unchecking all the options boxes when going through the setup wizard:









    Upon completion, there is still a component left that I do not want to have installed: the Oracle Workspace Manager.
    It is registred in the database's registry:
    SYS@orcl>SQL>SELECT COMP_NAME,COMP_ID,VERSION,STATUS FROM DBA_REGISTRY;
    
    COMP_NAME                                COMP_ID                        VERSION                        STATUS
    ---------------------------------------- ------------------------------ ------------------------------ ----------------
    Oracle Database Catalog Views            CATALOG                        19.0.0.0.0                     VALID
    Oracle Database Packages and Types       CATPROC                        19.0.0.0.0                     VALID
    Oracle Real Application Clusters         RAC                            19.0.0.0.0                     OPTION OFF
    Oracle XML Database                      XDB                            19.0.0.0.0                     VALID
    Oracle Workspace Manager                 OWM                            19.0.0.0.0                     VALID
    
    To remove the OWM component:
    SYS@orcl>SQL> @?/rdbms/admin/owmuinst.plb
    
    Session altered.
    
    PL/SQL procedure executed.
    
    PL/SQL procedure executed.
    
    Session altered.
    
    Option is now deinstalled:
    SYS@orcl>SQL>SELECT COMP_NAME,COMP_ID,VERSION,STATUS FROM DBA_REGISTRY;
    
    COMP_NAME                                COMP_ID                        VERSION                        STATUS
    ---------------------------------------- ------------------------------ ------------------------------ ------------------
    Oracle Database Catalog Views            CATALOG                        19.0.0.0.0                     VALID
    Oracle Database Packages and Types       CATPROC                        19.0.0.0.0                     VALID
    Oracle Real Application Clusters         RAC                            19.0.0.0.0                     OPTION OFF
    Oracle XML Database                      XDB                            19.0.0.0.0                     VALID
    
    What exactly is the OWM ?

    In a nutshell, it's a version tool for data within a schema. It has been around since Oracle 9i

    See documentation here

    Particulary the whitepaper

    Check out Tim Hall's article on oracle-base.com about the subject.

    Thursday, September 14, 2023

    How to install an extension in a postgreSQL database

    Are the desired extensions available in our installation?
    [postgres@myserver.no ~]$ echo "SELECT * FROM pg_available_extensions;" | psql | egrep 'cube|earthdistance';
     cube               | 1.5             |                   | data type for multidimensional cubes
     earthdistance      | 1.1             |                   | calculate great-circle distances on the surface of the Earth
    
    Yes they are.

    Source : https://www.postgresql.org/docs/current/view-pg-available-extensions.html

    Connect to the relevant database and create the extensions in the schema you want them:
    postgres=# \connect mydb1
    You are now connected to database "mydb1" as user "postgres".
    mydb1=# create extension if not exists cube with schema myschema1 cascade;
    CREATE EXTENSION
    mydb1=# create extension if not exists earthdistance  with schema myschema1 cascade;
    CREATE EXTENSION
    mydb1=# exit
    
    
    Check if they have indeed been installed:
    [postgres@myserver.no ~]$ psql mydb01
    psql (15.4)
    Type "help" for help.
    
    sit1=# \dx
                                                    List of installed extensions
            Name        | Version |       Schema        |                              Description
    --------------------+---------+---------------------+------------------------------------------------------------------------
     cube               | 1.5     | myschema1           | data type for multidimensional cubes
     earthdistance      | 1.1     | myschema1           | calculate great-circle distances on the surface of the Earth
     pg_qualstats       | 2.0.4   | public              | An extension collecting statistics about quals
     pg_stat_statements | 1.10    | public              | track planning and execution statistics of all SQL statements executed
     plpgsql            | 1.0     | pg_catalog          | PL/pgSQL procedural language
    (5 rows)
    

    Create extension is documented here

    Solution for [WARNING] ORA-01081: cannot start already-running ORACLE - shut it down first when running dbca

    I received the following error multiple times, when executing dbca like below:
    dbca -createDatabase -responsefile ./cdb.rsp -silent
     2023-09-14 15:05:45.435 CEST ] Prepare for db operation
    DBCA_PROGRESS : 10%
    [ 2023-09-14 15:05:45.505 CEST ] Copying database files
    DBCA_PROGRESS : 12%
    [ 2023-09-14 15:05:47.250 CEST ] [WARNING] ORA-01081: cannot start already-running ORACLE - shut it down first
    
    DBCA_PROGRESS : 40%
    DBCA_PROGRESS : 100%
    [ 2023-09-14 15:05:47.616 CEST ] [FATAL] Recovery Manager failed to restore datafiles. Refer logs for details.
    DBCA_PROGRESS : 10%
    DBCA_PROGRESS : 0%
    
    At first I thought it was because I had forgotten to terminate some processes owned by oracle. And I also made sure that /etc/oratab was empty before I started.

    Reason:

    Turns out, there were old memory segments left behind that dbca considers a part of a running instance. Even if
    ps -fu oracle
    
    gave no processes in the list.

    Solution:
    su - oracle
    sqlplus / as sysdba
    shutdown abort
    
    Given that you've set ORACLE_SID to the same value you used in your response file, this will properly shut down your instance, and clean up the memory segments left behind from the previous run.

    Tuesday, September 12, 2023

    How to delete a pluggable database with dbca using the command line

    dbca -silent -deletePluggableDatabase \
    -sourceDB cdb \
    -pdbName pdb3 \
    

    How to create a pluggable database with dbca using the command line

    In the following code snippet, I am creating the pluggable database "pdb3" as a copy of the already existing pluggable database "pdb1":
    dbca -silent -createPluggableDatabase \
    -sourceDB cdb.skead.no \
    -pdbName pdb3 \
    -sourcePDB pdb1 \
    -createPDBFrom PDB \
    -pdbDatafileDestination "/dbfiles/oradata/cdb/pdb3/" \
    -pdbAdminPassword mysecretpassword1 \
    -sysPassword mysecretpassword2 \
    -systemPassword mysecretpassword3 \
    
    If you want to use the SEED database as source instead of an already existing database, remove the directive
    -sourcePDB pdb1 \
    
    and use this directive instead:
    -createPDBFrom DEFAULT \
    
    Source: Oracle 19c documentation

    Friday, September 8, 2023

    Script for creating a multitenant database with dbca

    Prerequisites:
  • You have a valid Oracle 19c installation in a server
  • You have set your Oracle environment already, so that your PATH, ORACLE_SID etc already exists when you execute your script

    The script called run_dbca.sh:
    #!/bin/bash
    start=$(date +%s.%N)
    export GLOGFILE=run_dbca.log
    touch ${GLOGFILE}
    chmod 666 ${GLOGFILE}
    exec 1> ${GLOGFILE} 2>&1
    echo "Now running run_dbca.sh"
    echo "Resetting oratab..."
    echo '' > /etc/oratab
    if [ $? -ne 0 ]; then
     echo "Could not erase oratab. Exit."
     exit 1
    else
     echo "oratab erased. Continuing..."
    fi
    export instanceAlive=`ps -ef| grep pmon | grep -v grep |awk '{ print $8}' | cut -f 3 -d"_"`
    
    if [ ! -z ${instanceAlive} ]; then
     echo "Instance for database $ORACLE_SID is already running. Shut it down first"
     exit 1
    fi
    dbca -createDatabase -responsefile ./${ORACLE_SID}.rsp -silent
    echo "Finished running run_dbca.sh"
    dur=$(echo "$(date +%s.%N) - $start" | bc)
    printf "Total execution time for run_dbca.sh: %.6f seconds\n" $dur
    exit 0
    
    The response file can be seen below. I saved it in a file called cdb.rsp and put it in the same directory.

    I commented out most instructions, as they are not needed.

    The original template db_install.rsp is delivered by default with your oracle installation and resides in your $ORACLE_HOME/install/response.
    #-------------------------------------------------------------------------------
    # Do not change the responseFileVersion diretive!
    #-------------------------------------------------------------------------------
    responseFileVersion=/oracle/assistants/rspfmt_dbca_response_schema_v19.0.0
    gdbName=cdb.oric.no
    sid=cdb
    createAsContainerDatabase=true
    numberOfPDBs=1
    pdbName=pdb1
    useLocalUndoForPDBs=true
    pdbAdminPassword=mysecretpassword
    templateName=New_Database.dbt
    sysPassword=mysyspassword
    systemPassword=mysystempassword
    datafileDestination=/data01/oradata/cdb
    recoveryAreaDestination=/data02/fra
    characterSet=AL32UTF8
    initParams=max_pdbs=3,db_create_file_dest_size=1024GB
    memoryPercentage=75
    automaticMemoryManagement=false
    enableArchive=true
    redoLogFileSize=2048
    dbOptions=JSERVER:false,DV:false,ORACLE_TEXT:false,IMEDIA:false,CWMLITE:false,SPATIAL:false,OMS:false,APEX:false
    
    Execute the script like this:
    ./run_dbca.sh
    
    Follow the progression of the creation in the log run_dbca.log:
    tail -f run_dbca.log
    
    Sources:

    Oracle 19c documentation: About creating a database with dbca

    Oracle 19c documentation: Managing templates with dbca

    Oracle-Base.com: Multitenant : Create and Configure a Pluggable Database (PDB) in Oracle Database 12c Release 1 (12.1) - still a relevant and good source.

    Oracle-base.com: a dbca template

    Oracle-base.com: Database Configuration Assistant (DBCA) : Creating Databases in Silent Mode