Useful shortcuts for vi editor

Wednesday, 28 June 2017

plsql_optimize_level and plsql_code_type parameters

Purpose
We are able to use plsql_optimize_level parameter for getting better execution performance on plsql codes. On the other way, plsql_code_type parameter is using to change compilation mode.

Usage
Check current parameter:
SQL> show parameter plsql

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
plsql_ccflags                        string
plsql_code_type                      string      INTERPRETED
plsql_debug                          boolean     FALSE
plsql_optimize_level                 integer     2
plsql_v2_compatibility               boolean     FALSE
plsql_warnings                       string      DISABLE:ALL

Apply the setting:
init.ora file:
*.plsql_optimize_level=3
*.plsql_code_type='NATIVE'

SQL> shutdown immediate;

SQL> startup upgrade;

SQL> @$ORACLE_HOME/rdbms/admin/dbmsupgnv.sql;

SQL> shutdown;

SQL> startup;

SQL> ALTER SYSTEM ENABLE RESTRICTED SESSION;

SQL> @$ORACLE_HOME/rdbms/admin/utlrp.sql;

SQL> ALTER SYSTEM DISABLE RESTRICTED SESSION;

Check lastly:
SQL> show parameter plsql

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
plsql_ccflags                        string
plsql_code_type                      string      NATIVE
plsql_debug                          boolean     FALSE
plsql_optimize_level                 integer     3
plsql_v2_compatibility               boolean     FALSE
plsql_warnings                       string      DISABLE:ALL

To see current status of objects;
SQL> 
SELECT TYPE, PLSQL_CODE_TYPE, COUNT(*) FROM DBA_PLSQL_OBJECT_SETTINGS
WHERE PLSQL_CODE_TYPE IS NOT NULL
GROUP BY TYPE, PLSQL_CODE_TYPE
ORDER BY TYPE, PLSQL_CODE_TYPE;

Deep notes
INTERPRETED -> PL/SQL library units compile as bytecode format
NATIVE -> PL/SQL library units compile as native (machine) code format

Ref: https://becomeadba.com/?pages-list

Tuesday, 20 June 2017

How to find database object via SQL statements?

SQL>
select * from all_source where owner <> 'SYS' and upper(text) like '%ABC%'

Saturday, 10 June 2017

How to solve SQL Developer redrawing problem on Windows?

Problem

Solution
Tools -> Preferences -> Lock and Feel -> Set Windows -> Click OK

Thursday, 8 June 2017

e.g. bind variable usage

bind variable;
When user executes an SQL query or a PL/SQL code, Oracle uses CPU resource for parsing operations on the SGA. However, if user execute the query with bind variable, "soft parsing" exists instead of "hard parsing". Therefore, "total DB time" and "parsing time" decreases, library cache size is not occupied unnecessarily as well. 

e.g.
SET TIMING ON;
VARIABLE v_bind_value NUMBER;

DECLARE
   v_value   VARCHAR2 (30);
BEGIN
   :v_bind_value := 100;

   SELECT last_name
     INTO v_value
     FROM employees
    WHERE employee_id = :v_bind_value;

   DBMS_OUTPUT.put_line (v_value);
END;
/

Wednesday, 7 June 2017

A brief look to Oracle backup mode

Backup mode; 
Oracle runs slightly different that database files are able to only use for read (not for write) in SGA and all database changes (DML, DDL, etc) are written into redo log files by Oracle. In that time, user can copy database files to desired folders because database file are frozen by system.
For example, when DML execute, all data block changes are written to redo log files as a exact block not as a delta log. Therefore, 
Oracle runs slowly according to normal mode and staying backup mode for a long time is also important risk for recovery operations. 
e.g. -> if you run "shutdown abort",  database gets crash in startup (ORA-10873, ORA-01110). To solve it, run "recover database".

Enable backup mode:
SQL> alter database begin backup;

If you get ORA-01123 error;
Enable archivelog mode;
https://ozsoyler.blogspot.com.tr/2014/10/how-to-checkopen-archieve-log-in-sqlplus.html

To check current db file status:
SQL> select * from v$backup;
-- status column output should be "ACTIVE"

Now we are able to copy/paste operation on disk:
find datafile paths;
SQL> select * from v$datafile;

Finish file transfer operations then disable backup mode:
SQL> alter database end backup;

Monday, 5 June 2017

How to calculate maximum database file size?

Info: 
  • Maximum number of DB blocks are 4194304 blocks (222) per database file
  • Maximum DB block size is 32 KB per DB block
SQL> show parameter db_block_size;
-- Generally it is 8192 byte (8 KB)

e.g. if block size is 8 KB;
maximum database file size = 4194304 x 8 KB = 33554432 KB = 32768 MB = 32 GB

e.g. if block size is 32 KB (this can be maximum 32 KB)
maximum database file size = 4194304 x 32 KB = 134217728 KB = 131072 MB = 128 GB

Ref: https://docs.oracle.com/cd/B28359_01/server.111/b28320/limits002.htm#i287915
https://docs.oracle.com/cd/B28359_01/server.111/b32009/appg_db_lmts.htm#UNXAR408

Sunday, 4 June 2017

statistics_level parameter

Purpose
The purpose of this parameter is to gather database and operating system statistics into SYSAUX tablespace. For example, it uses for defining the detail of AWR reports.

Usage
Current setting:
SQL> show parameter statistics_level;
-- default is "TYPICAL"

(options -> BASIC | TYPICAL | ALL)
Change setting permanently:
add this into init.ora file;
*.statistics_level='ALL'
-- BASIC is not enough to get AWR Report
-- TYPICAL is recommended for AWR Report
-- ALL gathers operating system and plan execution statistics records in extra for AWR Report

Then restart the instance to perform.

Change setting for current instance - temporary:

SQL> alter system set statistics_level = ALL;

Result
SQL> show parameter statistics_level;
-- output; ALL

To check detail information, we may look at v$statistics_level view.
SQL> select * from v$statistics_level;

Ref: https://docs.oracle.com/cd/B28359_01/server.111/b28320/initparams240.htm#REFRN10214

Saturday, 3 June 2017

db_ultra_safe parameter

Purpose
The purpose of this parameter is to see instant file corruption on disk then DBA takes action against the issue.

Usage
Current setting:
SQL> show parameter db_ultra_safe;
-- default is "OFF"

Change setting (options -> OFF | DATA_ONLY | DATA_AND_INDEX):
add this into init.ora file;
*.db_ultra_safe='DATA_ONLY'
-- DB_BLOCK_CHECKING, DB_BLOCK_CHECKSUM, and DB_LOST_WRITE_PROTECT parameter are set by automatically according to db_ultra_safe parameter setting.

Then restart the instance to perform.

Result
SQL> show parameter db_ultra_safe;
-- output; data_only

Ref: https://docs.oracle.com/cd/B28359_01/server.111/b28320/initparams064.htm#REFRN10295