DBA_INDEXES and DBA_SEGMENTS mismatch

This is a fun one.

We developed a script to process certain indexes on a database somehow, it kept missing some of the indexes that clearly existed. We then found the problem: DBA_INDEXES had more entries than DBA_SEGMENTS. See the following example:

SQL> SELECT owner, index_name as i_name from dba_indexes WHERE owner = 'SIMON'
  2  MINUS
  3  SELECT owner, segment_name as i_name FROM dba_segments WHERE owner = 'SIMON';

OWNER                I_NAME
-------------------- --------------------------------------------------
SIMON                IDX_...
SIMON                IDX_...
SIMON                IDX_...
SIMON                PK_...
SIMON                PK_...
SIMON                UNQ_...
SIMON                UNQ_...

7 rows selected.

So here we see that there are clearly indexes for which there are no segments. We then looked at the tables where these indexes are located and noticed a particular thing: All the corresponding tables for these indexes were empty.

So the reason for this behaviour is called “Deferred Segment Creation“. This means that when a “CREATE TABLE” statement is issued and no rows are inserted, there are no segments that are created. This behaviour can be controlled by the DEFERRED_SEGMENT_CREATION parameter.

This makes sense in large schemas, where not all tables are populated. Instead of having segments created and extents allocated, only the definition of the table is saved. As soon as the table has at least one row, the segments are automatically created.

Find password for database link

Alright, so when we need to recreate a database link for some reason and we do not happen to have the password handy, we’re usually stuck. However, sometimes there is a way to recover passwords for database links. Unfortunately, the method described below only works for the “old” password versions (<= 11.2.0.2)!

Read the rest of this entry »

RMAN “set until time” example

So here is another post I will keep just for my own reference.

Whenever I need to perform an incomplete recovery of the database, I usually use the SET UNTIL TIME to specify the time for an incomplete recovery. Sadly, when NLS_LANG is not set properly, the time format that needs to be used is not something I can remember.

So here is an example for using SET UNTIL TIME with a sane time format:

run {
set until time "to_date('22-APR-2015 13:30:00','DD-MON-YYYY HH24:MI:SS')";
restore database;
recover database;
alter database open resetlogs;
}

You can find more examples in the Oracle documentation.

csqlplus: New website

Last week, I launched a new website for my csqlplus project.

What is csqlplus, you might ask. The csqlplus script is a wrapper for SQL*Plus and will allow you to query multiple databases at once, so bascially a SQL*Plus for clusters:

Often, Oracle database administrators need to run commands on multiple databases at once. With csqlplus, a wrapper for the sqlplus command, a DBA can quickly query multiple databases simultaneously.

Basically, csqlplus is a simple wrapper script to call sqlplus for all databases specified in a file.

You can download the script from the website www.csqlplus.org.

Oracle 12c: RMAN Catalog must be Enterprise Edition

While upgrading an environment to Oracle 12c, one thing that needs to be done is to upgrade the RMAN catalog. One change introduced by Oracle is that there are new features used in the version 12 RMAN catalog. So if you try to upgrade an RMAN catalog running on Oracle Standard Edition, you will encounter the following error:

RMAN> upgrade catalog;

error creating create_deleted_object_seq
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-06004: ORACLE error from recovery catalog database: ORA-00439: feature not enabled: Partitioning

Read the rest of this entry »

Oracle Database 12c Administrator Certified Professional

Even though I am not really happy about the new recertification requirements from Oracle, I took it to myself to refresh my OCP certificate. I completed the exam 1Z0-060 and can call myself now a “Oracle Database 12c Administrator Certified Professional”.

O_Database12c_Admin_Professional_clr

Although I am not allowed to disclose information about the exam, I must say that the I found this exam easier than previous exams. Since the exam is a multiple-choice exam, one can often answer the questions by just guessing or by exclusion principle…

Oracle Linux 7: oracle-rdbms-server-12cR1-preinstall

So today I tried to install the Oracle Preinstall RPM on a freshly installed Oracle Linux 7 machine. However, when I executed yum search rdbms the preinstall package was nowhere to be seen!

It turns out that we need to enable the Oracle Linux 7 “addons” repository in order to find the package. Swiss blogger Martin Berger put me on the right track.

Read the rest of this entry »

Oracle 12c: Show PDB saved state

As of PSU 12.1.0.2, Oracle introduced “PDB State Management Across CDB Restart”, which will automatically put a pluggable database in a previously defined state on database startup. To show the current saved state of the PDBs, you can query the documented view cdb_pdb_saved_states:

SQL> SELECT con_name, instance_name, state FROM cdb_pdb_saved_states;

CON_NAME		       INSTANCE_NAME		      STATE
------------------------------ ------------------------------ --------------
P1			       cdb2			      OPEN
P2			       cdb2			      OPEN

But beware: When you unplug and plug in the database, this saved state will be lost.

I think this is one of the more awesome improvements in 12.1.0.2, since the original startup trigger was more of a workaround than a real solution.

Script to find reclaimable space in the datafiles

Storage costs are a major matter of expense in any large database environment. Therefore, in order to operate a cost-optimized environment, it makes sense to regularly review all databases in terms of datafile sizes. Usage of these files can vary dramatically, depending on the application using the database. Therefore, we need a way to quickly identify datafiles which we can shrink in order to save storage costs.

Read the rest of this entry »