Showing posts with label DATABASE CREATION. Show all posts
Showing posts with label DATABASE CREATION. Show all posts

Wednesday 14 August 2019

Check the last incarnation restore time of oracle database


Check the last incarnation restore time when the database is started with resetlogs command with following command.

Incarnation is the time when the database is started with resetlogs command. If you start the database is the incarnation, then all available archivelog and backup become invalid. If you want to restore old incarnation, then you need to set the incarnation level in RMAN to restore or recover old SCN.

Always take a fresh backup of the database when you start the database in resetlog. Because when the database is open with resetlogs all redo Sequence no is reset and start from one.

It will show you the last incarnation time when the database is up with resetlogs commands.

SELECT incarnation#,
resetlogs_change#,
TO_CHAR(resetlogs_time, 'dd-mon-yyyy hh24:mi:ss') db_restored_time ,
scn_to_timestamp(resetlogs_change#) db_recovery_till_time
FROM v$database_incarnation
WHERE resetlogs_change# !=
(SELECT MIN(resetlogs_change#) FROM v$database_incarnation
);

List of incarnation:

select incarnation#, resetlogs_change# from v$database_incarnation;

List incarnation from RMAN prompt:

RMAN> list incarnation of database;

When you open the database in resetlogs then a new incarnation is created at the database level. If you tried to restore the database before incarnation state, then you got the error:
RMAN-20208: until change is before resetlogs change

Then you need to check the SCN from incarnation commands:
Example:

RMAN> list incarnation of database;

 DB Key Inc Key DB Name DB ID         STATUS  Reset SCN Reset Time
------ ------- ------- ------------- ------- --------- -----------
1      1       ORCL     1235491512   PARENT  1         03-AUG-17
2      2       ORCL     1235491512   PARENT  543000    10-OCT-17
3      3       ORCL     1235491512   CURRENT 548000    10-OCT-17


If I want to restore the SCN no 54700 previous then the current incarnation number, then I will get the rman error:
RMAN-20208: until change is before resetlogs change

run{
set until scn=547000;
restore database;
recover database;
}
executing command: set until clause
using target database control file instead of recovery catalog
RMAN-00571: ===========================================================
RMAN-00569: =============== error message stack follows ===============
RMAN-00571: ===========================================================
RMAN-03002: failure of set command at 10/10/2017 9:10:11
RMAN-20208: until change is before resetlogs change

Solution:
to overcome this problem, we need to set the database to old incarnation:

RMAN> shutdown immediate
RMAN> startup mount
RMAN> reset database to incarnation 2;
database reset to incarnation 2
Then after restore, you can check incarnation status again:

RMAN> run
2> {
3> set until scn=547000;
4> restore database;
5> recover database;
6> }

RMAN> alter database open resetlogs;
database opened
RMAN> list incarnation of database;
using target database control file instead of recovery catalog
List of Database Incarnations

DB Key Inc Key DB Name DB ID         STATUS  Reset SCN Reset Time
------ ------- ------- ------------- ------- --------- -----------
1      1       ORCL     1235491512   PARENT  1         03-AUG-17
2      2       ORCL     1235491512   PARENT  543000    10-OCT-17
4      4       ORCL     1235491512   CURRENT 547000    10-OCT-17
3      3       ORCL     1235491512   ORPHAN  548000    10-OCT-17







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

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

Monday 13 October 2014

STEPS TO CREATE ORACLE DATABASE MANUALLY ON LINUX



There are basically two ways to create an Oracle database:
1. Using the Database Configuration Assistant (DBCA)
2. With the SQL create database statement
This article shows you steps using second option to create a database manually on Linux.

STEP 1: Install oracle software first using  ./runinstaller


STEP 2: Create all the necessary directories. Followings are my directories:

testdb1]$ ls
admin backup archive
admin]$ ls
data redo control bdump udump adump cdump

STEP 3: Next prepare the database creation script.

