Jul 22, 2021
Requested Trace Files- Files

The trace files you typically expect to be generated as the result of enabling trace via DBMS_MONITOR or using the extended trace facility via the 10046 event might be as follows:

SQL> alter session set events ‘10046 trace name context forever, level 12’; Session altered.

These trace files contain diagnostic and performance-related information. They provide invaluable insights into the inner workings of your database application. You will see these trace files more often than any other kind of trace file in a normally operating database.

File Locations

Whether you use DBMS_MONITOR or the extended trace facility, Oracle will start generating a trace file on the database server derived from the setting of the DIAGNOSTIC_DEST initialization parameter. The structure of the directory specified by DIAGNOSTIC_DEST is as follows:

/diag/rdbms//

This location is known as the Automatic Diagnostic Repository (ADR) Home. For example, if the database name is CDB and the instance name is CDB, the ADR home directory would be /diag/rdbms/cdb/CDB. You can view the directory settings with this query:

SQL> select name, value from v$diag_info;

AME VALUE

Diag Enabled TRUE
ADR Base /opt/oracle
ADR Home /opt/oracle/diag/rdbms/cdb/CDB

Diag Trace /opt/oracle/diag/rdbms/cdb/CDB/trace
Diag Alert /opt/oracle/diag/rdbms/cdb/CDB/alert
Diag Incident /opt/oracle/diag/rdbms/cdb/CDB/incident
Diag Cdump /opt/oracle/diag/rdbms/cdb/CDB/cdump
Health Monitor /opt/oracle/diag/rdbms/cdb/CDB/hm
Default Trace File /opt/oracle/diag/rdbms/cdb/CDB/trace/CDB_ora_15884.trc …

The most important rows are

•\ Diag Trace: This is where the text-based alert log goes along with the trace file.
•\ Diag Alert: This is where the XML-based alert log file is written.

As a DBA, you’ll spend time working with files in the Diag Trace directory. These files are used so often (debugging and maintenance) that DBAs will often create aliases that will take them to that directory directly and tail the alert log. For example:

$ alias cda=’cd /opt/oracle/diag/rdbms/cdb/CDB/trace’
$ alias ta=’tail -f /opt/oracle/diag/rdbms/cdb/CDB/trace/alert_CDB.log’

The aliases create shortcuts for working with these critical files.

Naming Convention

The trace file naming convention changes from time to time in Oracle, but if you have an example trace file name from your system, it is easy to see the template in use. For example, on my various UNIX/Linux servers, a trace file name has this general format:

ora.trc

The trace file name can be broken down as follows:

•\ The first part of the file name is the ORACLE_SID.

•\ The next bit of the file name is just ora.

•\ The number in the trace file name is the process ID of your dedicated server, available to you from the V$PROCESS view.

A query, then, to generate your trace file name could be

SQL> column trace new_val TRACE format a100
SQL> select i.value || ‘/’ || d.instance_name || ‘ora‘ || a.spid || ‘.trc’ trace
from v$process a, v$session b, v$diag_info i , v$instance d where a.addr = b.paddr
and b.audsid = userenv(‘sessionid’)
and i.name=’Diag Trace’;

TRACE

/opt/oracle/diag/rdbms/cdb/CDB/trace/CDB_ora_16908.trc

And this just shows that if the file exists, you’ll be able to access it via that name (assuming you have the permissions to read the trace directory). The following example generates a trace file, showing how the file is created once the trace is enabled:

SQL> !ls &TRACE
ls: cannot access /opt/oracle/diag/rdbms/cdb/CDB/trace/CDB_ora_16908.trc:

No such file or directory
SQL> exec dbms_monitor.session_trace_enable PL/SQL procedure successfully completed.
SQL> !ls &TRACE
/opt/oracle/diag/rdbms/cdb/CDB/trace/CDB_ora_16908.trc

As you can see, before we enabled tracing in that session, no file existed; as soon as tracing is enabled, however, we are able to see it.

And if you’re using Windows, it should be obvious that you’d replace the / with .

More Details
May 22, 2021
Setting Values in SPFILEs- Files

