Tuesday 2 December 2014

How to enable Archivelog mode in Oracle database 11g


There are two types of logging modes in Oracle database

1.
ARCHIVELOG :- In this type of logging whatever oracle writes in a redo log file related to transactions in database, saved to another location after a log file has been filled . This location is called Archive location. if database is in Archive log mode then in case of any disaster, we can recover our database upto the last commit and user don't have to reenter their data. Until a redo log file is not written to the Archive location it cannot be reused by oracle to write redo related data.

2.
NOARCHIVELOG :- In this type of logging whatever oracle writes in a redo log file related to transactions in database must be overwritten when all the log files have been filled. In this type of logging we can recover our database upto the last consistent backup we have with us, after that users have to reenter their data

To change the Oracle database in ARCHIVELOG mode

1. Check current archive log mode

[oracle@NVMBD1BZY150D00 ~]$ sqlplus / as sysdba

 SQL*Plus: Release 11.2.0.3.0 Production on Wed Dec 3 10:45:21 2014

Copyright (c) 1982, 2011, Oracle.  All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

sql> archive log list
Database log mode No Archive Mode
Automatic archival Enabled
Archive destination USE_DB_RECOVERY_FILE_DEST
Oldest online log sequence 2296
Current log sequence 2299
OR

SQL> select log_mode from v$database;

LOG_MODE
------------
NOARCHIVELOG

2 Change archive log location and archive log format with new location and format.

If needed set the archive log destination where you want to save your archive logs whether to a single location or to multiple location. If this is not set then Oracle save archive log files in DB_RECOVERY_FILE_DEST location if set. If you have not set your DB_RECOVERY_FILE_DEST location then you have to set your archive location before changing your database to ARCHIVELOG mode.

SQL> alter system set log_archive_dest_1='LOCATION=/u01/archives/' scope=both;
System altered.

SQL> alter system set log_archive_format = 'archive_%t_%s_%r.arc' scope=spfile;                
System altered.

3. Check location has reflected or not.

SQL> archive log list;
Database log mode No Archive Mode
Automatic archival Enabled
Archive destination /u01/archives/
Oldest online log sequence 2296
Current log sequence 2299

4. Shut down the database

SQL> shutdown immediate
Database closed.
Database dismounted.
ORACLE instance shut down.

5. Startup in mount mode to change archive log mode

SQL> startup mount

ORACLE instance started.
 
Total System Global Area 535662592 bytes

Fixed Size 1375792 bytes
Variable Size 385876432 bytes
Database Buffers 142606336 bytes
Redo Buffers 5804032 bytes
Database mounted.

6. Enable archive log

SQL> alter database archivelog;

Database altered.

7. Open database

SQL> alter database open;

Database altered.
8. Apply log switch to check archives generating at new location.

SQL> alter system switch logfile;

System altered.

9.Check /verify archivelog mode.

SQL> SELECT LOG_MODE FROM V$DATABASE;
 
LOG_MODE
------------
ARCHIVELOG

OR

SQL> ARCHIVE LOG LIST

Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u01/archives/
Oldest online log sequence 2296
Next log sequence to archive 2299
Current log sequence 2299
 
To change the Oracle database in NOARCHIVELOG mode
 
1. Shutdown your running database.

SQL> shut immediate

Database closed.
Database dismounted.
ORACLE instance shut down.
 
2. Start your database in MOUNT mode.

 SQL> startup mount

ORACLE instance started.
 
Total System Global Area 1025298432 bytes

Fixed Size 1341000 bytes
Variable Size 322963896 bytes
Database Buffers 696254464 bytes
Redo Buffers 4739072 bytes
Database mounted.

SQL> alter database noarchivelog;
 
Database altered.

 SQL> alter database open;
 
Database altered.
 
SQL> archive log list

Database log mode No Archive Mode
Automatic archival Disabled
Archive destination /u01/archives
Oldest online log sequence 1
Current log sequence 1


SQL> select name,log_mode from v$database;

NAME LOG_MODE
--------- ------------
ORCL NOARCHIVELOG


Database changed to NOARCHIVELOG mode


I hope this article helped you. Your suggestions/feedback are most welcome.

Keep learning... Have a great day!!!

Friday 28 November 2014

How to re-open expired oracle database account without change password



Imagine that you have an expired Oracle Database account and you have an urgent need to recover it. Maybe you don’t have any chance to ask that user to change password, or maybe you expired such an account that used by a production application by mistake!

-yes, I confess; it was me who experienced that situation-

If so, do what I did; calm down and take a deep breath and imagine that you are the one who survived after a big disaster on the earth. Just kidding, it’s not a big trouble.

Anyway, I couldn’t find any documented solution for that by Oracle, but found a way to accomplish this task:
Alter user’s password with existing password. Yes, it works. Let’s make a short demo:
    1. Create a user
    2. Expire it
    3. Alter user’s password with existing password to unexpire

1. CREATE AN ACCOUNT NAME TEST

SQL> CREATE USER TEST IDENTIFIED BY "manager";

User Created

SQL> SELECT username,account_status,expiry_date FROM dba_users WHERE username='TEST';

USERNAME ACCOUNT_STATUS EXPIRY_DATE
-------- -------------- -----------
TEST OPEN

2. EXPIRE IT
 
SQL> ALTER USER TEST PASSWORD EXPIRE;

User altered.


SQL> SELECT username,account_status,expiry_date
FROM dba_users
WHERE username = 'TEST';

USERNAME ACCOUNT_STATUS EXPIRY_DATE
-------- -------------- ------------
TEST EXPIRED 19/12/2012
 
3. GET THE EXISTING PASSWORD

