When we define varchar2 data type to particular column in table, same time we define its length or you can say its range but knowledge point is how many byte oracle server take? to store particular string or number values its depend upon the character set .So my this post explain to you how many byte oracle server take to store values.
Explanation:-
SQL> create table test(id varchar2(10);
table created
SQL> insert into test values('abcdefghij');
one row inserted
SQL>commit;
SQL> select length ('abcdefghij') from dual; **/ length is 10 so no error has been generated after execution of insert statement /*****
SQL> insert into test values('1234567891');
one row inserted
SQL> commit;
SQL> select length('1234567891') from dual; **/ length is 10 so no error has been generated after execution of insert statement /*****
LENGTH('1234567891')
--------------------
10
SQL>insert into test values('12345678910');
ERROR at line 1:
ORA-12899: value too large for column "SCOTT"."TEST"."ID" (actual: 11, maximum:
10)
**/ After execution of statement oracle server gives error because insert statement cross specified range /***
NOTE:- that's means oracle server allowed you to insert only number of numeric and string values as per you specified range of column while creation of table.
SQL> create table test1 (id VARCHAR2(10 byte));
Table created.
note:- now oracle server take only10byte data that means insert only those numeric and string values which within 10 bytes.if numeric or string values cross 10 byte range then oracle server gives error.
Thursday, 27 June 2013
how to kill process which is running on particular session.
Some time we needs to terminate current process which is running on particular users session.in this process first we find out which process is running on particular session then we first get it id and serial number,through this two attribute we can kill the oracle process.
note:- this process is very important to kill oracle process without any impact.
Oracle session process kill steps:-
SQL>SET LINESIZE 100
COLUMN spid FORMAT A10
COLUMN username FORMAT A10
COLUMN program FORMAT A45
SELECT s.inst_id,
s.sid,
s.serial#,
p.spid,
s.username,
s.program
FROM gv$session s
JOIN gv$process p ON p.addr = s.paddr AND p.inst_id = s.inst_id
WHERE s.type != 'BACKGROUND';
SQL> ALTER SYSTEM KILL SESSION 'sid,serial#';
In a RAC environment, you optionally specify the INST_ID, shown when querying the GV$SESSION view. This allows you to kill a session on different RAC node.
SQL> ALTER SYSTEM KILL SESSION 'sid,serial#,@inst_id';
The KILL SESSION command doesn't actually kill the session. It merely asks the session to kill itself. In some situations, like waiting for a reply
from a remote database or rolling back transactions, the session will not kill itself immediately and will wait for the current operation to complete.
In these cases the session will have a status of "marked for kill". It will then be killed as soon as possible.
SQL> ALTER SYSTEM KILL SESSION 'sid,serial#' IMMEDIATE;
*************END*************
note:- this process is very important to kill oracle process without any impact.
Oracle session process kill steps:-
SQL>SET LINESIZE 100
COLUMN spid FORMAT A10
COLUMN username FORMAT A10
COLUMN program FORMAT A45
SELECT s.inst_id,
s.sid,
s.serial#,
p.spid,
s.username,
s.program
FROM gv$session s
JOIN gv$process p ON p.addr = s.paddr AND p.inst_id = s.inst_id
WHERE s.type != 'BACKGROUND';
SQL> ALTER SYSTEM KILL SESSION 'sid,serial#';
In a RAC environment, you optionally specify the INST_ID, shown when querying the GV$SESSION view. This allows you to kill a session on different RAC node.
SQL> ALTER SYSTEM KILL SESSION 'sid,serial#,@inst_id';
The KILL SESSION command doesn't actually kill the session. It merely asks the session to kill itself. In some situations, like waiting for a reply
from a remote database or rolling back transactions, the session will not kill itself immediately and will wait for the current operation to complete.
In these cases the session will have a status of "marked for kill". It will then be killed as soon as possible.
SQL> ALTER SYSTEM KILL SESSION 'sid,serial#' IMMEDIATE;
*************END*************
Create database link using host:port/service new syntax
when we want to access data from different database that time we use database link through service name to access particular data.so my this post is for to create database link without change in to tnsname.ora file that means without using service name.
Example:-
Targate Database: orcl
Source Database : test
1)target database
SQL>create user test
identified by test
default tablespace test;
SQL>grant connect,resource to test;
SQL> connect scott/tiger;
SQL> create table test(id number);
SQL>begin
for i in 1..10 loop
insert into test values(i);
end loop;
end;
/
SQL> commit;
SQL> select count(*) from test;
COUNT(*)
----------
10
SQL>
2)Source Database
SQL> CREATE DATABASE LINK test_db_link
CONNECT TO scott IDENTIFIED BY tiger
USING '192.168.128.135:1521/db11g'; ---(use ip address or host_name which you specified in listener file)
SQL>select * from test@test_link;
COUNT(*)
----------
10
********END*************
Example:-
Targate Database: orcl
Source Database : test
1)target database
SQL>create user test
identified by test
default tablespace test;
SQL>grant connect,resource to test;
SQL> connect scott/tiger;
SQL> create table test(id number);
SQL>begin
for i in 1..10 loop
insert into test values(i);
end loop;
end;
/
SQL> commit;
SQL> select count(*) from test;
COUNT(*)
----------
10
SQL>
2)Source Database
SQL> CREATE DATABASE LINK test_db_link
CONNECT TO scott IDENTIFIED BY tiger
USING '192.168.128.135:1521/db11g'; ---(use ip address or host_name which you specified in listener file)
SQL>select * from test@test_link;
COUNT(*)
----------
10
********END*************
Wednesday, 26 June 2013
Create database link without changing tnsname.ora file.
when we want to access data from different database that time we use database link through service name to access particular data.so my this post is for to create database link without change in to tnsname.ora file that means without using service name.
Example:-
Targate Database: orcl
Source Database : test
1)target database
SQL>create user test
identified by test
default tablespace test;
SQL>grant connect,resource to test;
SQL> connect scott/tiger;
SQL> create table test(id number);
SQL>begin
for i in 1..10 loop
insert into test values(i);
end loop;
end;
/
SQL> commit;
SQL> select count(*) from test;
COUNT(*)
----------
10
SQL>
2)Source Database
SQL> create database link test_link
connect to test identified by test
using using
'(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.128.135)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = db11g)
)
)' ;
SQL>select * from test@test_link;
COUNT(*)
----------
10
********END*************
Example:-
Targate Database: orcl
Source Database : test
1)target database
SQL>create user test
identified by test
default tablespace test;
SQL>grant connect,resource to test;
SQL> connect scott/tiger;
SQL> create table test(id number);
SQL>begin
for i in 1..10 loop
insert into test values(i);
end loop;
end;
/
SQL> commit;
SQL> select count(*) from test;
COUNT(*)
----------
10
SQL>
2)Source Database
SQL> create database link test_link
connect to test identified by test
using using
'(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.128.135)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = db11g)
)
)' ;
SQL>select * from test@test_link;
COUNT(*)
----------
10
********END*************
Friday, 14 June 2013
Secure externel password storage using oracle Wallet.
ORACLE WALLET: Secure external password storage using oracle Wallet.
Some time we create shell scripts or batch file etc. for database operation.In particulate file we specify the oracle user name and password so it will not secure that means any person can get our username and password through this file. So nullify this problem oracle provide the solution called as oracle wallet. Using this you can directly connect to oracle server using service name example: '/@db11g' no need to specify username and password. So no one can get your oracle user password.
:- ORACLE wallet creation steps.
[oracle@orcl admin]$ vi sqlnet.ora
stener.ora Network Configuration File: /u01/app/oracle/product/11.2.0/db_1/network/admin/sqlnet.ora
# Generated by Oracle configuration tools.
WALLET_LOCATION =
(SOURCE =
(METHOD = FILE)
(METHOD_DATA =
(DIRECTORY =/u01/app/oracle/product/11.2.0/db_1/network/admin)
)
)
SQLNET.WALLET_OVERRIDE = TRUE
SSL_CLIENT_AUTHENTICATION = FALSE
SSL_VERSION = 0
[oracle@orcl admin]$ mkstore -wrl "/u01/app/oracle/product/11.2.0/db_1/network/admin" -create
Oracle Secret Store Tool : Version 11.2.0.1.0 - Production
Copyright (c) 2004, 2009, Oracle and/or its affiliates. All rights reserved.
Enter password:
Enter password again:
(password should be a strong password which contain character/number/special value)
[oracle@orcl admin]$ mkstore -wrl "/u01/app/oracle/product/11.2.0/db_1/network/admin" -createCredential db11g scott tiger
(db11g is service name which specified into tnsname.ora and listener.ora then username and password)
Oracle Secret Store Tool : Version 11.2.0.1.0 - Production
Copyright (c) 2004, 2009, Oracle and/or its affiliates. All rights reserved.
Enter wallet password: (Enter the oracle wallet password which specified on above command)
[oracle@orcl admin]$ mkstore -wrl "/u01/app/oracle/product/11.2.0/db_1/network/admin" -listCredential
Oracle Secret Store Tool : Version 11.2.0.1.0 - Production
Copyright (c) 2004, 2009, Oracle and/or its affiliates. All rights reserved.
Enter wallet password:
List credential (index: connect_string username)
1: db11g scott
(this command shows the user entry in oracle wallet with there name and service name)
[oracle@orcl admin]$ sqlplus /@db11g (db11g is service name)
SQL*Plus: Release 11.2.0.1.0 Production on Fri Jun 14 21:42:55 2013
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL>
---Password credentials of existing wallet entries can be modified or deleted using the below commands.
Note:- every username should have different service name. so service name cant be conflict for username and his password.
Some time we create shell scripts or batch file etc. for database operation.In particulate file we specify the oracle user name and password so it will not secure that means any person can get our username and password through this file. So nullify this problem oracle provide the solution called as oracle wallet. Using this you can directly connect to oracle server using service name example: '/@db11g' no need to specify username and password. So no one can get your oracle user password.
:- ORACLE wallet creation steps.
[oracle@orcl admin]$ vi sqlnet.ora
stener.ora Network Configuration File: /u01/app/oracle/product/11.2.0/db_1/network/admin/sqlnet.ora
# Generated by Oracle configuration tools.
WALLET_LOCATION =
(SOURCE =
(METHOD = FILE)
(METHOD_DATA =
(DIRECTORY =/u01/app/oracle/product/11.2.0/db_1/network/admin)
)
)
SQLNET.WALLET_OVERRIDE = TRUE
SSL_CLIENT_AUTHENTICATION = FALSE
SSL_VERSION = 0
[oracle@orcl admin]$ mkstore -wrl "/u01/app/oracle/product/11.2.0/db_1/network/admin" -create
Oracle Secret Store Tool : Version 11.2.0.1.0 - Production
Copyright (c) 2004, 2009, Oracle and/or its affiliates. All rights reserved.
Enter password:
Enter password again:
(password should be a strong password which contain character/number/special value)
[oracle@orcl admin]$ mkstore -wrl "/u01/app/oracle/product/11.2.0/db_1/network/admin" -createCredential db11g scott tiger
(db11g is service name which specified into tnsname.ora and listener.ora then username and password)
Oracle Secret Store Tool : Version 11.2.0.1.0 - Production
Copyright (c) 2004, 2009, Oracle and/or its affiliates. All rights reserved.
Enter wallet password: (Enter the oracle wallet password which specified on above command)
[oracle@orcl admin]$ mkstore -wrl "/u01/app/oracle/product/11.2.0/db_1/network/admin" -listCredential
Oracle Secret Store Tool : Version 11.2.0.1.0 - Production
Copyright (c) 2004, 2009, Oracle and/or its affiliates. All rights reserved.
Enter wallet password:
List credential (index: connect_string username)
1: db11g scott
(this command shows the user entry in oracle wallet with there name and service name)
[oracle@orcl admin]$ sqlplus /@db11g (db11g is service name)
SQL*Plus: Release 11.2.0.1.0 Production on Fri Jun 14 21:42:55 2013
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL>
---Password credentials of existing wallet entries can be modified or deleted using the below commands.
mkstore -wrl <wallet_location> -modifyCredential <dbase_alias> <username> <password> mkstore -wrl <wallet_location> -deleteCredential <db_alias>
Note:- every username should have different service name. so service name cant be conflict for username and his password.
Transfer particulate single table from one database to other database.
Transfer particular single table from one database to other database.
Some time requirement is to transfer only one table to other database for development operation or any operation so that time impdp/expdp logical backup utility helps us to transfer table from one database to other database.so my bellow example showing you transfer one table using expdp/impdp.
Example:-
Target database:- orcl
Source database:- db11g
1]on target Database
[oracle@orcl expd]$ sqlplus
/as sysdba
SQL> create user rock
identified by rock
default tablespace users;
user created
SQL> grant connect,resource to rock;
Grant succeeded.
SQL> conn rock/rock
SQL> create table rock (id number);
table created
sql>begin
for i in 1...100000 loop
insert into rock values(i);
end loop;
end;
/
SQL> commit;
SQL> select count(*) from rock;
COUNT(*)
----------
100000
SQL>exit
[oracle@orcl expd]$expdp directory=expdp dumpfile=rock_table.dmp logfile=rock_table.log tables=rock.rock
2] copy perticuler table to source database through (FTP,hard drive etc.....) location /u02/dump.
3] on source Database
[oracle@db11g]$ mkdir -p /u02/dump
[oracle@db11g]$ sqlplus
/as sysdba
SQL>create directory dump as '/u02/dump';
SQL>create user rock
identified by rock
default tablespace test; (any tablespace of your database)
user created
SQL> Grant connect,resource to rock;
Grant succeeded.
SQL>!
[oracle@db11g]$impdp directory=expdp dumpfile=rock_table.dmp logfile=rock_table.log full=y
[oracle@db11g]$exit
SQL> conn rock/rock
SQL> select count(*) rock;
COUNT(*)
----------
100000
Note:- this blog is dedicated to all my collage friends.......
Thursday, 13 June 2013
Transfer tablespace from one database to other database.
Transfer tablespace from one database to other database.
there are many method's to transfer tablespace from one database to other other.In bellow example
i am using impdp/expdp utility to transfer tablespace.
Example:-
Target Database: orcl
Source Database: db11g
1] on target database
SQL> create tablespace test
datafile '/u01/app/oracle/oradata/db11g/test01.dbf' size 10g;
Tablespace created.
SQL> create user test
identified by test
default tablespace test;
User created.
SQL> grant connect , resource to test;
Grant succeeded.
SQL> conn test/test
SQL> create table test(id number);
SQL> begin
for i in 1..10 loop
insert into test values(i);
end loop;
end;
/
SQL> commit;
SQL>select count(*) from test;
COUNT(*)
----------
10
SQL> !
[oracle@orcl]$ expdp directory=expdp dumpfile=exp_tablespace.dmp logfile=exp_tablespace.log tablespaces=test
Export: Release 11.2.0.1.0 - Production on Fri Jun 14 16:40:16 2013
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Username: /as sysdba
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SYS"."SYS_EXPORT_TABLESPACE_01": /******** AS SYSDBA directory=expdp dumpfile=exp_tablespace.dmp logfile=exp_tablespace.log tablespaces=test
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 128 KB
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
. . exported "TEST"."TEST" 5.070 KB 10 rows
Master table "SYS"."SYS_EXPORT_TABLESPACE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SYS.SYS_EXPORT_TABLESPACE_01 is:
/u01/expd/exp_tablespace.dmp
Job "SYS"."SYS_EXPORT_TABLESPACE_01" successfully completed at 16:40:37
2] copy dumpfile to source database using ftp,hard drive etc....(/u01/expdp).
3] on source database.
[oracle@db11g]$ sqlplus
SQL*Plus: Release 11.2.0.1.0 Production on Fri Jun 14 16:14:12 2013
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Enter user-name: /as sysdba
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL>create directory expdp as '/u01/expdp'
SQL> create tablespace test
datafile '/u01/app/oracle/oradata/db11g/test01.dbf' size 10g;
Tablespace created.
SQL>create user test
identified by test
default tablespace test;
user created
SQL> grant connect , resource to test;
Grant succeeded.
SQL>exit
[oracle@db11g]$impdp directory=EXPDP dumpfile=exp_tablespace.dmp logfile=exp_tablespace.log full=y
Import: Release 11.2.0.1.0 - Production on Fri Jun 14 16:18:26 2013
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Username: /as sysdba
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
................
..............
[oracle@db11g]$ exit
SQL> conn test/test
SQL> select count(*) from test;
COUNT(*)
----------
10
there are many method's to transfer tablespace from one database to other other.In bellow example
i am using impdp/expdp utility to transfer tablespace.
Example:-
Target Database: orcl
Source Database: db11g
1] on target database
SQL> create tablespace test
datafile '/u01/app/oracle/oradata/db11g/test01.dbf' size 10g;
Tablespace created.
SQL> create user test
identified by test
default tablespace test;
User created.
SQL> grant connect , resource to test;
Grant succeeded.
SQL> conn test/test
SQL> create table test(id number);
SQL> begin
for i in 1..10 loop
insert into test values(i);
end loop;
end;
/
SQL> commit;
SQL>select count(*) from test;
COUNT(*)
----------
10
SQL> !
[oracle@orcl]$ expdp directory=expdp dumpfile=exp_tablespace.dmp logfile=exp_tablespace.log tablespaces=test
Export: Release 11.2.0.1.0 - Production on Fri Jun 14 16:40:16 2013
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Username: /as sysdba
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Starting "SYS"."SYS_EXPORT_TABLESPACE_01": /******** AS SYSDBA directory=expdp dumpfile=exp_tablespace.dmp logfile=exp_tablespace.log tablespaces=test
Estimate in progress using BLOCKS method...
Processing object type TABLE_EXPORT/TABLE/TABLE_DATA
Total estimation using BLOCKS method: 128 KB
Processing object type TABLE_EXPORT/TABLE/TABLE
Processing object type TABLE_EXPORT/TABLE/STATISTICS/TABLE_STATISTICS
. . exported "TEST"."TEST" 5.070 KB 10 rows
Master table "SYS"."SYS_EXPORT_TABLESPACE_01" successfully loaded/unloaded
******************************************************************************
Dump file set for SYS.SYS_EXPORT_TABLESPACE_01 is:
/u01/expd/exp_tablespace.dmp
Job "SYS"."SYS_EXPORT_TABLESPACE_01" successfully completed at 16:40:37
2] copy dumpfile to source database using ftp,hard drive etc....(/u01/expdp).
3] on source database.
[oracle@db11g]$ sqlplus
SQL*Plus: Release 11.2.0.1.0 Production on Fri Jun 14 16:14:12 2013
Copyright (c) 1982, 2009, Oracle. All rights reserved.
Enter user-name: /as sysdba
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
SQL>create directory expdp as '/u01/expdp'
SQL> create tablespace test
datafile '/u01/app/oracle/oradata/db11g/test01.dbf' size 10g;
Tablespace created.
SQL>create user test
identified by test
default tablespace test;
user created
SQL> grant connect , resource to test;
Grant succeeded.
SQL>exit
[oracle@db11g]$impdp directory=EXPDP dumpfile=exp_tablespace.dmp logfile=exp_tablespace.log full=y
Import: Release 11.2.0.1.0 - Production on Fri Jun 14 16:18:26 2013
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Username: /as sysdba
Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
................
..............
[oracle@db11g]$ exit
SQL> conn test/test
SQL> select count(*) from test;
COUNT(*)
----------
10
Move database from one server to other server using logical backup utility.(impdp/expdp)
Move database from one server to other server using logical backup utility.
:- Following are the steps to move database from one to other server.
target database :- ORCL
source database :- DB11G
1] on Target database server.
:-create extra tablespace and users in target database.
SQL>create tablspace test
datafile '/u01/app/oracle/oradata/db11g/test01.dbf' size 10G;
SQL> create tablespace test1
datafiles '/u01/app/oracle/oradata/db11g/test11.dbf' size 10G;
SQL> select name from v$tablespace;
NAME
------------------------------
SYSTEM
SYSAUX
UNDOTBS1
USERS
TEMP
RAVI
TEST
TEST1
FAM
FAM1
10 rows selected.
SQL>create user test
identified by test
default tablespace test;
SQ> grant connect,resource to test;
SQ> create user test1
identfied by test1
default tablespace test1;
SQL> grant connect,resource to test1;
SQL>connect test/test
SQL>create table test(id number);
SQL>begin
for i in 1..10 loop
insert into test values(i);
end loop;
end;
/
SQL> commit;
SQL> connect test1/test1
SQL> create table test1(id number);
SQL>begin
for i in 1..10 loop
insert into test1 values(i);
end loop;
end;
/
SQL>commit;
SQL>!
[oracle@orcl ~]$ mkdir -p /u01/expdp
[oracle@orcl ~]$exit
SQL> create directory expdp as '/u01/expdp';
SQ> exit
[oracle@orcl ~]$ expdp directory=expdp dumpfile=full1.dmp logfilename=full1.log full=y
LRM-00101: unknown parameter name 'logfilename'
[oracle@orcl ~]$ expdp directory=expdp dumpfile=full1.dmp logfile=full1.log full=y
Export: Release 11.2.0.1.0 - Production on Thu Jun 13 16:56:01 2013
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Username: /as sysdba
2]on source database server.
[oracle@db11gl expd]$ mkdir -p /u01/expdp
[oracle@db11g expd]$ sqlplus
connect sys/admin as sysdba
SQL> create directory expdp as '/u02/expdp';
:- transfer dump file target server to source server(using ftp,hard drive etc...) in perticuler directory (/u01/expdp).
SQL> !
[oracle@db11g expd]$impdp directory=expdp dumpfile=full1.dmp logfilename=full1.log full=y ignore=y
Export: Release 11.2.0.1.0 - Production on Thu Jun 13 16:56:01 2013
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Username: /as sysdba
NOTE:- In step 1 i created tablespace and users its not mandatory. i did this because only after you import data from dump file so after that you just check it, both tablespace and users created on source database that means you import database process is successfully completed.
:- Following are the steps to move database from one to other server.
target database :- ORCL
source database :- DB11G
1] on Target database server.
:-create extra tablespace and users in target database.
SQL>create tablspace test
datafile '/u01/app/oracle/oradata/db11g/test01.dbf' size 10G;
SQL> create tablespace test1
datafiles '/u01/app/oracle/oradata/db11g/test11.dbf' size 10G;
SQL> select name from v$tablespace;
NAME
------------------------------
SYSTEM
SYSAUX
UNDOTBS1
USERS
TEMP
RAVI
TEST
TEST1
FAM
FAM1
10 rows selected.
SQL>create user test
identified by test
default tablespace test;
SQ> grant connect,resource to test;
SQ> create user test1
identfied by test1
default tablespace test1;
SQL> grant connect,resource to test1;
SQL>connect test/test
SQL>create table test(id number);
SQL>begin
for i in 1..10 loop
insert into test values(i);
end loop;
end;
/
SQL> commit;
SQL> connect test1/test1
SQL> create table test1(id number);
SQL>begin
for i in 1..10 loop
insert into test1 values(i);
end loop;
end;
/
SQL>commit;
SQL>!
[oracle@orcl ~]$ mkdir -p /u01/expdp
[oracle@orcl ~]$exit
SQL> create directory expdp as '/u01/expdp';
SQ> exit
[oracle@orcl ~]$ expdp directory=expdp dumpfile=full1.dmp logfilename=full1.log full=y
LRM-00101: unknown parameter name 'logfilename'
[oracle@orcl ~]$ expdp directory=expdp dumpfile=full1.dmp logfile=full1.log full=y
Export: Release 11.2.0.1.0 - Production on Thu Jun 13 16:56:01 2013
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Username: /as sysdba
2]on source database server.
[oracle@db11gl expd]$ mkdir -p /u01/expdp
[oracle@db11g expd]$ sqlplus
connect sys/admin as sysdba
SQL> create directory expdp as '/u02/expdp';
:- transfer dump file target server to source server(using ftp,hard drive etc...) in perticuler directory (/u01/expdp).
SQL> !
[oracle@db11g expd]$impdp directory=expdp dumpfile=full1.dmp logfilename=full1.log full=y ignore=y
Export: Release 11.2.0.1.0 - Production on Thu Jun 13 16:56:01 2013
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Username: /as sysdba
NOTE:- In step 1 i created tablespace and users its not mandatory. i did this because only after you import data from dump file so after that you just check it, both tablespace and users created on source database that means you import database process is successfully completed.
Wednesday, 12 June 2013
tablespace point in time recovery using SCN (RMAN)
tablespace point in time recovery using SCN (RMAN).
I got this solution after visit number links regarding rman backup and recovery.I sort all documents and perform this practical on test database and got desired result.
Example:-
SQL> select name from v$tablespace;
NAME
---------------------------------------------------
SYSTEM
SYSAUX
UNDOTBS1
USERS
TEMP
RAVI
TEST
6 rows selected.
SQL> conn test/test
Connected.
SQL> create table test1(id number);
Table created.
SQL> begin
for i in 1..10 loop
insert into test values(i);
end loop;
end;
/
SQL> commit;
Commit complete.
SQL> select count(*) from test;
COUNT(*)
----------
10
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@orcl ~]$ rman
Recovery Manager: Release 11.2.0.1.0 - Production on Wed Jun 12 16:55:01 2013
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
RMAN> connect target
connected to target database: DB11G (DBID=287159184)
RMAN> run
2> {
3> ALLOCATE CHANNEL ch1 TYPE
4> DISK FORMAT '/u01/backup/DB11G/%d_DB_%u_%s_%p';
5> BACKUP DATABASE plus ARCHIVELOG;
6> backup current controlfile;
7> RELEASE CHANNEL ch1;
8> }
9> EXIT;
using target database control file instead of recovery catalog
allocated channel: ch1
channel ch1: SID=1 device type=DISK
Starting backup at 12-JUN-13
current log archived
channel ch1: starting archived log backup set
channel ch1: specifying archived log(s) in backup set
input archived log thread=1 sequence=3 RECID=1 STAMP=817500225
input archived log thread=1 sequence=4 RECID=2 STAMP=817500225
input archived log thread=1 sequence=5 RECID=3 STAMP=817500227
input archived log thread=1 sequence=6 RECID=4 STAMP=817500259
input archived log thread=1 sequence=7 RECID=5 STAMP=817500260
input archived log thread=1 sequence=8 RECID=6 STAMP=817500263
input archived log thread=1 sequence=9 RECID=7 STAMP=817500267
input archived log thread=1 sequence=10 RECID=8 STAMP=817500282
input archived log thread=1 sequence=11 RECID=9 STAMP=817500283
input archived log thread=1 sequence=12 RECID=10 STAMP=817500284
input archived log thread=1 sequence=13 RECID=11 STAMP=817500284
input archived log thread=1 sequence=14 RECID=12 STAMP=817510623
channel ch1: starting piece 1 at 12-JUN-13
channel ch1: finished piece 1 at 12-JUN-13
piece handle=/u01/backup/DB11G/DB11G_DB_1coc118o_44_1 tag=TAG20130612T165551 comment=NONE
channel ch1: backup set complete, elapsed time: 00:00:04
channel ch1: starting archived log backup set
channel ch1: specifying archived log(s) in backup set
input archived log thread=1 sequence=1 RECID=19 STAMP=817749472
input archived log thread=1 sequence=2 RECID=20 STAMP=817749579
input archived log thread=1 sequence=3 RECID=21 STAMP=817759858
input archived log thread=1 sequence=4 RECID=22 STAMP=817774302
input archived log thread=1 sequence=5 RECID=23 STAMP=817842613
input archived log thread=1 sequence=6 RECID=24 STAMP=817851202
input archived log thread=1 sequence=7 RECID=25 STAMP=817851369
input archived log thread=1 sequence=8 RECID=26 STAMP=817851598
input archived log thread=1 sequence=9 RECID=27 STAMP=817851600
input archived log thread=1 sequence=10 RECID=28 STAMP=817851605
input archived log thread=1 sequence=11 RECID=29 STAMP=817851624
input archived log thread=1 sequence=12 RECID=30 STAMP=817855047
input archived log thread=1 sequence=13 RECID=31 STAMP=817855512
input archived log thread=1 sequence=14 RECID=32 STAMP=817855642
input archived log thread=1 sequence=15 RECID=33 STAMP=817911008
channel ch1: starting piece 1 at 12-JUN-13
channel ch1: finished piece 1 at 12-JUN-13
piece handle=/u01/backup/DB11G/DB11G_DB_1doc118s_45_1 tag=TAG20130612T165551 comment=NONE
channel ch1: backup set complete, elapsed time: 00:00:15
channel ch1: starting archived log backup set
channel ch1: specifying archived log(s) in backup set
input archived log thread=1 sequence=21 RECID=18 STAMP=817749346
channel ch1: starting piece 1 at 12-JUN-13
channel ch1: finished piece 1 at 12-JUN-13
piece handle=/u01/backup/DB11G/DB11G_DB_1eoc119b_46_1 tag=TAG20130612T165551 comment=NONE
channel ch1: backup set complete, elapsed time: 00:00:04
channel ch1: starting archived log backup set
channel ch1: specifying archived log(s) in backup set
input archived log thread=1 sequence=16 RECID=34 STAMP=817914817
input archived log thread=1 sequence=17 RECID=35 STAMP=817914938
input archived log thread=1 sequence=18 RECID=36 STAMP=817917655
input archived log thread=1 sequence=19 RECID=37 STAMP=817917656
input archived log thread=1 sequence=20 RECID=38 STAMP=817917661
input archived log thread=1 sequence=21 RECID=39 STAMP=817918877
input archived log thread=1 sequence=22 RECID=40 STAMP=817919815
channel ch1: starting piece 1 at 12-JUN-13
channel ch1: finished piece 1 at 12-JUN-13
piece handle=/u01/backup/DB11G/DB11G_DB_1foc119f_47_1 tag=TAG20130612T165551 comment=NONE
channel ch1: backup set complete, elapsed time: 00:00:01
channel ch1: starting archived log backup set
channel ch1: specifying archived log(s) in backup set
input archived log thread=1 sequence=22 RECID=16 STAMP=817749341
channel ch1: starting piece 1 at 12-JUN-13
channel ch1: finished piece 1 at 12-JUN-13
piece handle=/u01/backup/DB11G/DB11G_DB_1goc119g_48_1 tag=TAG20130612T165551 comment=NONE
channel ch1: backup set complete, elapsed time: 00:00:04
channel ch1: starting archived log backup set
channel ch1: specifying archived log(s) in backup set
input archived log thread=1 sequence=23 RECID=41 STAMP=817920792
input archived log thread=1 sequence=24 RECID=42 STAMP=817920917
input archived log thread=1 sequence=25 RECID=43 STAMP=817922548
channel ch1: starting piece 1 at 12-JUN-13
channel ch1: finished piece 1 at 12-JUN-13
piece handle=/u01/backup/DB11G/DB11G_DB_1hoc119k_49_1 tag=TAG20130612T165551 comment=NONE
channel ch1: backup set complete, elapsed time: 00:00:01
channel ch1: starting archived log backup set
channel ch1: specifying archived log(s) in backup set
input archived log thread=1 sequence=23 RECID=17 STAMP=817749343
channel ch1: starting piece 1 at 12-JUN-13
channel ch1: finished piece 1 at 12-JUN-13
piece handle=/u01/backup/DB11G/DB11G_DB_1ioc119l_50_1 tag=TAG20130612T165551 comment=NONE
channel ch1: backup set complete, elapsed time: 00:00:04
channel ch1: starting archived log backup set
channel ch1: specifying archived log(s) in backup set
input archived log thread=1 sequence=26 RECID=44 STAMP=817923351
channel ch1: starting piece 1 at 12-JUN-13
channel ch1: finished piece 1 at 12-JUN-13
piece handle=/u01/backup/DB11G/DB11G_DB_1joc119p_51_1 tag=TAG20130612T165551 comment=NONE
channel ch1: backup set complete, elapsed time: 00:00:01
Finished backup at 12-JUN-13
Starting backup at 12-JUN-13
channel ch1: starting full datafile backup set
channel ch1: specifying datafile(s) in backup set
input datafile file number=00001 name=/u01/app/oracle/oradata/db11g/system01.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/db11g/sysaux01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/db11g/undotbs01.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/db11g/ravi01.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/db11g/users01.dbf
input datafile file number=00006 name=/u01/app/oracle/oradata/db11g/test01.dbf
channel ch1: starting piece 1 at 12-JUN-13
channel ch1: finished piece 1 at 12-JUN-13
piece handle=/u01/backup/DB11G/DB11G_DB_1koc119r_52_1 tag=TAG20130612T165626 comment=NONE
channel ch1: backup set complete, elapsed time: 00:01:16
channel ch1: starting full datafile backup set
channel ch1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ch1: starting piece 1 at 12-JUN-13
channel ch1: finished piece 1 at 12-JUN-13
piece handle=/u01/backup/DB11G/DB11G_DB_1loc11c7_53_1 tag=TAG20130612T165626 comment=NONE
channel ch1: backup set complete, elapsed time: 00:00:01
Finished backup at 12-JUN-13
Starting backup at 12-JUN-13
current log archived
channel ch1: starting archived log backup set
channel ch1: specifying archived log(s) in backup set
input archived log thread=1 sequence=27 RECID=45 STAMP=817923467
channel ch1: starting piece 1 at 12-JUN-13
channel ch1: finished piece 1 at 12-JUN-13
piece handle=/u01/backup/DB11G/DB11G_DB_1moc11cc_54_1 tag=TAG20130612T165748 comment=NONE
channel ch1: backup set complete, elapsed time: 00:00:01
Finished backup at 12-JUN-13
Starting backup at 12-JUN-13
channel ch1: starting full datafile backup set
channel ch1: specifying datafile(s) in backup set
including current control file in backup set
channel ch1: starting piece 1 at 12-JUN-13
channel ch1: finished piece 1 at 12-JUN-13
piece handle=/u01/backup/DB11G/DB11G_DB_1noc11cd_55_1 tag=TAG20130612T165749 comment=NONE
channel ch1: backup set complete, elapsed time: 00:00:01
Finished backup at 12-JUN-13
released channel: ch1
Recovery Manager complete.
[oracle@orcl u01]$ sqlplus
SQL> conn sys/admin as sysdba
SQL> alter system switch logfile;
SQL> alter system switch logfile;
System altered.
SQL> /
System altered.
SQL> /
System altered.
SQL>
SQL> create tablespace test_1 datafile '/u01/app/oracle/oradata/db11g/test_101.dbf' size 2m;
SQL> select name from v$tablespace;
NAME
------------------------------
SYSTEM
SYSAUX
UNDOTBS1
USERS
TEMP
RAVI
TEST
TEST_1
8 rows selected.
SQL> create user test1
2 identified by test1
3 default tablespace test_1;
User created.
SQL> grant connect, resource to test;
Grant succeeded.
SQL> create table test_1(id number);
Table created.
SQL> begin
for i in 1..10 loop
insert into test_1 values(i);
end loop;
end;
/ 2 3 4 5 6
PL/SQL procedure successfully completed.
SQL> commit;
Commit complete.
SQL> select count(*) from test_1;
COUNT(*)
----------
10
SQL> set time on;
17:03:43 SQL> connect test/test
Connected.
17:04:09 SQL> drop table test;
Table dropped.
17:04:15 SQL> conn sys/admin as sysdba
Connected.
17:04:39 SQL> col name format a51;
17:06:15 SQL> col status for a10;
17:06:26 SQL> select name,status from v$datafile;
NAME STATUS
--------------------------------------------------- ----------
/u01/app/oracle/oradata/db11g/system01.dbf SYSTEM
/u01/app/oracle/oradata/db11g/sysaux01.dbf ONLINE
/u01/app/oracle/oradata/db11g/undotbs01.dbf ONLINE
/u01/app/oracle/oradata/db11g/users01.dbf ONLINE
/u01/app/oracle/oradata/db11g/ravi01.dbf ONLINE
/u01/app/oracle/oradata/db11g/test01.dbf ONLINE
/u01/app/oracle/oradata/db11g/test_101.dbf ONLINE
17:07:15 SQL> alter tablespace test offline immediate;
Tablespace altered.
17:07:30 SQL> select name,status from v$datafile;
NAME STATUS
--------------------------------------------------- ----------
/u01/app/oracle/oradata/db11g/system01.dbf SYSTEM
/u01/app/oracle/oradata/db11g/sysaux01.dbf ONLINE
/u01/app/oracle/oradata/db11g/undotbs01.dbf ONLINE
/u01/app/oracle/oradata/db11g/users01.dbf ONLINE
/u01/app/oracle/oradata/db11g/ravi01.dbf ONLINE
/u01/app/oracle/oradata/db11g/test01.dbf RECOVER
/u01/app/oracle/oradata/db11g/test_101.dbf ONLINE
7 rows selected.
17:08:16 SQL> connect test1/test1
Connected.
17:08:31 SQL> create table test2(id number);
Table created.
17:09:38 SQL> begin
for i in 1..10 loop
insert into test2 values(i);
end loop;
end;
/
PL/SQL procedure successfully completed.
17:09:48 SQL> commit;
Commit complete.
17:09:51 SQL> select count(*) from test2;
COUNT(*)
----------
10
[oracle@orcl u01]$ rman
Recovery Manager: Release 11.2.0.1.0 - Production on Wed Jun 12 15:35:30 2013
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
RMAN> connect target
connected to target database: DB11G (DBID=287159184)
RMAN> list backup;
BS Key Size Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
42 28.78M DISK 00:00:02 12-JUN-13
BP Key: 42 Status: AVAILABLE Compressed: NO Tag: TAG20130612T165551
Piece Name: /u01/backup/DB11G/DB11G_DB_1coc118o_44_1
List of Archived Logs in backup set 42
Thrd Seq Low SCN Low Time Next SCN Next Time
---- ------- ---------- --------- ---------- ---------
1 3 785707 07-JUN-13 786173 07-JUN-13
1 4 786173 07-JUN-13 786176 07-JUN-13
1 5 786176 07-JUN-13 810540 07-JUN-13
1 6 810540 07-JUN-13 810667 07-JUN-13
1 7 810667 07-JUN-13 810670 07-JUN-13
1 8 810670 07-JUN-13 810674 07-JUN-13
1 9 810674 07-JUN-13 810677 07-JUN-13
1 10 810677 07-JUN-13 810682 07-JUN-13
1 11 810682 07-JUN-13 810685 07-JUN-13
1 12 810685 07-JUN-13 810688 07-JUN-13
1 13 810688 07-JUN-13 810691 07-JUN-13
1 14 810691 07-JUN-13 821070 07-JUN-13
BS Key Size Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
43 179.38M DISK 00:00:14 12-JUN-13
BP Key: 43 Status: AVAILABLE Compressed: NO Tag: TAG20130612T165551
Piece Name: /u01/backup/DB11G/DB11G_DB_1doc118s_45_1
List of Archived Logs in backup set 43
Thrd Seq Low SCN Low Time Next SCN Next Time
---- ------- ---------- --------- ---------- ---------
1 1 821082 10-JUN-13 821493 10-JUN-13
1 2 821493 10-JUN-13 821525 10-JUN-13
1 3 821525 10-JUN-13 827239 10-JUN-13
1 4 827239 10-JUN-13 842360 10-JUN-13
1 5 842360 10-JUN-13 871981 11-JUN-13
1 6 871981 11-JUN-13 876028 11-JUN-13
1 7 876028 11-JUN-13 876124 11-JUN-13
1 8 876124 11-JUN-13 876307 11-JUN-13
1 9 876307 11-JUN-13 876311 11-JUN-13
1 10 876311 11-JUN-13 876315 11-JUN-13
1 11 876315 11-JUN-13 876321 11-JUN-13
1 12 876321 11-JUN-13 878372 11-JUN-13
1 13 878372 11-JUN-13 882722 11-JUN-13
1 14 882722 11-JUN-13 882772 11-JUN-13
1 15 882772 11-JUN-13 909083 12-JUN-13
BS Key Size Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
44 40.57M DISK 00:00:02 12-JUN-13
BP Key: 44 Status: AVAILABLE Compressed: NO Tag: TAG20130612T165551
Piece Name: /u01/backup/DB11G/DB11G_DB_1eoc119b_46_1
List of Archived Logs in backup set 44
Thrd Seq Low SCN Low Time Next SCN Next Time
---- ------- ---------- --------- ---------- ---------
1 21 902545 09-JUN-13 921147 09-JUN-13
BS Key Size Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
45 5.68M DISK 00:00:01 12-JUN-13
BP Key: 45 Status: AVAILABLE Compressed: NO Tag: TAG20130612T165551
Piece Name: /u01/backup/DB11G/DB11G_DB_1foc119f_47_1
List of Archived Logs in backup set 45
Thrd Seq Low SCN Low Time Next SCN Next Time
---- ------- ---------- --------- ---------- ---------
1 16 909083 12-JUN-13 911013 12-JUN-13
1 17 911013 12-JUN-13 911052 12-JUN-13
1 18 911052 12-JUN-13 912283 12-JUN-13
1 19 912283 12-JUN-13 912286 12-JUN-13
1 20 912286 12-JUN-13 912292 12-JUN-13
1 21 912292 12-JUN-13 913442 12-JUN-13
1 22 913442 12-JUN-13 933915 12-JUN-13
BS Key Size Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
46 38.70M DISK 00:00:02 12-JUN-13
BP Key: 46 Status: AVAILABLE Compressed: NO Tag: TAG20130612T165551
Piece Name: /u01/backup/DB11G/DB11G_DB_1goc119g_48_1
List of Archived Logs in backup set 46
Thrd Seq Low SCN Low Time Next SCN Next Time
---- ------- ---------- --------- ---------- ---------
1 22 921147 09-JUN-13 935457 10-JUN-13
BS Key Size Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
47 2.72M DISK 00:00:00 12-JUN-13
BP Key: 47 Status: AVAILABLE Compressed: NO Tag: TAG20130612T165551
Piece Name: /u01/backup/DB11G/DB11G_DB_1hoc119k_49_1
List of Archived Logs in backup set 47
Thrd Seq Low SCN Low Time Next SCN Next Time
---- ------- ---------- --------- ---------- ---------
1 23 933915 12-JUN-13 934937 12-JUN-13
1 24 934937 12-JUN-13 934975 12-JUN-13
1 25 934975 12-JUN-13 935842 12-JUN-13
BS Key Size Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
48 32.13M DISK 00:00:02 12-JUN-13
BP Key: 48 Status: AVAILABLE Compressed: NO Tag: TAG20130612T165551
Piece Name: /u01/backup/DB11G/DB11G_DB_1ioc119l_50_1
List of Archived Logs in backup set 48
Thrd Seq Low SCN Low Time Next SCN Next Time
---- ------- ---------- --------- ---------- ---------
1 23 935457 10-JUN-13 960820 10-JUN-13
BS Key Size Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
49 733.50K DISK 00:00:00 12-JUN-13
BP Key: 49 Status: AVAILABLE Compressed: NO Tag: TAG20130612T165551
Piece Name: /u01/backup/DB11G/DB11G_DB_1joc119p_51_1
List of Archived Logs in backup set 49
Thrd Seq Low SCN Low Time Next SCN Next Time
---- ------- ---------- --------- ---------- ---------
1 26 935842 12-JUN-13 936718 12-JUN-13
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
50 Full 959.59M DISK 00:01:08 12-JUN-13
BP Key: 50 Status: AVAILABLE Compressed: NO Tag: TAG20130612T165626
Piece Name: /u01/backup/DB11G/DB11G_DB_1koc119r_52_1
List of Datafiles in backup set 50
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
1 Full 936730 12-JUN-13 /u01/app/oracle/oradata/db11g/system01.dbf
2 Full 936730 12-JUN-13 /u01/app/oracle/oradata/db11g/sysaux01.dbf
3 Full 936730 12-JUN-13 /u01/app/oracle/oradata/db11g/undotbs01.dbf
4 Full 936730 12-JUN-13 /u01/app/oracle/oradata/db11g/users01.dbf
5 Full 936730 12-JUN-13 /u01/app/oracle/oradata/db11g/ravi01.dbf
6 Full 936730 12-JUN-13 /u01/app/oracle/oradata/db11g/test01.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
51 Full 9.39M DISK 00:00:04 12-JUN-13
BP Key: 51 Status: AVAILABLE Compressed: NO Tag: TAG20130612T165626
Piece Name: /u01/backup/DB11G/DB11G_DB_1loc11c7_53_1
SPFILE Included: Modification time: 12-JUN-13
SPFILE db_unique_name: DB11G
Control File Included: Ckp SCN: 936750 Ckp time: 12-JUN-13
BS Key Size Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
52 14.00K DISK 00:00:00 12-JUN-13
BP Key: 52 Status: AVAILABLE Compressed: NO Tag: TAG20130612T165748
Piece Name: /u01/backup/DB11G/DB11G_DB_1moc11cc_54_1
List of Archived Logs in backup set 52
Thrd Seq Low SCN Low Time Next SCN Next Time
---- ------- ---------- --------- ---------- ---------
1 27 936718 12-JUN-13 936756 12-JUN-13
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
53 Full 9.36M DISK 00:00:02 12-JUN-13
BP Key: 53 Status: AVAILABLE Compressed: NO Tag: TAG20130612T165749
Piece Name: /u01/backup/DB11G/DB11G_DB_1noc11cd_55_1
Control File Included: Ckp SCN: 936765 Ckp time: 12-JUN-13
RMAN> run
{
recover tablespace 'TEST'
until scn 936765
AUXILIARY DESTINATION '/u01/auxilary';
}
Starting recover at 12-JUN-13
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=43 device type=DISK
RMAN-05026: WARNING: presuming following set of tablespaces applies to specified point-in-time
List of tablespaces expected to have UNDO segments
Tablespace SYSTEM
Tablespace UNDOTBS1
Creating automatic instance, with SID='ltix'
initialization parameters used for automatic instance:
db_name=DB11G
db_unique_name=ltix_tspitr_DB11G
compatible=11.2.0.0.0
db_block_size=8192
db_files=200
sga_target=280M
processes=50
db_create_file_dest=/u01/auxilary
log_archive_dest_1='location=/u01/auxilary'
#No auxiliary parameter file used
starting up automatic instance DB11G
Oracle instance started
Total System Global Area 292933632 bytes
Fixed Size 1336092 bytes
Variable Size 100666596 bytes
Database Buffers 184549376 bytes
Redo Buffers 6381568 bytes
Automatic instance created
Running TRANSPORT_SET_CHECK on recovery set tablespaces
TRANSPORT_SET_CHECK completed successfully
contents of Memory Script:
{
# set requested point in time
set until scn 936765;
# restore the controlfile
restore clone controlfile;
# mount the controlfile
sql clone 'alter database mount clone database';
# archive current online log
sql 'alter system archive log current';
# avoid unnecessary autobackups for structural changes during TSPITR
sql 'begin dbms_backup_restore.AutoBackupFlag(FALSE); end;';
}
executing Memory Script
executing command: SET until clause
Starting restore at 12-JUN-13
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=19 device type=DISK
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: reading from backup piece /u01/backup/DB11G/DB11G_DB_1noc11cd_55_1
channel ORA_AUX_DISK_1: piece handle=/u01/backup/DB11G/DB11G_DB_1noc11cd_55_1 tag=TAG20130612T165749
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/u01/auxilary/DB11G/controlfile/o1_mf_8vjr943b_.ctl
Finished restore at 12-JUN-13
sql statement: alter database mount clone database
sql statement: alter system archive log current
sql statement: begin dbms_backup_restore.AutoBackupFlag(FALSE); end;
contents of Memory Script:
{
# set requested point in time
set until scn 936765;
# set destinations for recovery set and auxiliary set datafiles
set newname for clone datafile 1 to new;
set newname for clone datafile 3 to new;
set newname for clone datafile 2 to new;
set newname for clone tempfile 1 to new;
set newname for datafile 6 to
"/u01/app/oracle/oradata/db11g/test01.dbf";
# switch all tempfiles
switch clone tempfile all;
# restore the tablespaces in the recovery set and the auxiliary set
restore clone datafile 1, 3, 2, 6;
switch clone datafile all;
}
executing Memory Script
executing command: SET until clause
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
renamed tempfile 1 to /u01/auxilary/DB11G/datafile/o1_mf_temp_%u_.tmp in control file
Starting restore at 12-JUN-13
using channel ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00001 to /u01/auxilary/DB11G/datafile/o1_mf_system_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /u01/auxilary/DB11G/datafile/o1_mf_undotbs1_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00002 to /u01/auxilary/DB11G/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00006 to /u01/app/oracle/oradata/db11g/test01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u01/backup/DB11G/DB11G_DB_1koc119r_52_1
channel ORA_AUX_DISK_1: piece handle=/u01/backup/DB11G/DB11G_DB_1koc119r_52_1 tag=TAG20130612T165626
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:45
Finished restore at 12-JUN-13
datafile 1 switched to datafile copy
input datafile copy RECID=4 STAMP=817925043 file name=/u01/auxilary/DB11G/datafile/o1_mf_system_8vjr9ft2_.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=5 STAMP=817925043 file name=/u01/auxilary/DB11G/datafile/o1_mf_undotbs1_8vjr9ftv_.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=6 STAMP=817925043 file name=/u01/auxilary/DB11G/datafile/o1_mf_sysaux_8vjr9ftr_.dbf
contents of Memory Script:
{
# set requested point in time
set until scn 936765;
# online the datafiles restored or switched
sql clone "alter database datafile 1 online";
sql clone "alter database datafile 3 online";
sql clone "alter database datafile 2 online";
sql clone "alter database datafile 6 online";
# recover and open resetlogs
recover clone database tablespace "TEST", "SYSTEM", "UNDOTBS1", "SYSAUX" delete archivelog;
alter clone database open resetlogs;
}
executing Memory Script
executing command: SET until clause
sql statement: alter database datafile 1 online
sql statement: alter database datafile 3 online
sql statement: alter database datafile 2 online
sql statement: alter database datafile 6 online
Starting recover at 12-JUN-13
using channel ORA_AUX_DISK_1
starting media recovery
archived log for thread 1 with sequence 27 is already on disk as file /u01/archivelog/arch_1_27_817749339.arc
archived log for thread 1 with sequence 28 is already on disk as file /u01/archivelog/arch_1_28_817749339.arc
archived log file name=/u01/archivelog/arch_1_27_817749339.arc thread=1 sequence=27
archived log file name=/u01/archivelog/arch_1_28_817749339.arc thread=1 sequence=28
media recovery complete, elapsed time: 00:00:01
Finished recover at 12-JUN-13
database opened
contents of Memory Script:
{
# make read only the tablespace that will be exported
sql clone 'alter tablespace "TEST" read only';
# create directory for datapump import
sql "create or replace directory TSPITR_DIROBJ_DPDIR as ''
/u01/auxilary''";
# create directory for datapump export
sql clone "create or replace directory TSPITR_DIROBJ_DPDIR as ''
/u01/auxilary''";
}
executing Memory Script
sql statement: alter tablespace "TEST" read only
sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/u01/auxilary''
sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/u01/auxilary''
Performing export of metadata...
EXPDP> Starting "SYS"."TSPITR_EXP_ltix":
EXPDP> Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
EXPDP> Processing object type TRANSPORTABLE_EXPORT/TABLE
EXPDP> Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
EXPDP> Master table "SYS"."TSPITR_EXP_ltix" successfully loaded/unloaded
EXPDP> ******************************************************************************
EXPDP> Dump file set for SYS.TSPITR_EXP_ltix is:
EXPDP> /u01/auxilary/tspitr_ltix_72884.dmp
EXPDP> ******************************************************************************
EXPDP> Datafiles required for transportable tablespace TEST:
EXPDP> /u01/app/oracle/oradata/db11g/test01.dbf
EXPDP> Job "SYS"."TSPITR_EXP_ltix" successfully completed at 17:26:08
Export completed
contents of Memory Script:
{
# shutdown clone before import
shutdown clone immediate
# drop target tablespaces before importing them back
sql 'drop tablespace "TEST" including contents keep datafiles';
}
executing Memory Script
database closed
database dismounted
Oracle instance shut down
sql statement: drop tablespace "TEST" including contents keep datafiles
Performing import of metadata...
IMPDP> Master table "SYS"."TSPITR_IMP_ltix" successfully loaded/unloaded
IMPDP> Starting "SYS"."TSPITR_IMP_ltix":
IMPDP> Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
IMPDP> Processing object type TRANSPORTABLE_EXPORT/TABLE
IMPDP> Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
IMPDP> Job "SYS"."TSPITR_IMP_ltix" successfully completed at 17:27:15
Import completed
contents of Memory Script:
{
# make read write and offline the imported tablespaces
sql 'alter tablespace "TEST" read write';
sql 'alter tablespace "TEST" offline';
# enable autobackups after TSPITR is finished
sql 'begin dbms_backup_restore.AutoBackupFlag(TRUE); end;';
}
executing Memory Script
sql statement: alter tablespace "TEST" read write
sql statement: alter tablespace "TEST" offline
sql statement: begin dbms_backup_restore.AutoBackupFlag(TRUE); end;
Removing automatic instance
Automatic instance removed
auxiliary instance file /u01/auxilary/DB11G/datafile/o1_mf_temp_8vjrc9z4_.tmp deleted
auxiliary instance file /u01/auxilary/DB11G/onlinelog/o1_mf_3_8vjrc34l_.log deleted
auxiliary instance file /u01/auxilary/DB11G/onlinelog/o1_mf_2_8vjrc1vp_.log deleted
auxiliary instance file /u01/auxilary/DB11G/onlinelog/o1_mf_1_8vjrc0gv_.log deleted
auxiliary instance file /u01/auxilary/DB11G/datafile/o1_mf_sysaux_8vjr9ftr_.dbf deleted
auxiliary instance file /u01/auxilary/DB11G/datafile/o1_mf_undotbs1_8vjr9ftv_.dbf deleted
auxiliary instance file /u01/auxilary/DB11G/datafile/o1_mf_system_8vjr9ft2_.dbf deleted
auxiliary instance file /u01/auxilary/DB11G/controlfile/o1_mf_8vjr943b_.ctl deleted
Finished recover at 12-JUN-13
RMAN> exit
Recovery Manager complete.
[oracle@orcl u01]$sqlplus
SQL> conn test/test
Connected.
SQL> select count(*) from test;
select count(*) from test
*
ERROR at line 1:
ORA-00376: file 6 cannot be read at this time
ORA-01110: data file 6: '/u01/app/oracle/oradata/db11g/test01.dbf'
SQL> conn /as sysdba
Connected.
SQL> alter tablespace test online;
Tablespace altered.
SQL> conn test/test;
Connected.
SQL> select count(*) from test;
COUNT(*)
----------
10
I got this solution after visit number links regarding rman backup and recovery.I sort all documents and perform this practical on test database and got desired result.
Example:-
SQL> select name from v$tablespace;
NAME
---------------------------------------------------
SYSTEM
SYSAUX
UNDOTBS1
USERS
TEMP
RAVI
TEST
6 rows selected.
SQL> conn test/test
Connected.
SQL> create table test1(id number);
Table created.
SQL> begin
for i in 1..10 loop
insert into test values(i);
end loop;
end;
/
SQL> commit;
Commit complete.
SQL> select count(*) from test;
COUNT(*)
----------
10
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[oracle@orcl ~]$ rman
Recovery Manager: Release 11.2.0.1.0 - Production on Wed Jun 12 16:55:01 2013
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
RMAN> connect target
connected to target database: DB11G (DBID=287159184)
RMAN> run
2> {
3> ALLOCATE CHANNEL ch1 TYPE
4> DISK FORMAT '/u01/backup/DB11G/%d_DB_%u_%s_%p';
5> BACKUP DATABASE plus ARCHIVELOG;
6> backup current controlfile;
7> RELEASE CHANNEL ch1;
8> }
9> EXIT;
using target database control file instead of recovery catalog
allocated channel: ch1
channel ch1: SID=1 device type=DISK
Starting backup at 12-JUN-13
current log archived
channel ch1: starting archived log backup set
channel ch1: specifying archived log(s) in backup set
input archived log thread=1 sequence=3 RECID=1 STAMP=817500225
input archived log thread=1 sequence=4 RECID=2 STAMP=817500225
input archived log thread=1 sequence=5 RECID=3 STAMP=817500227
input archived log thread=1 sequence=6 RECID=4 STAMP=817500259
input archived log thread=1 sequence=7 RECID=5 STAMP=817500260
input archived log thread=1 sequence=8 RECID=6 STAMP=817500263
input archived log thread=1 sequence=9 RECID=7 STAMP=817500267
input archived log thread=1 sequence=10 RECID=8 STAMP=817500282
input archived log thread=1 sequence=11 RECID=9 STAMP=817500283
input archived log thread=1 sequence=12 RECID=10 STAMP=817500284
input archived log thread=1 sequence=13 RECID=11 STAMP=817500284
input archived log thread=1 sequence=14 RECID=12 STAMP=817510623
channel ch1: starting piece 1 at 12-JUN-13
channel ch1: finished piece 1 at 12-JUN-13
piece handle=/u01/backup/DB11G/DB11G_DB_1coc118o_44_1 tag=TAG20130612T165551 comment=NONE
channel ch1: backup set complete, elapsed time: 00:00:04
channel ch1: starting archived log backup set
channel ch1: specifying archived log(s) in backup set
input archived log thread=1 sequence=1 RECID=19 STAMP=817749472
input archived log thread=1 sequence=2 RECID=20 STAMP=817749579
input archived log thread=1 sequence=3 RECID=21 STAMP=817759858
input archived log thread=1 sequence=4 RECID=22 STAMP=817774302
input archived log thread=1 sequence=5 RECID=23 STAMP=817842613
input archived log thread=1 sequence=6 RECID=24 STAMP=817851202
input archived log thread=1 sequence=7 RECID=25 STAMP=817851369
input archived log thread=1 sequence=8 RECID=26 STAMP=817851598
input archived log thread=1 sequence=9 RECID=27 STAMP=817851600
input archived log thread=1 sequence=10 RECID=28 STAMP=817851605
input archived log thread=1 sequence=11 RECID=29 STAMP=817851624
input archived log thread=1 sequence=12 RECID=30 STAMP=817855047
input archived log thread=1 sequence=13 RECID=31 STAMP=817855512
input archived log thread=1 sequence=14 RECID=32 STAMP=817855642
input archived log thread=1 sequence=15 RECID=33 STAMP=817911008
channel ch1: starting piece 1 at 12-JUN-13
channel ch1: finished piece 1 at 12-JUN-13
piece handle=/u01/backup/DB11G/DB11G_DB_1doc118s_45_1 tag=TAG20130612T165551 comment=NONE
channel ch1: backup set complete, elapsed time: 00:00:15
channel ch1: starting archived log backup set
channel ch1: specifying archived log(s) in backup set
input archived log thread=1 sequence=21 RECID=18 STAMP=817749346
channel ch1: starting piece 1 at 12-JUN-13
channel ch1: finished piece 1 at 12-JUN-13
piece handle=/u01/backup/DB11G/DB11G_DB_1eoc119b_46_1 tag=TAG20130612T165551 comment=NONE
channel ch1: backup set complete, elapsed time: 00:00:04
channel ch1: starting archived log backup set
channel ch1: specifying archived log(s) in backup set
input archived log thread=1 sequence=16 RECID=34 STAMP=817914817
input archived log thread=1 sequence=17 RECID=35 STAMP=817914938
input archived log thread=1 sequence=18 RECID=36 STAMP=817917655
input archived log thread=1 sequence=19 RECID=37 STAMP=817917656
input archived log thread=1 sequence=20 RECID=38 STAMP=817917661
input archived log thread=1 sequence=21 RECID=39 STAMP=817918877
input archived log thread=1 sequence=22 RECID=40 STAMP=817919815
channel ch1: starting piece 1 at 12-JUN-13
channel ch1: finished piece 1 at 12-JUN-13
piece handle=/u01/backup/DB11G/DB11G_DB_1foc119f_47_1 tag=TAG20130612T165551 comment=NONE
channel ch1: backup set complete, elapsed time: 00:00:01
channel ch1: starting archived log backup set
channel ch1: specifying archived log(s) in backup set
input archived log thread=1 sequence=22 RECID=16 STAMP=817749341
channel ch1: starting piece 1 at 12-JUN-13
channel ch1: finished piece 1 at 12-JUN-13
piece handle=/u01/backup/DB11G/DB11G_DB_1goc119g_48_1 tag=TAG20130612T165551 comment=NONE
channel ch1: backup set complete, elapsed time: 00:00:04
channel ch1: starting archived log backup set
channel ch1: specifying archived log(s) in backup set
input archived log thread=1 sequence=23 RECID=41 STAMP=817920792
input archived log thread=1 sequence=24 RECID=42 STAMP=817920917
input archived log thread=1 sequence=25 RECID=43 STAMP=817922548
channel ch1: starting piece 1 at 12-JUN-13
channel ch1: finished piece 1 at 12-JUN-13
piece handle=/u01/backup/DB11G/DB11G_DB_1hoc119k_49_1 tag=TAG20130612T165551 comment=NONE
channel ch1: backup set complete, elapsed time: 00:00:01
channel ch1: starting archived log backup set
channel ch1: specifying archived log(s) in backup set
input archived log thread=1 sequence=23 RECID=17 STAMP=817749343
channel ch1: starting piece 1 at 12-JUN-13
channel ch1: finished piece 1 at 12-JUN-13
piece handle=/u01/backup/DB11G/DB11G_DB_1ioc119l_50_1 tag=TAG20130612T165551 comment=NONE
channel ch1: backup set complete, elapsed time: 00:00:04
channel ch1: starting archived log backup set
channel ch1: specifying archived log(s) in backup set
input archived log thread=1 sequence=26 RECID=44 STAMP=817923351
channel ch1: starting piece 1 at 12-JUN-13
channel ch1: finished piece 1 at 12-JUN-13
piece handle=/u01/backup/DB11G/DB11G_DB_1joc119p_51_1 tag=TAG20130612T165551 comment=NONE
channel ch1: backup set complete, elapsed time: 00:00:01
Finished backup at 12-JUN-13
Starting backup at 12-JUN-13
channel ch1: starting full datafile backup set
channel ch1: specifying datafile(s) in backup set
input datafile file number=00001 name=/u01/app/oracle/oradata/db11g/system01.dbf
input datafile file number=00002 name=/u01/app/oracle/oradata/db11g/sysaux01.dbf
input datafile file number=00003 name=/u01/app/oracle/oradata/db11g/undotbs01.dbf
input datafile file number=00005 name=/u01/app/oracle/oradata/db11g/ravi01.dbf
input datafile file number=00004 name=/u01/app/oracle/oradata/db11g/users01.dbf
input datafile file number=00006 name=/u01/app/oracle/oradata/db11g/test01.dbf
channel ch1: starting piece 1 at 12-JUN-13
channel ch1: finished piece 1 at 12-JUN-13
piece handle=/u01/backup/DB11G/DB11G_DB_1koc119r_52_1 tag=TAG20130612T165626 comment=NONE
channel ch1: backup set complete, elapsed time: 00:01:16
channel ch1: starting full datafile backup set
channel ch1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ch1: starting piece 1 at 12-JUN-13
channel ch1: finished piece 1 at 12-JUN-13
piece handle=/u01/backup/DB11G/DB11G_DB_1loc11c7_53_1 tag=TAG20130612T165626 comment=NONE
channel ch1: backup set complete, elapsed time: 00:00:01
Finished backup at 12-JUN-13
Starting backup at 12-JUN-13
current log archived
channel ch1: starting archived log backup set
channel ch1: specifying archived log(s) in backup set
input archived log thread=1 sequence=27 RECID=45 STAMP=817923467
channel ch1: starting piece 1 at 12-JUN-13
channel ch1: finished piece 1 at 12-JUN-13
piece handle=/u01/backup/DB11G/DB11G_DB_1moc11cc_54_1 tag=TAG20130612T165748 comment=NONE
channel ch1: backup set complete, elapsed time: 00:00:01
Finished backup at 12-JUN-13
Starting backup at 12-JUN-13
channel ch1: starting full datafile backup set
channel ch1: specifying datafile(s) in backup set
including current control file in backup set
channel ch1: starting piece 1 at 12-JUN-13
channel ch1: finished piece 1 at 12-JUN-13
piece handle=/u01/backup/DB11G/DB11G_DB_1noc11cd_55_1 tag=TAG20130612T165749 comment=NONE
channel ch1: backup set complete, elapsed time: 00:00:01
Finished backup at 12-JUN-13
released channel: ch1
Recovery Manager complete.
[oracle@orcl u01]$ sqlplus
SQL> conn sys/admin as sysdba
SQL> alter system switch logfile;
SQL> alter system switch logfile;
System altered.
SQL> /
System altered.
SQL> /
System altered.
SQL>
SQL> create tablespace test_1 datafile '/u01/app/oracle/oradata/db11g/test_101.dbf' size 2m;
SQL> select name from v$tablespace;
NAME
------------------------------
SYSTEM
SYSAUX
UNDOTBS1
USERS
TEMP
RAVI
TEST
TEST_1
8 rows selected.
SQL> create user test1
2 identified by test1
3 default tablespace test_1;
User created.
SQL> grant connect, resource to test;
Grant succeeded.
SQL> create table test_1(id number);
Table created.
SQL> begin
for i in 1..10 loop
insert into test_1 values(i);
end loop;
end;
/ 2 3 4 5 6
PL/SQL procedure successfully completed.
SQL> commit;
Commit complete.
SQL> select count(*) from test_1;
COUNT(*)
----------
10
SQL> set time on;
17:03:43 SQL> connect test/test
Connected.
17:04:09 SQL> drop table test;
Table dropped.
17:04:15 SQL> conn sys/admin as sysdba
Connected.
17:04:39 SQL> col name format a51;
17:06:15 SQL> col status for a10;
17:06:26 SQL> select name,status from v$datafile;
NAME STATUS
--------------------------------------------------- ----------
/u01/app/oracle/oradata/db11g/system01.dbf SYSTEM
/u01/app/oracle/oradata/db11g/sysaux01.dbf ONLINE
/u01/app/oracle/oradata/db11g/undotbs01.dbf ONLINE
/u01/app/oracle/oradata/db11g/users01.dbf ONLINE
/u01/app/oracle/oradata/db11g/ravi01.dbf ONLINE
/u01/app/oracle/oradata/db11g/test01.dbf ONLINE
/u01/app/oracle/oradata/db11g/test_101.dbf ONLINE
17:07:15 SQL> alter tablespace test offline immediate;
Tablespace altered.
17:07:30 SQL> select name,status from v$datafile;
NAME STATUS
--------------------------------------------------- ----------
/u01/app/oracle/oradata/db11g/system01.dbf SYSTEM
/u01/app/oracle/oradata/db11g/sysaux01.dbf ONLINE
/u01/app/oracle/oradata/db11g/undotbs01.dbf ONLINE
/u01/app/oracle/oradata/db11g/users01.dbf ONLINE
/u01/app/oracle/oradata/db11g/ravi01.dbf ONLINE
/u01/app/oracle/oradata/db11g/test01.dbf RECOVER
/u01/app/oracle/oradata/db11g/test_101.dbf ONLINE
7 rows selected.
17:08:16 SQL> connect test1/test1
Connected.
17:08:31 SQL> create table test2(id number);
Table created.
17:09:38 SQL> begin
for i in 1..10 loop
insert into test2 values(i);
end loop;
end;
/
PL/SQL procedure successfully completed.
17:09:48 SQL> commit;
Commit complete.
17:09:51 SQL> select count(*) from test2;
COUNT(*)
----------
10
[oracle@orcl u01]$ rman
Recovery Manager: Release 11.2.0.1.0 - Production on Wed Jun 12 15:35:30 2013
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
RMAN> connect target
connected to target database: DB11G (DBID=287159184)
RMAN> list backup;
BS Key Size Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
42 28.78M DISK 00:00:02 12-JUN-13
BP Key: 42 Status: AVAILABLE Compressed: NO Tag: TAG20130612T165551
Piece Name: /u01/backup/DB11G/DB11G_DB_1coc118o_44_1
List of Archived Logs in backup set 42
Thrd Seq Low SCN Low Time Next SCN Next Time
---- ------- ---------- --------- ---------- ---------
1 3 785707 07-JUN-13 786173 07-JUN-13
1 4 786173 07-JUN-13 786176 07-JUN-13
1 5 786176 07-JUN-13 810540 07-JUN-13
1 6 810540 07-JUN-13 810667 07-JUN-13
1 7 810667 07-JUN-13 810670 07-JUN-13
1 8 810670 07-JUN-13 810674 07-JUN-13
1 9 810674 07-JUN-13 810677 07-JUN-13
1 10 810677 07-JUN-13 810682 07-JUN-13
1 11 810682 07-JUN-13 810685 07-JUN-13
1 12 810685 07-JUN-13 810688 07-JUN-13
1 13 810688 07-JUN-13 810691 07-JUN-13
1 14 810691 07-JUN-13 821070 07-JUN-13
BS Key Size Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
43 179.38M DISK 00:00:14 12-JUN-13
BP Key: 43 Status: AVAILABLE Compressed: NO Tag: TAG20130612T165551
Piece Name: /u01/backup/DB11G/DB11G_DB_1doc118s_45_1
List of Archived Logs in backup set 43
Thrd Seq Low SCN Low Time Next SCN Next Time
---- ------- ---------- --------- ---------- ---------
1 1 821082 10-JUN-13 821493 10-JUN-13
1 2 821493 10-JUN-13 821525 10-JUN-13
1 3 821525 10-JUN-13 827239 10-JUN-13
1 4 827239 10-JUN-13 842360 10-JUN-13
1 5 842360 10-JUN-13 871981 11-JUN-13
1 6 871981 11-JUN-13 876028 11-JUN-13
1 7 876028 11-JUN-13 876124 11-JUN-13
1 8 876124 11-JUN-13 876307 11-JUN-13
1 9 876307 11-JUN-13 876311 11-JUN-13
1 10 876311 11-JUN-13 876315 11-JUN-13
1 11 876315 11-JUN-13 876321 11-JUN-13
1 12 876321 11-JUN-13 878372 11-JUN-13
1 13 878372 11-JUN-13 882722 11-JUN-13
1 14 882722 11-JUN-13 882772 11-JUN-13
1 15 882772 11-JUN-13 909083 12-JUN-13
BS Key Size Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
44 40.57M DISK 00:00:02 12-JUN-13
BP Key: 44 Status: AVAILABLE Compressed: NO Tag: TAG20130612T165551
Piece Name: /u01/backup/DB11G/DB11G_DB_1eoc119b_46_1
List of Archived Logs in backup set 44
Thrd Seq Low SCN Low Time Next SCN Next Time
---- ------- ---------- --------- ---------- ---------
1 21 902545 09-JUN-13 921147 09-JUN-13
BS Key Size Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
45 5.68M DISK 00:00:01 12-JUN-13
BP Key: 45 Status: AVAILABLE Compressed: NO Tag: TAG20130612T165551
Piece Name: /u01/backup/DB11G/DB11G_DB_1foc119f_47_1
List of Archived Logs in backup set 45
Thrd Seq Low SCN Low Time Next SCN Next Time
---- ------- ---------- --------- ---------- ---------
1 16 909083 12-JUN-13 911013 12-JUN-13
1 17 911013 12-JUN-13 911052 12-JUN-13
1 18 911052 12-JUN-13 912283 12-JUN-13
1 19 912283 12-JUN-13 912286 12-JUN-13
1 20 912286 12-JUN-13 912292 12-JUN-13
1 21 912292 12-JUN-13 913442 12-JUN-13
1 22 913442 12-JUN-13 933915 12-JUN-13
BS Key Size Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
46 38.70M DISK 00:00:02 12-JUN-13
BP Key: 46 Status: AVAILABLE Compressed: NO Tag: TAG20130612T165551
Piece Name: /u01/backup/DB11G/DB11G_DB_1goc119g_48_1
List of Archived Logs in backup set 46
Thrd Seq Low SCN Low Time Next SCN Next Time
---- ------- ---------- --------- ---------- ---------
1 22 921147 09-JUN-13 935457 10-JUN-13
BS Key Size Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
47 2.72M DISK 00:00:00 12-JUN-13
BP Key: 47 Status: AVAILABLE Compressed: NO Tag: TAG20130612T165551
Piece Name: /u01/backup/DB11G/DB11G_DB_1hoc119k_49_1
List of Archived Logs in backup set 47
Thrd Seq Low SCN Low Time Next SCN Next Time
---- ------- ---------- --------- ---------- ---------
1 23 933915 12-JUN-13 934937 12-JUN-13
1 24 934937 12-JUN-13 934975 12-JUN-13
1 25 934975 12-JUN-13 935842 12-JUN-13
BS Key Size Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
48 32.13M DISK 00:00:02 12-JUN-13
BP Key: 48 Status: AVAILABLE Compressed: NO Tag: TAG20130612T165551
Piece Name: /u01/backup/DB11G/DB11G_DB_1ioc119l_50_1
List of Archived Logs in backup set 48
Thrd Seq Low SCN Low Time Next SCN Next Time
---- ------- ---------- --------- ---------- ---------
1 23 935457 10-JUN-13 960820 10-JUN-13
BS Key Size Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
49 733.50K DISK 00:00:00 12-JUN-13
BP Key: 49 Status: AVAILABLE Compressed: NO Tag: TAG20130612T165551
Piece Name: /u01/backup/DB11G/DB11G_DB_1joc119p_51_1
List of Archived Logs in backup set 49
Thrd Seq Low SCN Low Time Next SCN Next Time
---- ------- ---------- --------- ---------- ---------
1 26 935842 12-JUN-13 936718 12-JUN-13
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
50 Full 959.59M DISK 00:01:08 12-JUN-13
BP Key: 50 Status: AVAILABLE Compressed: NO Tag: TAG20130612T165626
Piece Name: /u01/backup/DB11G/DB11G_DB_1koc119r_52_1
List of Datafiles in backup set 50
File LV Type Ckp SCN Ckp Time Name
---- -- ---- ---------- --------- ----
1 Full 936730 12-JUN-13 /u01/app/oracle/oradata/db11g/system01.dbf
2 Full 936730 12-JUN-13 /u01/app/oracle/oradata/db11g/sysaux01.dbf
3 Full 936730 12-JUN-13 /u01/app/oracle/oradata/db11g/undotbs01.dbf
4 Full 936730 12-JUN-13 /u01/app/oracle/oradata/db11g/users01.dbf
5 Full 936730 12-JUN-13 /u01/app/oracle/oradata/db11g/ravi01.dbf
6 Full 936730 12-JUN-13 /u01/app/oracle/oradata/db11g/test01.dbf
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
51 Full 9.39M DISK 00:00:04 12-JUN-13
BP Key: 51 Status: AVAILABLE Compressed: NO Tag: TAG20130612T165626
Piece Name: /u01/backup/DB11G/DB11G_DB_1loc11c7_53_1
SPFILE Included: Modification time: 12-JUN-13
SPFILE db_unique_name: DB11G
Control File Included: Ckp SCN: 936750 Ckp time: 12-JUN-13
BS Key Size Device Type Elapsed Time Completion Time
------- ---------- ----------- ------------ ---------------
52 14.00K DISK 00:00:00 12-JUN-13
BP Key: 52 Status: AVAILABLE Compressed: NO Tag: TAG20130612T165748
Piece Name: /u01/backup/DB11G/DB11G_DB_1moc11cc_54_1
List of Archived Logs in backup set 52
Thrd Seq Low SCN Low Time Next SCN Next Time
---- ------- ---------- --------- ---------- ---------
1 27 936718 12-JUN-13 936756 12-JUN-13
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
53 Full 9.36M DISK 00:00:02 12-JUN-13
BP Key: 53 Status: AVAILABLE Compressed: NO Tag: TAG20130612T165749
Piece Name: /u01/backup/DB11G/DB11G_DB_1noc11cd_55_1
Control File Included: Ckp SCN: 936765 Ckp time: 12-JUN-13
RMAN> run
{
recover tablespace 'TEST'
until scn 936765
AUXILIARY DESTINATION '/u01/auxilary';
}
Starting recover at 12-JUN-13
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=43 device type=DISK
RMAN-05026: WARNING: presuming following set of tablespaces applies to specified point-in-time
List of tablespaces expected to have UNDO segments
Tablespace SYSTEM
Tablespace UNDOTBS1
Creating automatic instance, with SID='ltix'
initialization parameters used for automatic instance:
db_name=DB11G
db_unique_name=ltix_tspitr_DB11G
compatible=11.2.0.0.0
db_block_size=8192
db_files=200
sga_target=280M
processes=50
db_create_file_dest=/u01/auxilary
log_archive_dest_1='location=/u01/auxilary'
#No auxiliary parameter file used
starting up automatic instance DB11G
Oracle instance started
Total System Global Area 292933632 bytes
Fixed Size 1336092 bytes
Variable Size 100666596 bytes
Database Buffers 184549376 bytes
Redo Buffers 6381568 bytes
Automatic instance created
Running TRANSPORT_SET_CHECK on recovery set tablespaces
TRANSPORT_SET_CHECK completed successfully
contents of Memory Script:
{
# set requested point in time
set until scn 936765;
# restore the controlfile
restore clone controlfile;
# mount the controlfile
sql clone 'alter database mount clone database';
# archive current online log
sql 'alter system archive log current';
# avoid unnecessary autobackups for structural changes during TSPITR
sql 'begin dbms_backup_restore.AutoBackupFlag(FALSE); end;';
}
executing Memory Script
executing command: SET until clause
Starting restore at 12-JUN-13
allocated channel: ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: SID=19 device type=DISK
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: restoring control file
channel ORA_AUX_DISK_1: reading from backup piece /u01/backup/DB11G/DB11G_DB_1noc11cd_55_1
channel ORA_AUX_DISK_1: piece handle=/u01/backup/DB11G/DB11G_DB_1noc11cd_55_1 tag=TAG20130612T165749
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:01
output file name=/u01/auxilary/DB11G/controlfile/o1_mf_8vjr943b_.ctl
Finished restore at 12-JUN-13
sql statement: alter database mount clone database
sql statement: alter system archive log current
sql statement: begin dbms_backup_restore.AutoBackupFlag(FALSE); end;
contents of Memory Script:
{
# set requested point in time
set until scn 936765;
# set destinations for recovery set and auxiliary set datafiles
set newname for clone datafile 1 to new;
set newname for clone datafile 3 to new;
set newname for clone datafile 2 to new;
set newname for clone tempfile 1 to new;
set newname for datafile 6 to
"/u01/app/oracle/oradata/db11g/test01.dbf";
# switch all tempfiles
switch clone tempfile all;
# restore the tablespaces in the recovery set and the auxiliary set
restore clone datafile 1, 3, 2, 6;
switch clone datafile all;
}
executing Memory Script
executing command: SET until clause
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
executing command: SET NEWNAME
renamed tempfile 1 to /u01/auxilary/DB11G/datafile/o1_mf_temp_%u_.tmp in control file
Starting restore at 12-JUN-13
using channel ORA_AUX_DISK_1
channel ORA_AUX_DISK_1: starting datafile backup set restore
channel ORA_AUX_DISK_1: specifying datafile(s) to restore from backup set
channel ORA_AUX_DISK_1: restoring datafile 00001 to /u01/auxilary/DB11G/datafile/o1_mf_system_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00003 to /u01/auxilary/DB11G/datafile/o1_mf_undotbs1_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00002 to /u01/auxilary/DB11G/datafile/o1_mf_sysaux_%u_.dbf
channel ORA_AUX_DISK_1: restoring datafile 00006 to /u01/app/oracle/oradata/db11g/test01.dbf
channel ORA_AUX_DISK_1: reading from backup piece /u01/backup/DB11G/DB11G_DB_1koc119r_52_1
channel ORA_AUX_DISK_1: piece handle=/u01/backup/DB11G/DB11G_DB_1koc119r_52_1 tag=TAG20130612T165626
channel ORA_AUX_DISK_1: restored backup piece 1
channel ORA_AUX_DISK_1: restore complete, elapsed time: 00:00:45
Finished restore at 12-JUN-13
datafile 1 switched to datafile copy
input datafile copy RECID=4 STAMP=817925043 file name=/u01/auxilary/DB11G/datafile/o1_mf_system_8vjr9ft2_.dbf
datafile 3 switched to datafile copy
input datafile copy RECID=5 STAMP=817925043 file name=/u01/auxilary/DB11G/datafile/o1_mf_undotbs1_8vjr9ftv_.dbf
datafile 2 switched to datafile copy
input datafile copy RECID=6 STAMP=817925043 file name=/u01/auxilary/DB11G/datafile/o1_mf_sysaux_8vjr9ftr_.dbf
contents of Memory Script:
{
# set requested point in time
set until scn 936765;
# online the datafiles restored or switched
sql clone "alter database datafile 1 online";
sql clone "alter database datafile 3 online";
sql clone "alter database datafile 2 online";
sql clone "alter database datafile 6 online";
# recover and open resetlogs
recover clone database tablespace "TEST", "SYSTEM", "UNDOTBS1", "SYSAUX" delete archivelog;
alter clone database open resetlogs;
}
executing Memory Script
executing command: SET until clause
sql statement: alter database datafile 1 online
sql statement: alter database datafile 3 online
sql statement: alter database datafile 2 online
sql statement: alter database datafile 6 online
Starting recover at 12-JUN-13
using channel ORA_AUX_DISK_1
starting media recovery
archived log for thread 1 with sequence 27 is already on disk as file /u01/archivelog/arch_1_27_817749339.arc
archived log for thread 1 with sequence 28 is already on disk as file /u01/archivelog/arch_1_28_817749339.arc
archived log file name=/u01/archivelog/arch_1_27_817749339.arc thread=1 sequence=27
archived log file name=/u01/archivelog/arch_1_28_817749339.arc thread=1 sequence=28
media recovery complete, elapsed time: 00:00:01
Finished recover at 12-JUN-13
database opened
contents of Memory Script:
{
# make read only the tablespace that will be exported
sql clone 'alter tablespace "TEST" read only';
# create directory for datapump import
sql "create or replace directory TSPITR_DIROBJ_DPDIR as ''
/u01/auxilary''";
# create directory for datapump export
sql clone "create or replace directory TSPITR_DIROBJ_DPDIR as ''
/u01/auxilary''";
}
executing Memory Script
sql statement: alter tablespace "TEST" read only
sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/u01/auxilary''
sql statement: create or replace directory TSPITR_DIROBJ_DPDIR as ''/u01/auxilary''
Performing export of metadata...
EXPDP> Starting "SYS"."TSPITR_EXP_ltix":
EXPDP> Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
EXPDP> Processing object type TRANSPORTABLE_EXPORT/TABLE
EXPDP> Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
EXPDP> Master table "SYS"."TSPITR_EXP_ltix" successfully loaded/unloaded
EXPDP> ******************************************************************************
EXPDP> Dump file set for SYS.TSPITR_EXP_ltix is:
EXPDP> /u01/auxilary/tspitr_ltix_72884.dmp
EXPDP> ******************************************************************************
EXPDP> Datafiles required for transportable tablespace TEST:
EXPDP> /u01/app/oracle/oradata/db11g/test01.dbf
EXPDP> Job "SYS"."TSPITR_EXP_ltix" successfully completed at 17:26:08
Export completed
contents of Memory Script:
{
# shutdown clone before import
shutdown clone immediate
# drop target tablespaces before importing them back
sql 'drop tablespace "TEST" including contents keep datafiles';
}
executing Memory Script
database closed
database dismounted
Oracle instance shut down
sql statement: drop tablespace "TEST" including contents keep datafiles
Performing import of metadata...
IMPDP> Master table "SYS"."TSPITR_IMP_ltix" successfully loaded/unloaded
IMPDP> Starting "SYS"."TSPITR_IMP_ltix":
IMPDP> Processing object type TRANSPORTABLE_EXPORT/PLUGTS_BLK
IMPDP> Processing object type TRANSPORTABLE_EXPORT/TABLE
IMPDP> Processing object type TRANSPORTABLE_EXPORT/POST_INSTANCE/PLUGTS_BLK
IMPDP> Job "SYS"."TSPITR_IMP_ltix" successfully completed at 17:27:15
Import completed
contents of Memory Script:
{
# make read write and offline the imported tablespaces
sql 'alter tablespace "TEST" read write';
sql 'alter tablespace "TEST" offline';
# enable autobackups after TSPITR is finished
sql 'begin dbms_backup_restore.AutoBackupFlag(TRUE); end;';
}
executing Memory Script
sql statement: alter tablespace "TEST" read write
sql statement: alter tablespace "TEST" offline
sql statement: begin dbms_backup_restore.AutoBackupFlag(TRUE); end;
Removing automatic instance
Automatic instance removed
auxiliary instance file /u01/auxilary/DB11G/datafile/o1_mf_temp_8vjrc9z4_.tmp deleted
auxiliary instance file /u01/auxilary/DB11G/onlinelog/o1_mf_3_8vjrc34l_.log deleted
auxiliary instance file /u01/auxilary/DB11G/onlinelog/o1_mf_2_8vjrc1vp_.log deleted
auxiliary instance file /u01/auxilary/DB11G/onlinelog/o1_mf_1_8vjrc0gv_.log deleted
auxiliary instance file /u01/auxilary/DB11G/datafile/o1_mf_sysaux_8vjr9ftr_.dbf deleted
auxiliary instance file /u01/auxilary/DB11G/datafile/o1_mf_undotbs1_8vjr9ftv_.dbf deleted
auxiliary instance file /u01/auxilary/DB11G/datafile/o1_mf_system_8vjr9ft2_.dbf deleted
auxiliary instance file /u01/auxilary/DB11G/controlfile/o1_mf_8vjr943b_.ctl deleted
Finished recover at 12-JUN-13
RMAN> exit
Recovery Manager complete.
[oracle@orcl u01]$sqlplus
SQL> conn test/test
Connected.
SQL> select count(*) from test;
select count(*) from test
*
ERROR at line 1:
ORA-00376: file 6 cannot be read at this time
ORA-01110: data file 6: '/u01/app/oracle/oradata/db11g/test01.dbf'
SQL> conn /as sysdba
Connected.
SQL> alter tablespace test online;
Tablespace altered.
SQL> conn test/test;
Connected.
SQL> select count(*) from test;
COUNT(*)
----------
10
Sunday, 9 June 2013
how to recover dropped table in oracle?
how to recover dropped table in oracle?
Example:-
SQL>create table test_backup(id number);
SQL> begin
2 for i in 1..10 loop
3 insert into test_backup values(i);
4 end loop;
5 end;
6 /
PL/SQL procedure successfully completed.
SQL> commit;
Commit complete.
SQL> begin
2 for i in 1..10000 loop
3 insert into test_backup values(i);
4 end loop;
5 end;
6 /
PL/SQL procedure successfully completed.
SQL> commit;
Commit complete.
SQL> create index test_backup_ndx on test_backup(id);
Index created.
SQL> select index_name,STATUS from user_indexes where lower(table_name)='test_backup';
INDEX_NAME
------------------------------
TEST_BACKUP_NDX
SQL> select count(*) from test_backup;
COUNT(*)
----------
10010
SQL> SHOW RECYCLEBIN
ORIGINAL NAME RECYCLEBIN NAME OBJECT TYPE DROP TIME
---------------- ------------------------------ ------------ -------------------
TEST BIN$3pJCivMX4efgQKjAh4A0sg==$0 TABLE 2013-06-07:20:00:34
TEST BIN$3pJCivMW4efgQKjAh4A0sg==$0 TABLE 2013-06-07:19:59:34
note:- test table name not present in recyclebin list.
SQL> drop table test_backup;
Table dropped.
SQL> SHOW RECYCLEBIN
ORIGINAL NAME RECYCLEBIN NAME OBJECT TYPE DROP TIME
---------------- ------------------------------ ------------ -------------------
TEST BIN$3pJCivMX4efgQKjAh4A0sg==$0 TABLE 2013-06-07:20:00:34
TEST BIN$3pJCivMW4efgQKjAh4A0sg==$0 TABLE 2013-06-07:19:59:34
TEST_BACKUP BIN$3swJiRz/0tbgQKjAh4Bysw==$0 TABLE 2013-06-10:17:05:09
note:- now test_backup table name present in RECYCLEBIN list.
SQL> select count(*) from "BIN$3swJiRz/0tbgQKjAh4Bysw==$0";
COUNT(*)
----------
10010
SQL> flashback table test_backup to before drop;
Flashback complete.
SQL> SHOW RECYCLEBIN
ORIGINAL NAME RECYCLEBIN NAME OBJECT TYPE DROP TIME
---------------- ------------------------------ ------------ -------------------
TEST BIN$3pJCivMX4efgQKjAh4A0sg==$0 TABLE 2013-06-07:20:00:34
TEST BIN$3pJCivMW4efgQKjAh4A0sg==$0 TABLE 2013-06-07:19:59:34
note:- now test table name not present in recyclebin list.
sql> select count(*) from test_backup;
COUNT(*)
----------
10010
SQL> select index_name,STATUS from user_indexes where lower(table_name)='test_backup';
INDEX_NAME STATUS
------------------------------ --------
BIN$3swJiRz+0tbgQKjAh4Bysw==$0 VALID
SQL>alter index "BIN$3swJiRz+0tbgQKjAh4Bysw==$0" rename to TEST_BACKUP_NDX;
SQL> select index_name,STATUS from user_indexes where lower(table_name)='test_backup';
INDEX_NAME STATUS
------------------------------ --------
TEST_BACKUP_NDX VALID
Example:-
SQL>create table test_backup(id number);
SQL> begin
2 for i in 1..10 loop
3 insert into test_backup values(i);
4 end loop;
5 end;
6 /
PL/SQL procedure successfully completed.
SQL> commit;
Commit complete.
SQL> begin
2 for i in 1..10000 loop
3 insert into test_backup values(i);
4 end loop;
5 end;
6 /
PL/SQL procedure successfully completed.
SQL> commit;
Commit complete.
SQL> create index test_backup_ndx on test_backup(id);
Index created.
SQL> select index_name,STATUS from user_indexes where lower(table_name)='test_backup';
INDEX_NAME
------------------------------
TEST_BACKUP_NDX
SQL> select count(*) from test_backup;
COUNT(*)
----------
10010
SQL> SHOW RECYCLEBIN
ORIGINAL NAME RECYCLEBIN NAME OBJECT TYPE DROP TIME
---------------- ------------------------------ ------------ -------------------
TEST BIN$3pJCivMX4efgQKjAh4A0sg==$0 TABLE 2013-06-07:20:00:34
TEST BIN$3pJCivMW4efgQKjAh4A0sg==$0 TABLE 2013-06-07:19:59:34
note:- test table name not present in recyclebin list.
SQL> drop table test_backup;
Table dropped.
SQL> SHOW RECYCLEBIN
ORIGINAL NAME RECYCLEBIN NAME OBJECT TYPE DROP TIME
---------------- ------------------------------ ------------ -------------------
TEST BIN$3pJCivMX4efgQKjAh4A0sg==$0 TABLE 2013-06-07:20:00:34
TEST BIN$3pJCivMW4efgQKjAh4A0sg==$0 TABLE 2013-06-07:19:59:34
TEST_BACKUP BIN$3swJiRz/0tbgQKjAh4Bysw==$0 TABLE 2013-06-10:17:05:09
note:- now test_backup table name present in RECYCLEBIN list.
SQL> select count(*) from "BIN$3swJiRz/0tbgQKjAh4Bysw==$0";
COUNT(*)
----------
10010
SQL> flashback table test_backup to before drop;
Flashback complete.
SQL> SHOW RECYCLEBIN
ORIGINAL NAME RECYCLEBIN NAME OBJECT TYPE DROP TIME
---------------- ------------------------------ ------------ -------------------
TEST BIN$3pJCivMX4efgQKjAh4A0sg==$0 TABLE 2013-06-07:20:00:34
TEST BIN$3pJCivMW4efgQKjAh4A0sg==$0 TABLE 2013-06-07:19:59:34
note:- now test table name not present in recyclebin list.
sql> select count(*) from test_backup;
COUNT(*)
----------
10010
SQL> select index_name,STATUS from user_indexes where lower(table_name)='test_backup';
INDEX_NAME STATUS
------------------------------ --------
BIN$3swJiRz+0tbgQKjAh4Bysw==$0 VALID
SQL>alter index "BIN$3swJiRz+0tbgQKjAh4Bysw==$0" rename to TEST_BACKUP_NDX;
SQL> select index_name,STATUS from user_indexes where lower(table_name)='test_backup';
INDEX_NAME STATUS
------------------------------ --------
TEST_BACKUP_NDX VALID
Thursday, 6 June 2013
create database in archivelog mode
Q:-how create database in archive log mode after Creation of database?
Ans:-
sql> archive log list;
Database log mode No Archive Mode
Automatic archival Disabled
Archive destination /u01/database
Oldest online log sequence 1
Current log sequence 3
sql>
Ans:-
sql> archive log list;
Database log mode No Archive Mode
Automatic archival Disabled
Archive destination /u01/database
Oldest online log sequence 1
Current log sequence 3
sql>
alter system set log_archive_dest_1='LOCATION=/u01/archivelog
' scope=spfile;
sql>
show parameter log_archive_format;
System altered.
sql> show parameter log_archive_format;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
log_archive_format string %t_%s_%r.dbf
sql>alter system set log_archive_format='arch_%t_%s_%r_%d.arc' SCOPE=spfile;
System altered.
sql>shut immediate;
sql> startup mount;
ORACLE instance started.
ORACLE instance started.
Total System Global Area 422670336 bytes
Fixed Size 1336960 bytes
Variable Size 260049280 bytes
Database Buffers 155189248 bytes
Redo Buffers 6094848 bytes
Database mounted.
sql>alter database archivelog;
sql> alter database open;
sql> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u01/database
Oldest online log sequence 1
Next log sequence to archive 3
Current log sequence 3
sql> alter system switch logfile;
sql> alter system switch logfile;
sql> alter system switch logfile;
sql> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /u01/database
Oldest online log sequence 3
Next log sequence to archive 3
Current log sequence 5
Monday, 3 June 2013
how to create sql profile manually
After going through number Documents regarding sql profile. i got some solution regarding how to create sql profile manually. so below is example shows details of creation of sql profile.
1) Session I (connect normal user i used scott user).
SQL> exec dbms_stats.gather_table_stats('','TEST');
PL/SQL procedure successfully completed.
sql>set autotrace on
sql>select /*+ no_index(test test_idx) */ * from test where id=1;
Plan hash value: 1357081020
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 4 | 7 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| TEST | 1 | 4 | 7 (0)| 00:00:01 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("N"=1)
2) Session II (connect as sysdba).
Create and execute tuning task and run report tuning task.
Accept recommended SQL Profile.
Output:
GENERAL INFORMATION SECTION
-------------------------------------------------------------------------------
Tuning Task Name : my_sql_tuning_task_2
Tuning Task Owner : SCOTT
Workload Type : Single SQL Statement
Scope : COMPREHENSIVE
Time Limit(seconds): 60
Completion Status : COMPLETED
Started at : 06/04/2013 10:27:27
Completed at : 06/04/2013 10:27:32
-------------------------------------------------------------------------------
Schema Name: SCOTT
SQL ID : d4wgpc5g0s0vu
SQL Text : select /*+ no_index(test test_idx) */ * from test where id=1
-------------------------------------------------------------------------------
FINDINGS SECTION (1 finding)
-------------------------------------------------------------------------------
1- SQL Profile Finding (see explain plans section below)
--------------------------------------------------------
A potentially better execution plan was found for this statement.
Recommendation (estimated benefit: 95%)
---------------------------------------
- Consider accepting the recommended SQL profile.
execute dbms_sqltune.accept_sql_profile(task_name =>
'my_sql_tuning_task_2', task_owner => 'SCOTT', replace => TRUE);
Validation results
------------------
The SQL profile was tested by executing both its plan and the original plan
and measuring their respective execution statistics. A plan may have been
only partially executed if the other could be run to completion in less time.
Original Plan With SQL Profile % Improved
------------- ---------------- ----------
Completion Status: COMPLETE COMPLETE
Elapsed Time(us): 600 40 93.33 %
CPU Time(us): 399 0 100 %
User I/O Time(us): 0 0
Buffer Gets: 20 1 95 %
Physical Read Requests: 0 0
Physical Write Requests: 0 0
Physical Read Bytes: 0 0
Physical Write Bytes: 0 0
Rows Processed: 1 1
Fetches: 1 1
Executions: 1 1
Notes
-----
1. The original plan was first executed to warm the buffer cache.
2. Statistics for original plan were averaged over next 9 executions.
3. The SQL profile plan was first executed to warm the buffer cache.
4. Statistics for the SQL profile plan were averaged over next 9 executions.
-------------------------------------------------------------------------------
EXPLAIN PLANS SECTION
-------------------------------------------------------------------------------
1- Original With Adjusted Cost
------------------------------
Plan hash value: 1357081020
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 4 | 7 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| TEST | 1 | 4 | 7 (0)| 00:00:01 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("N"=1)
2- Using SQL Profile
--------------------
Plan hash value: 2882402178
-----------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 4 | 1 (0)| 00:00:01 |
|* 1 | INDEX RANGE SCAN| TEST_IDX | 1 | 4 | 1 (0)| 00:00:01 |
-----------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("N"=1)
-------------------------------------------------------------------------------
Execution Plan
----------------------------------------------------------
Plan hash value: 1388734953
-----------------------------------------------------------------
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
-----------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 2 (0)| 00:00:01 |
| 1 | FAST DUAL | | 1 | 2 (0)| 00:00:01 |
-----------------------------------------------------------------
Statistics
----------------------------------------------------------
4134 recursive calls
954 db block gets
2614 consistent gets
50 physical reads
572 redo size
5812 bytes sent via SQL*Net to client
1280 bytes received via SQL*Net from client
9 SQL*Net roundtrips to/from client
78 sorts (memory)
0 sorts (disk)
1 rows processed
sql>DECLARE
my_sqlprofile_name VARCHAR2(30);
begin
my_sqlprofile_name := DBMS_SQLTUNE.ACCEPT_SQL_PROFILE (
task_name => 'my_sql_tuning_task_2',
name => 'my_sql_profile');
end;
/
3) Session I (connect to scott user).
----------------------------------------------------------
Plan hash value: 2882402178
-----------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 4 | 1 (0)| 00:00:01 |
|* 1 | INDEX RANGE SCAN| TEST_IDX | 1 | 4 | 1 (0)| 00:00:01 |
-----------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("N"=1)
Note
-----
- SQL profile "my_sql_profile" used for this statement
Statistics
----------------------------------------------------------
9 recursive calls
0 db block gets
7 consistent gets
1 physical reads
0 redo size
415 bytes sent via SQL*Net to client
419 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
note:- now check CPU usage of particulate query.
hope this document will help you to solve the problem which you face during the creation of sql profile.also i am saying thanks to my friend fahim Mulla who help during creation of this Document.
1) Session I (connect normal user i used scott user).
SQL>
create table test (id number );
Table created.
Table created.
SQL>
declare
begin
for i in 1 .. 10000 loop
insert into test values(i);
commit;
end loop;
end;
/
PL/SQL procedure successfully completed.
begin
for i in 1 .. 10000 loop
insert into test values(i);
commit;
end loop;
end;
/
PL/SQL procedure successfully completed.
SQL>
create index test_idx on test(id);
Index created.
Index created.
SQL> exec dbms_stats.gather_table_stats('','TEST');
PL/SQL procedure successfully completed.
sql>set autotrace on
sql>select /*+ no_index(test test_idx) */ * from test where id=1;
Plan hash value: 1357081020
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 4 | 7 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| TEST | 1 | 4 | 7 (0)| 00:00:01 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("N"=1)
2) Session II (connect as sysdba).
Create and execute tuning task and run report tuning task.
Accept recommended SQL Profile.
sql>declare
my_task_name VARCHAR2(30);
my_sqltext CLOB;
begin
my_sqltext := 'select /*+ no_index(test test_idx) */ * from test where id=1';
my_task_name := DBMS_SQLTUNE.CREATE_TUNING_TASK(
sql_text => my_sqltext,
user_name => 'SCOTT',
scope => 'COMPREHENSIVE',
time_limit => 60,
task_name => 'my_sql_tuning_task_2',
description => 'Task to tune a query on a specified table');
end;
/
PL/SQL procedure successfully completed.
my_task_name VARCHAR2(30);
my_sqltext CLOB;
begin
my_sqltext := 'select /*+ no_index(test test_idx) */ * from test where id=1';
my_task_name := DBMS_SQLTUNE.CREATE_TUNING_TASK(
sql_text => my_sqltext,
user_name => 'SCOTT',
scope => 'COMPREHENSIVE',
time_limit => 60,
task_name => 'my_sql_tuning_task_2',
description => 'Task to tune a query on a specified table');
end;
/
PL/SQL procedure successfully completed.
sql>begin
DBMS_SQLTUNE.EXECUTE_TUNING_TASK( task_name => 'my_sql_tuning_task_2');
end;
/
DBMS_SQLTUNE.EXECUTE_TUNING_TASK( task_name => 'my_sql_tuning_task_2');
end;
/
PL/SQL
procedure successfully completed.
set long
10000
set longchunksize 1000
set linesize 100
set heading off
sql>SELECT DBMS_SQLTUNE.REPORT_TUNING_TASK( 'my_sql_tuning_task_2') from DUAL;
set heading on
set longchunksize 1000
set linesize 100
set heading off
sql>SELECT DBMS_SQLTUNE.REPORT_TUNING_TASK( 'my_sql_tuning_task_2') from DUAL;
set heading on
Output:
GENERAL INFORMATION SECTION
-------------------------------------------------------------------------------
Tuning Task Name : my_sql_tuning_task_2
Tuning Task Owner : SCOTT
Workload Type : Single SQL Statement
Scope : COMPREHENSIVE
Time Limit(seconds): 60
Completion Status : COMPLETED
Started at : 06/04/2013 10:27:27
Completed at : 06/04/2013 10:27:32
-------------------------------------------------------------------------------
Schema Name: SCOTT
SQL ID : d4wgpc5g0s0vu
SQL Text : select /*+ no_index(test test_idx) */ * from test where id=1
-------------------------------------------------------------------------------
FINDINGS SECTION (1 finding)
-------------------------------------------------------------------------------
1- SQL Profile Finding (see explain plans section below)
--------------------------------------------------------
A potentially better execution plan was found for this statement.
Recommendation (estimated benefit: 95%)
---------------------------------------
- Consider accepting the recommended SQL profile.
execute dbms_sqltune.accept_sql_profile(task_name =>
'my_sql_tuning_task_2', task_owner => 'SCOTT', replace => TRUE);
Validation results
------------------
The SQL profile was tested by executing both its plan and the original plan
and measuring their respective execution statistics. A plan may have been
only partially executed if the other could be run to completion in less time.
Original Plan With SQL Profile % Improved
------------- ---------------- ----------
Completion Status: COMPLETE COMPLETE
Elapsed Time(us): 600 40 93.33 %
CPU Time(us): 399 0 100 %
User I/O Time(us): 0 0
Buffer Gets: 20 1 95 %
Physical Read Requests: 0 0
Physical Write Requests: 0 0
Physical Read Bytes: 0 0
Physical Write Bytes: 0 0
Rows Processed: 1 1
Fetches: 1 1
Executions: 1 1
Notes
-----
1. The original plan was first executed to warm the buffer cache.
2. Statistics for original plan were averaged over next 9 executions.
3. The SQL profile plan was first executed to warm the buffer cache.
4. Statistics for the SQL profile plan were averaged over next 9 executions.
-------------------------------------------------------------------------------
EXPLAIN PLANS SECTION
-------------------------------------------------------------------------------
1- Original With Adjusted Cost
------------------------------
Plan hash value: 1357081020
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 4 | 7 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| TEST | 1 | 4 | 7 (0)| 00:00:01 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("N"=1)
2- Using SQL Profile
--------------------
Plan hash value: 2882402178
-----------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 4 | 1 (0)| 00:00:01 |
|* 1 | INDEX RANGE SCAN| TEST_IDX | 1 | 4 | 1 (0)| 00:00:01 |
-----------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("N"=1)
-------------------------------------------------------------------------------
Execution Plan
----------------------------------------------------------
Plan hash value: 1388734953
-----------------------------------------------------------------
| Id | Operation | Name | Rows | Cost (%CPU)| Time |
-----------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 2 (0)| 00:00:01 |
| 1 | FAST DUAL | | 1 | 2 (0)| 00:00:01 |
-----------------------------------------------------------------
Statistics
----------------------------------------------------------
4134 recursive calls
954 db block gets
2614 consistent gets
50 physical reads
572 redo size
5812 bytes sent via SQL*Net to client
1280 bytes received via SQL*Net from client
9 SQL*Net roundtrips to/from client
78 sorts (memory)
0 sorts (disk)
1 rows processed
sql>DECLARE
my_sqlprofile_name VARCHAR2(30);
begin
my_sqlprofile_name := DBMS_SQLTUNE.ACCEPT_SQL_PROFILE (
task_name => 'my_sql_tuning_task_2',
name => 'my_sql_profile');
end;
/
PL/SQL
procedure successfully completed.
3) Session I (connect to scott user).
SQL>
set autotrace on
SQL> select /*+ no_index(test test_idx) */ * from test where id=1;
Execution Plan SQL> select /*+ no_index(test test_idx) */ * from test where id=1;
----------------------------------------------------------
Plan hash value: 2882402178
-----------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 4 | 1 (0)| 00:00:01 |
|* 1 | INDEX RANGE SCAN| TEST_IDX | 1 | 4 | 1 (0)| 00:00:01 |
-----------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("N"=1)
Note
-----
- SQL profile "my_sql_profile" used for this statement
Statistics
----------------------------------------------------------
9 recursive calls
0 db block gets
7 consistent gets
1 physical reads
0 redo size
415 bytes sent via SQL*Net to client
419 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
note:- now check CPU usage of particulate query.
hope this document will help you to solve the problem which you face during the creation of sql profile.also i am saying thanks to my friend fahim Mulla who help during creation of this Document.
Subscribe to:
Posts (Atom)
work on autovacuum postgreSQL parameter
In This blog, we are discussing the auto vacuum parameter on a small scale. we will understand the below parameters and will see how to mod...
-
WARNING: 2019-06-15 06:40:03 WARNING OGG-02045 Database does not have streams_pool_size initialization parameter configured. Solut...
-
[INS-41112] Specified network interface doesnt maintain connectivity across cluster nodes issue and solution 01:- restart both node an...
-
error Details : SQL> alter user C##GGATE default tablespace GGUSER; alter user C##GGATE default tablespace GGUSER * ERROR at line ...