Pages

Thursday, September 23, 2010

Enable Archive mode in oracle 10g



Noarchive Mode:


When you run your database in NOARCHIVELOG mode, you disable the archiving of the redo log. The database control file indicates that filled groups are not required to be archived. Therefore, when a filled group becomes inactive after a log switch, the group is available for reuse by LGWR.
NOARCHIVELOG mode protects a database from instance failure but not from media failure.
In NOARCHIVELOG mode you cannot perform online tablespace backups, nor can you use online tablespace backups 



Archive Mode:



When you run a database in ARCHIVELOG mode, you enable the archiving of the redo log. The database control file indicates that a group of filled redo log files cannot be reused by LGWR until the group is archived. A filled group becomes available for archiving immediately after a redo log switch occurs.
The archiving of filled groups has these advantages:
  • A database backup, together with online and archived redo log files, guarantees that you can recover all committed transactions in the event of an operating system or disk failure.
  • If you keep an archived log, you can use a backup taken while the database is open and in normal system use.


    Benifits:


1. We can able to take database backup ONLINE.
2. No Need to Down Oracle DB Server
3. We can better Manage our Backup Policy through RMAN
4. Limited DBA task
5. We can able to RECOVER our database point-in-time


to enable Archive mode:


1. shutdown immediate
2. startup mount 
3. alter database archivelog;
4. alter database open



optionaly you can set a destination for archiving else archive files will create in Flash_Recovery_Area




--for win   alter system set log_archive_dest_1='location=c:\youfolder';

--for linux alter system set log_archive_dest_1='location=/u01/app/archive';




you can set upto 10 destination (including flash recover area)

using parameter log_archive_dest_n       where n is from 1 to 10.




some views that can provide us with information reguarding archives, such as:



v$DATABASE
v$ARCHIVED_LOG
V$ARCHIVE_DEST
V$ARCHIVE_PROCESSES
v$BACKUP_REDOLOG
v$LOG
V$LOG_HISTORY




Monday, August 9, 2010

create manual database

step 1
create folder on any drive (d:\mydb) as described
1.adump
2.bdump
3.cdump
4.udump
5.flash_recovery_area

6.pfile
7.redolog
8.datafile

now create a pfile (or get it from d:\oracle\product\10.2.0\admin\orcl\pfile\init.ora)
copy this pfile into d:\mydb\pfile\init.ora
********************************************
pfile must  contain  these parameters
******************************************


##############################################################################
# Copyright (c) 1991, 2001, 2002 by Oracle Corporation
##############################################################################
###########################################
# Archive
###########################################
log_archive_format=ARC%S_%R.%T
###########################################
# Cache and I/O
###########################################
db_block_size=8192
db_file_multiblock_read_count=16
###########################################
# Cursors and Library Cache
###########################################
open_cursors=300
###########################################
# Database Identification
###########################################
db_domain=""
db_name=mydb
###########################################
# Diagnostics and Statistics
###########################################
background_dump_dest=d:\mydb\bdump##############################################################################
# Copyright (c) 1991, 2001, 2002 by Oracle Corporation
##############################################################################
###########################################
# Archive
###########################################
log_archive_format=ARC%S_%R.%T
###########################################
# Cache and I/O
###########################################
db_block_size=8192
db_file_multiblock_read_count=16
###########################################
# Cursors and Library Cache
###########################################
open_cursors=300
###########################################
# Database Identification
###########################################
db_domain=""
db_name=orcl
###########################################
# Diagnostics and Statistics
###########################################
background_dump_dest=d:\mydb\bdump
core_dump_dest=d:\mydb\cdump
user_dump_dest=d:\mydb\udump
###########################################
# File Configuration
###########################################
control_files=("d:\mydb\controlfile\control01.ctl", "d:\mydb\controlfile\control02.ctl", "d:\mydb\controlfile\control03.ctl")
db_recovery_file_dest=d:\mydb\flash_recovery_area
db_recovery_file_dest_size=4G
###########################################
# Job Queues
###########################################
job_queue_processes=10
###########################################
# Miscellaneous
###########################################
compatible=10.2.0.1.0
###########################################
# Network Registration
###########################################
local_listener=LISTENER_ORCL
###########################################
# Processes and Sessions
###########################################
processes=150
###########################################
# SGA Memory
###########################################
sga_target=609222656
###########################################
# Security and Auditing
###########################################
audit_file_dest=d:\mydb\adump
remote_login_passwordfile=SHARED -- for remote authentication
###########################################
# Shared Server
###########################################
dispatchers="(PROTOCOL=TCP) (SERVICE=orclXDB)"
###########################################
# Sort, Hash Joins, Bitmap Indexes
###########################################
pga_aggregate_target=202375168
###########################################
# System Managed Undo and Rollback Segments
###########################################
undo_management=AUTO
undo_tablespace=UNDOTBS1
***********************************
now save this parameter file as d:\mydb\pfile\init.ora


 
start sqlplus


 1.shutdown immediate
