Presentation on how to chat with PDF using ChatGPT code interpreter
DDL logging Parameter in Oracle 11g & 12c
1. =======================================================
DDL logging: In Oracle 11g&12c
================================================================
There was no direct option available to log the DDL action in the previous releases.
1) From 11gr2 /12cR1, you can now log the DDL action into xml and log files.
2) This will be very useful to know when the drop or create command was executed
and by who.
3) The ENABLE_DDL_LOGGING initiation parameter can be set at the Database or
Session levels.
4) When this parameter is enabled, all DDL commands are logged in an xml and a
log file under the $ORACLE_BASE/diag/rdbms/DBNAME/log|ddl location.
5) An xml file contains information, such as DDL command, IP address, timestamp
etc.
6) It helps to identify User/Table dropped (or) DDL statement is triggered.
To enable DDL logging
SQL> ALTER SYSTEM|SESSION SET ENABLE_DDL_LOGGING=TRUE;
Note: When ENABLE_DDL_LOGGING is set to true, the following DDL statements are
written to the alert log:
ALTER/CREATE/DROP/TRUNCATE CLUSTER
ALTER/CREATE/DROP FUNCTION
ALTER/CREATE/DROP INDEX
ALTER/CREATE/DROP OUTLINE
ALTER/CREATE/DROP PACKAGE
ALTER/CREATE/DROP PACKAGE BODY
ALTER/CREATE/DROP PROCEDURE
ALTER/CREATE/DROP PROFILE
ALTER/CREATE/DROP SEQUENCE
CREATE/DROP SYNONYM
ALTER/CREATE/DROP/RENAME/TRUNCATE TABLE
ALTER/CREATE/DROP TRIGGER
ALTER/CREATE/DROP TYPE
ALTER/CREATE/DROP TYPE BODY
DROP USER
ALTER/CREATE/DROP VIEW
2. Following is the example of DDL logging:
======================================
-bash-4.1$ sqlplus / as sysdba
SQL*Plus: Release 12.1.0.2.0 Production on Tue Jun 7 11:26:27 2019
Copyright (c) 1982, 2014, Oracle. All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
SQL> show parameter enable_ddl_logging
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
enable_ddl_logging boolean FALSE
================================================================
Difference Between 11g & 12c for enable_ddl_logging Parameter:
================================================================
In Oracle 11g:
DDL statements are written to the alert log in:
$ADR_BASE/diag/rdbms/${DBNAME}/${ORACLE_SID}/trace/alert_${ORACLE_SID}.log
1. License: The init.ora parameter ENABLE_DDL_LOGGING is licensed as part
of the Database Lifecycle Management Pack when set to TRUE. When set to
TRUE, the database reports schema changes in real time into the database alert
log under the message group schema_ddl. The default setting is FALSE.”
2. RENAME: was not logged and a bug was reported for that and the same is
fixed in 11.2.0.4. Document 12938609.8 – ENABLE_DDL_LOGGING does not
log RENAME table statements, this is fixed in 11.2.0.4
However, the feature does not log DDLs of some DBMS_STATS operations like:
set_column_stats
set_index_stats
create_extended_stats
drop_extended_stats
set_*_prefs (table/schema/global etc)
delete_pending_stats
publish_pending_stats
export_pending_stats
create_stat_table
3. In Oracle 12c:
Now if you look in the following text file:
$ADR_BASE/diag/rdbms/${DBNAME}/${ORACLE_SID}/log/ddl_${ORACLE_SID}.log
1. If ENABLE_DDL_LOGGING is enabled, then DDL records are written to the ADR.
2. All DDL operations like alter/create/drop/truncate objects.
3. Only drop user will be logged, But create user will not be.
How to ENABLE :
SQL> alter system set enable_ddl_logging=true;
System altered.
SQL> show parameter enable_ddl_logging;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
enable_ddl_logging boolean TRUE
How to DISABLE :
SQL> show parameter enable_ddl_logging
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
enable_ddl_logging boolean TRUE
SQL> alter system set enable_ddl_logging =FALSE;
System altered.
SQL> show parameter ENABLE_DDL_LOGGING
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
enable_ddl_logging boolean FALSE
SQL> conn syed/syed
Connected.
SQL> create table Testddl (id number, name varchar2(50));
Table created.
SQL> alter table Testddl add ( address varchar2(100));
Table altered.
4. SQL> insert into Testddl values (1,'CBT','XYZ');
1 row created.
SQL> commit;
Commit complete.
SQL> drop table ddltest;
Table dropped.
Note: Now, check the log file for all DDL commands that was run by user.
-bash-4.1$ pwd
/mnt/Oracle/diag/rdbms/orclnew/orclnew/log/ddl
-bash-4.1$ cat log.xml
msg_id='opiexe:4383:2946163730' type='UNKNOWN' group='diag_adl'
level='16' host_id='OraLinuxNode' host_addr='10.184.150.107'
version='1'>
create table Testddl (id number, name varchar2(50))
msg_id='opiexe:4383:2946163730' type='UNKNOWN' group='diag_adl'
level='16' host_id='OraLinuxNode' host_addr='10.184.150.107'>
alter table Testddl add ( address varchar2(100))
msg_id='opiexe:4383:2946163730' type='UNKNOWN' group='diag_adl'
level='16' host_id='OraLinuxNode' host_addr='10.184.150.107'>
drop table Testddl
=======================================================
THANK YOU
=======================================================
Written by:
Syed Sadath Ullah
M.Tech;OCP
Database Administrator
Email:oraclecloud777@gmail.com