If you need, uninstall old samba
# yum erase samba samba-common samba-client
install tool
# yum install samba4
or upgrade tool
# yum upgrade samba4
configure settings
# vi /etc/samba/smb.conf
e.g.
[share_folder]
comment = Share Folder
path = /share_folder
create mode = 0777
readonly = no
browseable = yes
public = yes
Check configuration of samba
# testparm
check samba service and version
# smbstatus
startup options
# chkconfig smb on
# service smb start
connect to share folder
e.g.
RUN> \\10.10.10.10\share_folder
remove startup option and stop vnc
# chkconfig smb off
# service smb stop
Tuesday, 1 August 2017
ORA-28002 solution
Error
ORA-28002: the password will expire within [A] days
Solution
Disable password expiration
SQL> select profile from DBA_USERS where username = 'HR';
-- e.g. DEFAULT
Change password_life_time parameter
SQL> alter profile "DEFAULT" limit password_life_time UNLIMITED;
Check it
SQL> select resource_name,limit from dba_profiles where profile='DEFAULT';
Apply the new setting for user
SQL> alter user "HR" identified by "hr";
ORA-28002: the password will expire within [A] days
Solution
Disable password expiration
SQL> select profile from DBA_USERS where username = 'HR';
-- e.g. DEFAULT
Change password_life_time parameter
SQL> alter profile "DEFAULT" limit password_life_time UNLIMITED;
Check it
SQL> select resource_name,limit from dba_profiles where profile='DEFAULT';
Apply the new setting for user
SQL> alter user "HR" identified by "hr";
Tuesday, 25 July 2017
SQL PLUS system parameters usage (set/show)
To show parameter in detail
SQL> SHOW DEFINE;
To escape from substitution variable (&):
SQL> SET DEFINE OFF;
To enable DBMS_OUTPUT:
SQL> SET SERVEROUTPUT ON;
To see old and new values of variables:
SQL> SET VERIFY ON;
To calculate total execution time of SQL:
SQL> SET TIMING ON;
To print time on the SQL terminal:
SQL> SET TIME ON;
To see table columns name and types for a table:
SQL> DESC hr.employees@XE;
To see currently logged-in user:
SQL> SHOW user;
SQL> SHOW DEFINE;
To escape from substitution variable (&):
SQL> SET DEFINE OFF;
To enable DBMS_OUTPUT:
SQL> SET SERVEROUTPUT ON;
To see old and new values of variables:
SQL> SET VERIFY ON;
To calculate total execution time of SQL:
SQL> SET TIMING ON;
To print time on the SQL terminal:
SQL> SET TIME ON;
To see table columns name and types for a table:
SQL> DESC hr.employees@XE;
To see currently logged-in user:
SQL> SHOW user;
e.g. changing the DBID and Database Name
e.g.
Backup database
RMAN> backup database
Mount database
SQL> shu immediate;
SQL> startup mount;
Change DBID
$ nid TARGET=SYS
or
Change both DBID and DBNAME
$ nid TARGET=SYS DBNAME=new_xe
Change database name from parameter file (init.ora)
*.db_name='NEW_XE'
Mount database again
SQL> startup mount;
Open database
SQL> alter database open resetlogs;
Ref: https://docs.oracle.com/database/121/SUTIL/GUID-05B4733C-9EAA-438F-A2A4-4E84EB1E1E65.htm#SUTIL1544s
Backup database
RMAN> backup database
Mount database
SQL> shu immediate;
SQL> startup mount;
Change DBID
$ nid TARGET=SYS
or
Change both DBID and DBNAME
$ nid TARGET=SYS DBNAME=new_xe
Change database name from parameter file (init.ora)
*.db_name='NEW_XE'
Mount database again
SQL> startup mount;
Open database
SQL> alter database open resetlogs;
Ref: https://docs.oracle.com/database/121/SUTIL/GUID-05B4733C-9EAA-438F-A2A4-4E84EB1E1E65.htm#SUTIL1544s
Labels:
database_name,
dbid,
nid,
oracle
Monday, 17 July 2017
SYS_CONTEXT function parameters and examples
Active parameters
ACTION, AUDITED_CURSORID, AUTHENTICATED_IDENTITY, AUTHENTICATION_DATA, AUTHENTICATION_METHOD, BG_JOB_ID, CLIENT_IDENTIFIER, CLIENT_INFO, CURRENT_BIND, CURRENT_SCHEMA, CURRENT_SCHEMAID, CURRENT_SQL, CURRENT_SQLn, CURRENT_SQL_LENGTH, DB_DOMAIN, DB_NAME, DB_UNIQUE_NAME, ENTRYID, ENTERPRISE_IDENTITY, FG_JOB_ID, GLOBAL_CONTEXT_MEMORY, GLOBAL_UID, HOST, IDENTIFICATION_TYPE, INSTANCE, INSTANCE_NAME, IP_ADDRESS, ISDBA, LANG, LANGUAGE, MODULE, NETWORK_PROTOCOL, NLS_CALENDAR, NLS_CURRENCY, NLS_DATE_FORMAT, NLS_DATE_LANGUAGE, NLS_SORT, NLS_TERRITORY, OS_USER, POLICY_INVOKER, PROXY_ENTERPRISE_IDENTITY, PROXY_GLOBAL_UID, PROXY_USER, SERVER_HOST, SERVICE_NAME, SESSION_USER, SESSION_USERID, SESSIONID, SID, STATEMENTID, TERMINAL
e.g.
SQL> select SYS_CONTEXT ('USERENV', 'SESSION_USER') from dual;
-- HR
e.g.
SQL> select SYS_CONTEXT ('USERENV', 'CURRENT_SCHEMA') from dual;
-- HR
Deprecated parameters
AUTHENTICATION_TYPE, CURRENT_USER, CURRENT_USERID, EXTERNAL_NAME
Extra for sys_context
Link
Ref: http://docs.oracle.com/cd/B19306_01/server.102/b14200/functions165.htm
ACTION, AUDITED_CURSORID, AUTHENTICATED_IDENTITY, AUTHENTICATION_DATA, AUTHENTICATION_METHOD, BG_JOB_ID, CLIENT_IDENTIFIER, CLIENT_INFO, CURRENT_BIND, CURRENT_SCHEMA, CURRENT_SCHEMAID, CURRENT_SQL, CURRENT_SQLn, CURRENT_SQL_LENGTH, DB_DOMAIN, DB_NAME, DB_UNIQUE_NAME, ENTRYID, ENTERPRISE_IDENTITY, FG_JOB_ID, GLOBAL_CONTEXT_MEMORY, GLOBAL_UID, HOST, IDENTIFICATION_TYPE, INSTANCE, INSTANCE_NAME, IP_ADDRESS, ISDBA, LANG, LANGUAGE, MODULE, NETWORK_PROTOCOL, NLS_CALENDAR, NLS_CURRENCY, NLS_DATE_FORMAT, NLS_DATE_LANGUAGE, NLS_SORT, NLS_TERRITORY, OS_USER, POLICY_INVOKER, PROXY_ENTERPRISE_IDENTITY, PROXY_GLOBAL_UID, PROXY_USER, SERVER_HOST, SERVICE_NAME, SESSION_USER, SESSION_USERID, SESSIONID, SID, STATEMENTID, TERMINAL
e.g.
SQL> select SYS_CONTEXT ('USERENV', 'SESSION_USER') from dual;
-- HR
e.g.
SQL> select SYS_CONTEXT ('USERENV', 'CURRENT_SCHEMA') from dual;
-- HR
Deprecated parameters
AUTHENTICATION_TYPE, CURRENT_USER, CURRENT_USERID, EXTERNAL_NAME
Extra for sys_context
Link
Ref: http://docs.oracle.com/cd/B19306_01/server.102/b14200/functions165.htm
Labels:
oracle,
sys_context
Friday, 14 July 2017
Quiesce restricted mode vs Restricted mode
Differences;
* Quiesce restricted option is less raugh than restricted option and they are quite similar.
* In quiesce restricted option, active session allows to continue until it become inactive.
* In restricted session, only new users can login who has "restrict session" privileges, but in quiesce restricted session, system blocks new non-dba users.
commands;
SQL> ALTER SYSTEM QUIESCE RESTRICTED;
check the state;
SQL> SELECT ACTIVE_STATE FROM V$INSTANCE;
-- normal, quiescing, quiesced
SQL> ALTER SYSTEM UNQUIESCE;
check the state;
SQL> SELECT ACTIVE_STATE FROM V$INSTANCE;
-- normal, quiescing, quiesced
SQL> ALTER SYSTEM ENABLE RESTRICTED SESSION;
SQL> ALTER SYSTEM DISABLE RESTRICTED SESSION;
Ref: https://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:902149038276
* Quiesce restricted option is less raugh than restricted option and they are quite similar.
* In quiesce restricted option, active session allows to continue until it become inactive.
* In restricted session, only new users can login who has "restrict session" privileges, but in quiesce restricted session, system blocks new non-dba users.
commands;
SQL> ALTER SYSTEM QUIESCE RESTRICTED;
check the state;
SQL> SELECT ACTIVE_STATE FROM V$INSTANCE;
-- normal, quiescing, quiesced
SQL> ALTER SYSTEM UNQUIESCE;
check the state;
SQL> SELECT ACTIVE_STATE FROM V$INSTANCE;
-- normal, quiescing, quiesced
SQL> ALTER SYSTEM ENABLE RESTRICTED SESSION;
SQL> ALTER SYSTEM DISABLE RESTRICTED SESSION;
Ref: https://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:902149038276
Labels:
oracle,
quiesce restricted,
restricted
Tuesday, 11 July 2017
log_buffer, log_checkpoint_timeout and log_checkpoint_interval parameters
Purpose
We are able to tune CKPT process with these paramaters and they should be configured together.
Usage
e.g.
Check current parameter:
SQL> show parameter log
NAME TYPE VALUE
------------------------------------ ----------- -------------------
log_buffer integer 5361664
log_checkpoint_interval integer 0
log_checkpoint_timeout integer 1200
Check log file size of one group
SQL> select group#, bytes, blocksize, members from v$log;
GROUP# BYTES BLOCKSIZE MEMBERS
---------- ---------- ---------- ----------
1 52428800 512 2
2 52428800 512 2
Log file size -> 52428800 bytes -> 50 MB
Log buffer should be -> 50 MB * 3 = 150 MB -> 157286400
Log checkpoint timeout could be -> 600 -> 10 minutes
Log checkpoint interval could be -> 0 or 102400 (102400 * 512(OS Block size) -> 52428800 bytes -> 50 MB is equal to log file size)
Apply the setting:
init.ora file:
*.log_buffer=157286400
*.log_checkpoint_interval=102400
*.log_checkpoint_timeout=600
Then restart the instance to perform.
Check lastly:
SQL> show parameter log
NAME TYPE VALUE
------------------------------------ ----------- -------------------
log_buffer integer 157286400
log_checkpoint_interval integer 102400
log_checkpoint_timeout integer 600
Deep notes
Log group members should be at least 2, same size, same amount and located in different paths to take backup. (log members are exactly same, 1-> 1)
Log checkpoint timeout parameter means that at most 600 seconds later, dirty blocks are written to database files from SGA.
Log checkpoint interval parameter means that after active log file size exceeds to 50 MB, CKPT is triggered for DBWR. If this parameter is "0", Oracle decides CKPT running time automatically.
We are able to tune CKPT process with these paramaters and they should be configured together.
e.g.
Check current parameter:
SQL> show parameter log
NAME TYPE VALUE
------------------------------------ ----------- -------------------
log_buffer integer 5361664
log_checkpoint_interval integer 0
log_checkpoint_timeout integer 1200
Check log file size of one group
SQL> select group#, bytes, blocksize, members from v$log;
GROUP# BYTES BLOCKSIZE MEMBERS
---------- ---------- ---------- ----------
1 52428800 512 2
2 52428800 512 2
Log file size -> 52428800 bytes -> 50 MB
Log buffer should be -> 50 MB * 3 = 150 MB -> 157286400
Log checkpoint timeout could be -> 600 -> 10 minutes
Log checkpoint interval could be -> 0 or 102400 (102400 * 512(OS Block size) -> 52428800 bytes -> 50 MB is equal to log file size)
Apply the setting:
init.ora file:
*.log_buffer=157286400
*.log_checkpoint_interval=102400
*.log_checkpoint_timeout=600
Then restart the instance to perform.
Check lastly:
SQL> show parameter log
NAME TYPE VALUE
------------------------------------ ----------- -------------------
log_buffer integer 157286400
log_checkpoint_interval integer 102400
log_checkpoint_timeout integer 600
Deep notes
Log group members should be at least 2, same size, same amount and located in different paths to take backup. (log members are exactly same, 1-> 1)
Log checkpoint timeout parameter means that at most 600 seconds later, dirty blocks are written to database files from SGA.
Log checkpoint interval parameter means that after active log file size exceeds to 50 MB, CKPT is triggered for DBWR. If this parameter is "0", Oracle decides CKPT running time automatically.
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
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.
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
Labels:
oracle,
performance,
plsql_code_type,
plsql_optimize_level
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%'
select * from all_source where owner <> 'SYS' and upper(text) like '%ABC%'
Labels:
all_source,
oracle
Saturday, 10 June 2017
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;
/
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;
/
Labels:
bind variable,
oracle
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;
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:
-- 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
- Maximum number of DB blocks are 4194304 blocks (222) per database file
- Maximum DB block size is 32 KB per DB block
-- 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
Labels:
database file,
db_block_size,
oracle
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
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
Labels:
AWR,
oracle,
statistics_level
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
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
Labels:
db_ultra_safe,
oracle
Sunday, 21 May 2017
Oracle Enterprise Manager Version History
- Oracle Enterprise Manager Cloud Control 13c Release 2 (13.2.0.0)
- Oracle Enterprise Manager Cloud Control 13c Release 1 (13.1.0.0)
- Oracle Enterprise Manager Cloud Control 12c Release 5 (12.1.0.5)
Last Updated: 21/05/2017
Thursday, 18 May 2017
e.g. row lock (tx) and table lock (tm)
e.g.
row lock (tx)
In -A- database:
SQL>
select * from employees where employee_id = 100 FOR UPDATE;
to see the error;
In -B- database:
SQL>
update employees@alper_database
set salary = 10000
where employee_id = 100;
error -> ORA-02049: timeout: distributed transaction waiting for lock
e.g.
table lock (tm)
In -A- database:
SQL>
LOCK TABLE employees IN EXCLUSIVE MODE NOWAIT;
to see the error;
In -B- database:
SQL>
update employees@alper_database
set salary = 2500
where employee_id = 105;
--or
In -B- database:
LOCK TABLE employees@alper_database IN SHARE MODE;
to see the error;
In -A- database:
SQL>
update employees
set salary = 2500
where employee_id = 105;
same error for both methods -> ORA-02049: timeout: distributed transaction waiting for lock
ref: https://docs.oracle.com/cd/E11882_01/server.112/e41084/ap_locks001.htm#SQLRF55502
row lock (tx)
In -A- database:
SQL>
select * from employees where employee_id = 100 FOR UPDATE;
to see the error;
In -B- database:
SQL>
update employees@alper_database
set salary = 10000
where employee_id = 100;
error -> ORA-02049: timeout: distributed transaction waiting for lock
e.g.
table lock (tm)
In -A- database:
SQL>
LOCK TABLE employees IN EXCLUSIVE MODE NOWAIT;
to see the error;
In -B- database:
SQL>
update employees@alper_database
set salary = 2500
where employee_id = 105;
--or
In -B- database:
LOCK TABLE employees@alper_database IN SHARE MODE;
to see the error;
In -A- database:
SQL>
update employees
set salary = 2500
where employee_id = 105;
same error for both methods -> ORA-02049: timeout: distributed transaction waiting for lock
ref: https://docs.oracle.com/cd/E11882_01/server.112/e41084/ap_locks001.htm#SQLRF55502
Labels:
oracle,
row lock (tx),
table lock (tm)
Tuesday, 16 May 2017
ORA-2049 examples
Error
ORA-2049 timeout: distributed transaction waiting for lock
SQL> sho parameter distr
-- Default: 60 sec
e.g.
In -A- Database
select * from employees where employee_id = 100 for update;
or
update employees
set salary = 15000
where employee_id = 100;
-- Locked the row
IN -B- Database
select * from employees@a_dblink where employee_id = 100
update employees@a_dblink
set salary = 10000
where employee_id = 100;
-- Error occurred after 60 seconds -> ORA-2049
To decrease wait time:
add this into init.ora file in -A- database;
*.distributed_lock_timeout=5
Then restart the instance to perform.
To wait just one second in -B- Database:
select* from employees@a_dblink
where employee_id = 100
for update wait 1;
-- Error occurred after 1 second -> ORA-2049 if the row locked
Then try update;
update employees@a_dblink
set salary = 10000
where employee_id = 100;
commit;
Not to wait:
select* from employees@a_dblink
where employee_id = 100
for update nowait;
-- Error occurred immediately -> ORA-2049 if the row locked
Then try update;
update employees@a_dblink
set salary = 10000
where employee_id = 100;
commit;
ORA-2049 timeout: distributed transaction waiting for lock
SQL> sho parameter distr
-- Default: 60 sec
e.g.
In -A- Database
select * from employees where employee_id = 100 for update;
or
update employees
set salary = 15000
where employee_id = 100;
-- Locked the row
IN -B- Database
select * from employees@a_dblink where employee_id = 100
update employees@a_dblink
set salary = 10000
where employee_id = 100;
-- Error occurred after 60 seconds -> ORA-2049
To decrease wait time:
add this into init.ora file in -A- database;
*.distributed_lock_timeout=5
Then restart the instance to perform.
To wait just one second in -B- Database:
select* from employees@a_dblink
where employee_id = 100
for update wait 1;
-- Error occurred after 1 second -> ORA-2049 if the row locked
Then try update;
update employees@a_dblink
set salary = 10000
where employee_id = 100;
commit;
Not to wait:
select* from employees@a_dblink
where employee_id = 100
for update nowait;
-- Error occurred immediately -> ORA-2049 if the row locked
Then try update;
update employees@a_dblink
set salary = 10000
where employee_id = 100;
commit;
Labels:
db link,
distributed lock,
ORA-2049,
oracle
Wednesday, 10 May 2017
e.g. OLD and NEW Pseudorecords
e.g.
SQL>
create table employees_salary_log (employee_id number, cur_salary number(8,2), new_salary number(8,2), updated_date date);
SQL>
CREATE OR REPLACE TRIGGER HR.TBU_EMPLOYEES
BEFORE UPDATE
ON HR.EMPLOYEES
REFERENCING NEW AS NEW_ROW OLD AS OLD_ROW
FOR EACH ROW
DECLARE
BEGIN
IF :OLD_ROW.MANAGER_ID IS NOT NULL
THEN
INSERT INTO employees_salary_log
VALUES (:NEW_ROW.employee_id, :OLD_ROW.salary, :NEW_ROW.salary, SYSTIMESTAMP);
END IF;
EXCEPTION
WHEN OTHERS
THEN
raise_application_error (
-20001,
'An error was encountered - ' || SQLCODE || ' -ERROR- ' || SQLERRM);
NULL;
END;
/
update employees
set salary = 17100
where employee_id = 101
/
update employees
set salary = 35000
where employee_id = 100
/
commit
/
select * from employees_salary_log
-- only display employee who is not a manager
SQL>
create table employees_salary_log (employee_id number, cur_salary number(8,2), new_salary number(8,2), updated_date date);
SQL>
CREATE OR REPLACE TRIGGER HR.TBU_EMPLOYEES
BEFORE UPDATE
ON HR.EMPLOYEES
REFERENCING NEW AS NEW_ROW OLD AS OLD_ROW
FOR EACH ROW
DECLARE
BEGIN
IF :OLD_ROW.MANAGER_ID IS NOT NULL
THEN
INSERT INTO employees_salary_log
VALUES (:NEW_ROW.employee_id, :OLD_ROW.salary, :NEW_ROW.salary, SYSTIMESTAMP);
END IF;
EXCEPTION
WHEN OTHERS
THEN
raise_application_error (
-20001,
'An error was encountered - ' || SQLCODE || ' -ERROR- ' || SQLERRM);
NULL;
END;
/
update employees
set salary = 17100
where employee_id = 101
/
update employees
set salary = 35000
where employee_id = 100
/
commit
/
select * from employees_salary_log
-- only display employee who is not a manager
Labels:
oracle,
Pseudorecords
Monday, 8 May 2017
How to know $ORACLE_HOME path via sqlplus in Windows ?
CMD> sqlplus / as sysdba
SQL>
set serveroutput on;
SQL>
DECLARE
Result_Val VARCHAR2(100);
BEGIN
dbms_system.get_env('ORACLE_HOME', Result_Val);
dbms_output.put_line(Result_Val);
END;
/
SQL>
set serveroutput on;
SQL>
DECLARE
Result_Val VARCHAR2(100);
BEGIN
dbms_system.get_env('ORACLE_HOME', Result_Val);
dbms_output.put_line(Result_Val);
END;
/
Labels:
oracle,
oracle_home,
sqlplus
Subscribe to:
Posts (Atom)