2.startup nomount pfile=d:\mydb\pfile\init.ora


write and execute following create database command.


create database db_name
user sys    identified by password_sys
user system identified by password_system
character set          we8iso8859p1
national character set utf8
set default smallfile tablespace
-- database logging clauses
logfile  

group 1 ('d:\mydb\redolog\redo_1a.log', 'd:\mydb\redolog\redo_1b.log') size 50m,
group 2 ('d:\mydb\redolog\redo_2a.log', 'd:\mydb\redolog\redo_2b.log') size 50m


archivelog --- for archive mode
force logging
-- Tablespace Clauses
extent management local
datafile 'd:\mydb\datafile\system01.dbf' size 500M [reuse] autoextend off
sysaux datafile 'd:\mydb\datafile\sysaux01.dbf' size 300M [reuse] autoextend off
default tablespace users datafile 'd:\mydb\datafile\data01.dbf' size 100M autoextend on extent management local
default temporary tablespace temp tempfile 'd:\mydb\datafile\temp01.dbf' size 20M
undo tablespace undotbs1 datafile 'd:\mydb\datafile\undo.dbf' size 50M

after database creation run following scripts located at
oracle_home\rdbms\admin
1.catalog.sql --- for datadictionary
2.catproc.sql --- for PLSQl Packages etc

to create spfile
sql> create spfile from pfile='d:\mydb\pfile\init.ora'

to create database service

execute following command on cmd
oradim -new -sid mydb

Restrict User Access


 
suppose you have five machines and five users ( one user per machine)
Note: these users are database users...
e.g

User name
Machine name
User1
WORKGROUP\PC-01
User2
WORKGROUP\PC-02
User3
WORKGROUP\PC-03
User4
WORKGROUP\PC-04
User5
WORKGROUP\PC-05


So according to above table ye create a table in our database as sys user

Create table user_record
(user_name               varchar2(25),
Machine_name         varhcar2(30));

now insert user info ….

Insert into user_record (user_name,machine_name)
Values (‘USER1’,’ WORKGROUP\PC-01’);

Insert into user_record (user_name,machine_name)
Values (‘USER2’,’ WORKGROUP\PC-02’);

Insert into user_record (user_name,machine_name)
Values (‘USER3’,’ WORKGROUP\PC-03’);

Insert into user_record (user_name,machine_name)
Values (‘USER4’,’ WORKGROUP\PC-04’);

Insert into user_record (user_name,machine_name)
Values (‘USER4’,’ WORKGROUP\PC-04’);

Insert into user_record (user_name,machine_name)
Values (‘USER5’,’ WORKGROUP\PC-05’);

COMMIT;


NOW CREATE AFTER LOGON ON DATABASE TRIGGER AS SYS..

 *******************************************************************************************************
CREATE OR REPLACE TRIGGER USER_CHECK

  AFTER LOGON ON DATABASE

  DECLARE
 U_NAME       VARCHAR2(20);
  M_NAME     VARCHAR2(20);

BEGIN
 SELECT USER_NAME, MACHINE_NAME INTO U_NAME,M_NAME
 FROM USER_RECORD
 WHERE (USER_NAME, MACHINE_NAME) IN
    (SELECT USERNAME, MACHINE FROM V$SESSION WHERE SID=(SELECT DISTINCT SID FROM
V$MYSTAT));

  EXCEPTION

 WHEN NO_DATA_FOUND THEN

 RAISE_APPLICATION_ERROR(-20000,’YOU ARE NOT AUTHRIZE TO LOGIN FROM THIS MACHINE’);

 END;
 *******************************************************************************************************


this will connect 


user1 from WORKGROUP\PC-01 only 
user2 from WORKGROUP\PC-02 only
user3 from WORKGROUP\PC-03 only
user4 from WORKGROUP\PC-04 only
user5 from WORKGROUP\PC-05 only



HOPE THIS WILL WORK