Once our database is up and running on the SPFILE, the next question relates to how we set and change values contained therein. Remember, SPFILEs are binary files and we can’t just edit them using a text editor. The answer is to use the ALTER SYSTEM command, which has the following syntax (portions in <> are optional, and the presence of the pipe symbol indicates “one of the list”):

Alter system set parameter=value <comment=’text’> <deferred> <scope=memory|spfile|both> <sid=’sid|*’> <container=current|all>

The ALTER SYSTEM SET command, by default, will update the currently running instance and make the change to the SPFILE for you—or in the case of a pluggable database, in the data dictionary of that pluggable database (see the following section on pluggable databases for more information). This greatly eases administration, and it eliminates the problems that arose when you used ALTER SYSTEM to add or modify parameter settings, but you forgot to update or missed an init.ora parameter file.

Let’s take a look at each element of the command:

•\    The parameter=value assignment supplies the parameter name and the new value for the parameter. For example, pga_aggregate_ target = 1024m would set the pga_aggregate_target parameter to a value of 1024MB (1GB).

•\ comment=’text’ is an optional comment you can associate with this setting of the parameter. The comment will appear in the UPDATE_ COMMENT field of the V$PARAMETER view. If you use the option to save the change to the SPFILE, the comment will be written into the SPFILE and preserved across server restarts as well, so future restarts of the database will see the comment.

•\ deferred specifies whether the system change takes place for subsequent sessions only (not currently established sessions, including the one making the change). By default, the ALTER SYSTEM command will take effect immediately, but some parameters can’t be changed immediately—they can be changed only for newly established sessions. We can use the following query to see what parameters mandate the use of deferred:

SQL> select name from v$parameter where issys_modifiable=’DEFERRED’;

NAME
backup_tape_io_slaves
recyclebin
session_cached_cursors
private_temp_table_prefix
audit_file_dest
object_cache_optimal_size
object_cache_max_size_percent
sort_area_size
sort_area_retained_size
client_statistics_level
olap_page_pool_size

Note Your results may differ; from version to version, the list of which parameters may be set online—but must be deferred—can and will change.

The code shows that SORT_AREA_SIZE is modifiable at the system level, but only in a deferred manner. The following code shows what happens if we try to modify its value with and without the deferred option:

SQL> alter system set sort_area_size = 65536; alter system set sort_area_size = 65536

ERROR at line 1:

ORA-02096: specified initialization parameter is not modifiable with this option
SQL> alter system set sort_area_size = 65536 deferred;System altered.

•\ SCOPE=MEMORY|SPFILE|BOTH indicates the “scope” of this parameter setting. Here are our choices for setting the parameter value:

•\ SCOPE=MEMORY changes the setting in the instance(s) only; it will not survive a database restart. The next time you start the database, the setting will be whatever was already recorded in the

SPFILE.

•\ SCOPE=SPFILE changes the value in the SPFILE only. The change will not take place until the database is restarted and the SPFILE is processed again. Some parameters can be changed only by using this option. For example, the processes parameter must use SCOPE=SPFILE, as you can’t change the active instance value.

•\ SCOPE=BOTH means the parameter change takes place both in memory and in the SPFILE. The change will be reflected in the current instance, and, the next time you start, this change will still be in effect. This is the default value for scope when using an SPFILE. With an init.ora parameter file, the default and only valid value is SCOPE=MEMORY. This is the default if the instance was started with an SPFILE.

•\ sid=’sid|‘ is useful mostly in a clustered environment; sid=’‘ is the default. This lets you specify a parameter setting uniquely for any given instance in the cluster. Unless you are using Oracle RAC, you will not need to specify the sid= setting.

•\ container=current|all is used in a multitenant database to determine the scope of the change. If the ALTER SYSTEM is executed in a root container database, the setting may be propagated down to every pluggable database by using the all option. Otherwise, by default, only the current container or pluggable database is affected by the change. Note that pluggable database–specific settings are not recorded in the SPFILE but are stored in the data dictionary of the pluggable database, so that when it is moved to another container, its specific settings will move with it.

A typical use of this command might be simply
SQL> alter system set pga_aggregate_target=512m; System altered.

Note The preceding command—and in fact many of the ALTER SYSTEM commands in this book—may fail on your system. If you use other settings that are incompatible with my example (other memory parameters, for example), you may well receive an error. That doesn’t mean the command doesn’t work, but, rather, the settings you attempted to use are not compatible with your overall setup.