To create the database, issue the CREATE DATABASE command. The CREATE DATABASE command creates data files, control files, redo log files, the system tablespace along with the data file associated with it, and a system rollback segment. It creates the tables that underlie the data dictionary, assigns the character set to the database, optionally sets the database time zone, and mounts and opens the database for use.
The general format follows:
CREATE DATABASE [database name]
[CONTROLFILE REUSE]
[LOGFILE [GROUP integer] file specification]
[MAXLOGFILES integer]
[MAXLOGMEMBERS integer]
[MAXLOGHISTORY integer]
[MAXDATAFILES integer]
[MAXINSTANCES integer]
[ARCHIVELOG|NOARCHIVELOG]
[CHARACTER SET charset]
[NATIONAL CHARACTER SET charset]
[DATAFILE filespec [autoextend]]
[DEFAULT TEMPORARY TABLESPACE tablespace filespec]
[UNDO TABLESPACE tablespace DATAFILE filespec]
[SET TIME_ZONE [time_zone_region]];

Database is the name of the database that you are creating. If the name of the database is omitted, the initialization parameter DB_NAME is used. The database name should be the same as the DB_NAME parameter.

Control file reuse specifies that an existing control file identified by the control file parameter in the initialization file should be reused.
Log file group identifies the names of the log files to be used and the group to which they belong.
MAXLOGFILES specifies the maximum number of redo log files that can ever be created in the database.

MAXLOGMEMBERS specifies the maximum number of redo log file members that any given log file group can have in the database.
MAXLOGHISTORY specifies the maximum number of archive redo logs for automatic media recovery.

AUTOEXTEND enables or disables the automatic extension of SYSTEM tablespace's data files in the database.

MAXDATAFILES controls the initial sizing of the data file section of the control file at the time when the CREATE DATABASE or CREATE CONTROLFILE commands are issued. If an attempt is made to add a new file with a number greater than the value set to the MAXDATAFILES parameter, but less than the DB_FILES parameter, it causes the control file to expand automatically so that the data files section can accommodate the new files.

The MAXINSTANCES parameter is optional and is primarily used for Real Application Clusters (RAC) environments. The default, if left unspecified, is 1.

The optional ARCHIVELOG|NOARCHIVELOG statement provides the option for the database's redo log files to automatically initially be archived. This is an optional statement at database creation time. NOARCHIVELOG is the default if ARCHIVELOG is not specified. If, after database creation, you choose to change the archive log mode of the database, you can use the ALTER DATABASE command to change between the two. ARCHIVELOG establishes that the redo logs can be reused, but only after they have been archived. NOARCHIVELOG establishes that the redo logs can be reused without archiving their contents.

CHARACTER SET is the character set that the database uses to store the data.
The NATIONAL CHARACTER SET parameter is optional and is used to store data in columns specifically defined as NCHAR, NCLOB, or NVARCHAR2.

NOTE
More on National Language Support (NLS) and its associated parameters will be covered in Chapter 7, "Globalization Support."
DATAFILE, when connected directly to the CREATE DATABASE statement, is the file specification used to specify the data files to be used for the system tablespace.
DEFAULT TEMPORARY TABLESPACE instructs the database to assign this tablespace to all users created without having a temporary tablespace specified.
UNDO TABLESPACE creates and names the undo tablespace and the associated data files that should be used to store undo records for the database if you have specified (as Oracle suggests) UNDO_MANAGEMENT=AUTO in the initialization parameter file.

Following is my script "testdb1.sql"

CREATE DATABASE "testdb1"
MAXLOGFILES 5
MAXLOGMEMBERS 5
MAXDATAFILES 100
MAXINSTANCES 1
MAXLOGHISTORY 292
LOGFILE
GROUP 1 '/home/oracle/testdb1/admin/redo/redo1.log' SIZE 10M,
GROUP 2 '/home/oracle/testdb1/admin/redo/redo2.log' SIZE 10M,
GROUP 3 '/home/oracle/testdb1/admin/redo/redo3.log' SIZE 10M
DATAFILE
'/home/oracle/testdb1/admin/data/system.dbf' size 100m,
'/home/oracle/testdb1/admin/data/usr04.dbf' size 10m
sysaux datafile '/home/oracle/testdb1/admin/data/sysaux.dbf' size 100m
undo tablespace undotbs
datafile '/home/oracle/testdb1/admin/data/undo.dbf' size 50m
CHARACTER SET US7ASCII;

STEP 4: Prepare the init file. Like this one [inittestdb1.ora]