SQL> SELECT DBMS_METADATA.get_ddl ('USER', 'TEST')
FROM DUAL;

CREATE USER "TEST" IDENTIFIED BY VALUES 'S:24BF9B8EBC5BC5B609D01915E089AF86D13E1F0627A729146708F5296E32;806B1E705874556A'
DEFAULT TABLESPACE "USERS"
TEMPORARY TABLESPACE "TEMP"
PASSWORD EXPIRE
 
4.EDIT ABOVE SCRIPT TO HAVE ALTER STATEMENT AND EXECUTED IT

SQL> ALTER USER "TEST"
IDENTIFIED BY VALUES 'S:4F5BD279183624CB94C3E67420A1E748A484183579F89E64B98ECB17A162;806B1E705874556A';

User altered.


SQL>SELECT username,account_status, expiry_date FROM dba_users WHERE username = 'TEST';

USERNAME ACCOUNT_STATUS EXPIRY_DATE
-------- -------------- -----------
TEST OPEN


5.OPTIONALLY DELETE TUTORIAL OBJECT


SQL> Drop user TEST cascade;




I hope this article helped you. Your suggestions/feedback are most welcome.
Keep learning... Have a great day!!!


 

Wednesday 26 November 2014

How to Resolved the Account Locked (Timed) issue?


For application user account, you may come across issue where user account get lock very frequently.

To avoid frequent user account lock issue you can create new profile with unlimited resource limit.

Below are the detail step by step to resolve user account lock issue.

Details:
Oracle Database Version:
11g R2

 Application User: APPUSR
Error: ORA-28000: the account is locked

Login as SYSDBA

SQL> conn /as sysdba

Check the APPSUSR account status.

SQL> SELECT username, account_status,PROFILE FROM dba_users WHERE username= ‘APPUSR’;

USERNAME ACCOUNT_STATUS PROFILE
-------------------- -------------------- ---------------
APPUSR LOCKED(TIMED) DEFAULT

Here we can see the account status is LOCKED (TIMED) and the default user’s profile is DEFAULT.

Check the resource limits of DEFAULT profile.

SQL> SELECT resource_name,resource_type,limit FROM dba_profiles WHERE profile='DEFAULT';

RESOURCE_NAME RESOURCE LIMIT
-------------------------------- -------- ----------
COMPOSITE_LIMIT KERNEL UNLIMITED
SESSIONS_PER_USER KERNEL UNLIMITED
CPU_PER_SESSION KERNEL UNLIMITED
CPU_PER_CALL KERNEL UNLIMITED
LOGICAL_READS_PER_SESSION KERNEL UNLIMITED
LOGICAL_READS_PER_CALL KERNEL UNLIMITED
IDLE_TIME KERNEL UNLIMITED
CONNECT_TIME KERNEL UNLIMITED
PRIVATE_SGA KERNEL UNLIMITED
FAILED_LOGIN_ATTEMPTS PASSWORD 10
PASSWORD_LIFE_TIME PASSWORD UNLIMITED
PASSWORD_REUSE_TIME PASSWORD UNLIMITED
PASSWORD_REUSE_MAX PASSWORD UNLIMITED
PASSWORD_VERIFY_FUNCTION PASSWORD NULL
PASSWORD_LOCK_TIME PASSWORD UNLIMITED
PASSWORD_GRACE_TIME PASSWORD UNLIMITED

All resource limits for DEFAULT profile is set to UNLIMITED, but only for FAILED_LOGIN_ATTEPTS attribute, it’s set to some value (10). Due to this the user account keeps getting locked(timed).When we check in the Oracle Documentations, it’s stated that FAILED_LOGIN_ATTEPTS attribute for DEFAULT profile has been changed from 10.2.0.1 from UNLIMITED to 10.

What we can do is, either we may need to change the resource limit for FAILED_LOGIN_ATTEPTS attribute in DEFAULT profile, or create a new profile for that user with FAILED_LOGIN_ATTEPTS attribute value set to UNLIMITED. But for security reasons, we will not tamper the DEFAULT profile, which is not recommended too. Then let’s go for creating a new profile and assign that profile to the user.

Create a profile.

SQL> CREATE PROFILE APPUSR_DEFAULT LIMIT
COMPOSITE_LIMIT UNLIMITED
SESSIONS_PER_USER UNLIMITED
CPU_PER_SESSION UNLIMITED
CPU_PER_CALL UNLIMITED

LOGICAL_READS_PER_SESSION UNLIMITED
LOGICAL_READS_PER_CALL UNLIMITED
IDLE_TIME UNLIMITED
CONNECT_TIME UNLIMITED
PRIVATE_SGA UNLIMITED
FAILED_LOGIN_ATTEMPTS UNLIMITED
PASSWORD_LIFE_TIME UNLIMITED
PASSWORD_REUSE_TIME UNLIMITED
PASSWORD_REUSE_MAX UNLIMITED
PASSWORD_VERIFY_FUNCTION NULL
PASSWORD_LOCK_TIME UNLIMITED
PASSWORD_GRACE_TIME UNLIMITED;


Profile created.

Assign the newly created profile to the user as default profile.

SQL> ALTER USER appusr PROFILE appusr_default;

User altered.

Unlock the user account:

SQL> ALTER USER appusr ACCOUNT UNLOCK;

User altered.

Now check again the status of APPUSR user.

SQL> SELECT username, account_status FROM dba_users WHERE username= ‘APPUSR’;

USERNAME ACCOUNT_STATUS    PROFILE
-------------------- --------------------
APPUSR     OPEN           APPUSR_DEFAULT





I hope this article helped you. Your suggestions/feedback are most welcome.

Keep learning... Have a great day!!!