Better yet, perhaps, would be using the COMMENT= assignment to document when and/or why a particular change was made:

SQL> alter system set pga_aggregate_target=512m comment = ‘AWR recommendation’; System altered.
SQL> select value, update_comment from v$parameter where name = ‘pga_ aggregate_target’;

VALUE UPDATE_COMMENT
536870912 AWR recommendation

More Details
Mar 22, 2021
Unsetting Values in SPFILEs- Files

The next question that arises is, how do we unset a value that we previously set? In other words, we don’t want that parameter setting in our SPFILE anymore. Since we can’t edit the file using a text editor, how do we accomplish that? This, too, is done via the ALTER SYSTEM command, but using the RESET clause:

Alter system reset parameter sid=’sid|*’

So, for example, if we wanted to remove the sort_area_size parameter, to allow it to assume the default value we specified previously, we could do so as follows:

SQL> alter system reset sort_area_size scope=spfile ; System altered.

The sort_area_size is removed from the SPFILE, which you can verify by issuing the following:

SQL> create pfile=’/tmp/pfile.tst’ from spfile; File created.

You can then review the contents of /tmp/pfile.tst, which will be generated on the database server. You’ll find the sort_area_size parameter does not exist in the parameter file anymore.

Creating PFILEs from SPFILEs

The CREATE PFILE…FROM SPFILE command we just saw is the opposite of CREATE SPFILE. It takes the binary SPFILE and creates a plain text file from it—one that can be edited in any text editor and subsequently used to start up the database. You might use this command for at least two things on a regular basis:

•\ To create a one-time parameter file with some special settings, to start up the database for maintenance. So, you’d issue CREATE PFILE…

FROM SPFILE and edit the resulting text PFILE, modifying the required settings. You’d then start the database, using the PFILE= option to specify your PFILE instead of the SPFILE. After you finished, you’d just start up normally without specifying the PFILE=, and the database would use the SPFILE.

•\ To maintain a history of commented changes. In the past, many DBAs heavily commented their parameter files with a change history. If they changed the size of the SGA 20 times, for example, they would have 20 comments in front of the sga_target init.ora parameter setting, stating the date and reason for making the change. The SPFILE does not support this, but you can achieve the same effect if you get into the habit of doing the following:

SQL> connect / as sysdba
Connected.
SQL> create pfile=’init_10_feb_2021_CDB.ora’ from spfile; File created.
SQL> alter system set pga_aggregate_target=512m comment = ‘Changed 10-feb-­
2021, AWR recommendation’;System altered.

In this way, your history will be saved in the series of parameter files over time.

Fixing Corrupted SPFILEs

The last question that comes up with regard to SPFILEs is, “SPFILEs are binary files, so what happens if one gets corrupted and the database won’t start? At least the init.ora file was just text, so we could edit it and fix it.” Well, SPFILEs shouldn’t go corrupt any more than should a datafile, redo log file, control file, and so forth. However, in the event one does—or if you have set a value in your SPFILE that does not allow the database to start—you have a couple of options.

First, the amount of binary data in the SPFILE is very small. If you are on a UNIX/ Linux platform, a simple strings command will extract all of your settings:

$ strings $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora
*.audit_sys_operations=false
*.audit_trail=’none’
*.commit_logging=’batch’
*.commit_wait=’nowait’…

On Windows, simply open the file with write.exe (WordPad). WordPad will display all of the clear text in the file, and by simply cutting and pasting into init. ora, you can create a PFILE to use to start your instance.

In the event that the SPFILE has just “gone missing” (for whatever reason—not that I’ve seen an SPFILE disappear), you can also resurrect the information for your parameter file from the database’s alert log (more on the alert log shortly). Every time you start the database, the alert log will contain a section like this:

System parameters with non-default values:

processes = 300
nls_language = “AMERICAN”
nls_territory = “AMERICA”
filesystemio_options = “setall”
sga_target = 2152M
control_files = “/opt/oracle/oradata/CDB/control01.ctl”
db_block_size = 8192

From this section, you can easily create a PFILE to be converted into a new SPFILE using the CREATE SPFILE command.

More Details