*.audit_file_dest='/home/oracle/testdb1/admin/adump'
*.background_dump_dest='/home/oracle/testdb1/admin/bdump'
*.compatible='10.2.0.3.0'
*.control_files='/home/oracle/testdb1/admin/control/control01.ctl',
'/home/oracle/testdb1/admin/control/control02.ctl','/home/oracle/testdb1/admin/control/control03.ctl'
*.core_dump_dest='/home/oracle/testdb1/admin/cdump'
*.db_block_size=8192
*.db_domain=''
*.db_file_multiblock_read_count=16
*.db_name='testdb1'
*.dispatchers='(PROTOCOL=TCP) (SERVICE=indiaXDB)'
*.job_queue_processes=10
*.log_archive_dest_1='LOCATION=/home/oracle/testdb1/archive'
*.log_archive_format='%t_%s_%r.dbf'
*.open_cursors=300
*.pga_aggregate_target=200278016
*.processes=150
*.remote_login_passwordfile='EXCLUSIVE'
*.sga_target=601882624
*.undo_management='AUTO'
*.undo_tablespace='UNDOTBS'
*.user_dump_dest='/home/oracle/testdb1/admin/udump'
*.db_recovery_file_dest='/home/oracle/testdb1/backup'
*.db_recovery_file_dest_size=2147483648

STEP 5: Now perform the following steps:

$ export ORACLE_SID=testdb1

$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.3.0 - Production on Thu May 22 17:35:28 2008
Copyright (c) 1982, 2006, Oracle. All Rights Reserved.
Connected to an idle instance.

SQL> startup pfile=/u01/app/oracle/product/10.2.0/db_1/dbs/inittestdb1.ora nomount
ORACLE instance started.
Total System Global Area 603979776 bytes
Fixed Size 1263176 bytes
Variable Size 167774648 bytes
Database Buffers 427819008 bytes
Redo Buffers 7122944 bytes

SQL> @testdb1.sql
Database created

CAUTION
If you use the CONTROLFILE REUSE command, make absolutely sure that you don't specify a control file attached to another database. The reuse command will cause it to be overwritten. Although this will not cause the database and instance to crash (the one that had the control file overwritten) immediately, it is cause for care and concern. Oracle will not tell you that you are overwriting the wrong file, and, if you don't realize it, this can cause the overwritten database to not start after it is shut down.
If you are using Oracle Managed File (OMF) systems and you have specified the appropriate OMF initialization parameters in the parameter file (DB_CREATE_FILE_DEST and DB_CREATE_ONLINE_DEST_n), the following statement creates the database:
Startup nomount
Create database
Default temporary tablespace mydb1temp;
At this point, your database now contains data files (at least a limited number of them), control files, redo log files, the SYS and SYSTEM users, and all the internal data dictionary tables, but no data dictionary views. You can see the dynamic performance views, such as V$LOGFIEL, V$CONTROLFILE, and V$DATAFILE. If you have not yet changed the default passwords for SYS (change_on_install) and SYSTEM (manager), now is a good time to do it.

STEP 6: Run the catalog.sql and catproc.sql scripts

So your database is create. Now just run the catalog.sql and catproc.sql scripts.
so run this script in open stage of the instance
You will find the in $ cd $ORACLE_HOME/rdbms/admin

SQL> @$ORACLE_HOME/rdbms/admin/catalog.sql
SQL> @$ORACLE_HOME/rdbms/admin/catproc.sql
SQL> select name from v$database;
NAME
---------
TESTDB1

STEP 7: Create a Server Parameter File

This step is optional, although highly recommended by Oracle. Your Oracle database was created by starting the instance with a parameter file, or PFILE. Because it is editable, you can migrate, easily, your new database to using a server parameter file. Creation of the server parameter file (or spfile) is accomplished by issuing the following statement:
SQL> Create spfile from pfile;
This command looks in the default location (ORACLE_HOME/dbs) for an initialization parameter file (or PFILE) with the default name. If your database is named mydb1, the default name would be initmydb1.ora. The command creates an spfile with the default name in the same default location unless otherwise specified.

STEP 8: Back Up the Database

Now that your database is created, take this chance to shut down the database and take a cold backup of the new database.

STEP 9: Create Additional Tablespaces

After the backups are finished, you can restart the database and create new tablespaces, tables, and users; add data; and in general, open the new database for business.

Now Database is ready to use



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