11.09.2009

Different Options for Exports/Imports:

expdp help=y
To estimate size without actually taking the dump:
expdp prod7/thword7 tables=OLD_DATA directory=DUMPS_NAHAR estimate_only=y
=>estimated "PROD7"."OLD_DATA" 156.8 GB

Directory creation
SQL> col DIRECTORY_PATH format a60
SQL> select DIRECTORY_NAME,DIRECTORY_PATH from dba_directories;

SQL> Create or replace directory DUMPS_NAHAR3 As '/oracle';
SQL> grant read,write on directory DUMPS_NAHAR3 to prod7;

EXPORT
expdp single table
expdp prod/pass tables=LOGIN directory=DBDUMPS dumpfile=LOGIN_20100620.dmp logfile=LOGIN_20100620_LOG.log

expdp Multiple tables, starting with different name
expdp prod/
pass tables=LOGIN_CLIENTS,TAC_FORM_SUMMARY directory=DUMPS_TAHSEEN dumpfile=DUMPS_TAHSEEN_20100301.dmp logfile=DUMPS_TAHSEEN_EXPORT_LOG_20100301.log

expdp Multiple tables, starting with same name - TMS
expdp prod/pass DIRECTORY=DUMPS_NAHAR_NEPTUNE SCHEMAS=prod INCLUDE=TABLE:"like'TR_%'" DUMPFILE=DUMPS_ZAHIDUL_20100308.dmp logfile=DUMPS_ZAHIDUL_EXPORT_LOG_20100308.log

Example - Exclude tables
expdp prod/
pass DIRECTORY=DUMPS_TERMINUS_PROD7_20100708 SCHEMAS=PROD EXCLUDE=TABLE:\"IN \(\'OLD_DATA\',\'USER_ACTIVITY\'\)\" DUMPFILE=DUMPS_TERMINUS_PROD_20100708.dmp logfile=DUMPS_TERMINUS_PROD_20100708_LOG_20100308.log

exclude=TABLE:\"='TABLE_NAME'\"
EXCLUDE=TABLE:\"IN \(\'TEMP\',\'TEMP1\'\)\"

Full schema
expdp atiq2/pass schemas=atiq2 directory=DUMPS_NAHAR3 dumpfile=atiq2_nd_20100907.dmp logfile=exp_atiq2_nd_20100907.log

In multiple file
expdp prod7/pass SCHEMAS=prod7 DIRECTORY=data_pump_dir DUMPFILE=saturn_prod7_%U.dmp FILESIZE=5G LOGFILE=saturn_prod7_exp.log


IMPORT
1: TABLE_EXISTS_ACTION=replace
impdp prod/pass DIRECTORY=DUMPS_NAHAR_NEPTUNE SCHEMAS=prod DUMPFILE=dbserver_scema_date.dmp TABLE_EXISTS_ACTION=replace PARALLEL=3

Full schema
impdp prod/pass DIRECTORY=DUMPS_NAHAR_NEPTUNE DUMPFILE=df01_prod_flexdoc_smaruf_nahar_20101012.dmp TABLE_EXISTS_ACTION=replace PARALLEL=3

2: REMAP_SCHEMA
impdp system/pass DIRECTORY=DUMPS_NAHAR4 DUMPFILE=atiq2_nd_20100907.dmp REMAP_SCHEMA=atiq2:states PARALLEL=3

-- REMAP_TABLE: We can't do it in 10g. This is only available in 11g.

3: CONTENT=DATA_ONLY/
METADATA_ONLY
impdp system/pass DIRECTORY=DUMPS_NAHAR CONTENT=DATA_ONLY DUMPFILE=OLD_DATA_20100705.dmp REMAP_SCHEMA=PROD7:NAHAR PARALLEL=3

4: Import on a fresh a schema
impdp states/pass DIRECTORY=DUMPS_NAHAR_NEPTUNE SCHEMAS=states DUMPFILE=states_dump_20100919.dmp PARALLEL=3

--wrong
expdp prod/pass DIRECTORY=DUMPS_TERMINUS_PROD_20100708 SCHEMAS=PROD DUMPFILE=DUMPS_TERMINUS_PROD_20100708.dmp logfile=DUMPS_TERMINUS_PROD_20100708_LOG_20100308.log

--If I wanted to take dump from different directory then I should use like:
DUMPFILE=datadir1:schema1%U.dmp,datadir2:schema2%U.dmp

How to zip & unzip
zip: nahar@mf01:~$ gzip df01_prod7_flexdoc_smaruf_nahar_201001012.dmp
zip: nahar@mf01:~$ gunzip df01_prod7_flexdoc_smaruf_nahar_20101012.zip

More:
www.oracle-dba-online.com
http://www.oracle-base.com/articles/10g/OracleDataPump10g.php

Working Example:

I will export dump from Estern's (db server) prod (db user) and will import this dump in juptr's (db server) nahar (db user).

I have to pass following steps-
Directory Creation -> Export the dump file to that directory of Estern -> Copy the dump file to another machine -> Make a directory to that location where I create the dump -> Impdp .dmp file to that directory of juptr


Step-1: I am searching where the space available to export?

oracle@Estern:~$ df -h

I need to make a physical directory-

oracle@Estern:~$ cd /dump
oracle@Estern:/dump$ mkdir dumps_nahar_20091015

Step-2: Create Directory

oracle@Estern:~$ sqlplus
Enter user-name: s as sysdba

SQL> Create or replace directory
dumps_nahar As '/dump/dumps_nahar_20091015';

Testing the view is really created or not-
SQL> select OWNER,DIRECTORY_NAME,DIRECTORY_PATH from DBA_DIRECTORIES where DIRECTORY_NAME like '%NAHAR%';

SQL> grant read,write on directory dumps_nahar to prod;

Step-3: Taking the Dump or Export the Dump

expdp prod/password DIRECTORY=dumps_nahar SCHEMAS=prd7 DUMPFILE=nahar_from_Estern_20091015_%U.dmp

Step-4: copy dump from Estern to Jupiter

Now I am coping the dump file from Estern to Juptr's /backup1/dumps_nahar_20091015 location.

bash-3.00$ scp nahar_from_Estern_20091015_01.dmp oracle@juptr:/backup1/dumps_nahar_20091015

--Export from Estern and Copy the dump in juptr done.
--Now I will Import the dump in Juptr's nahar user.

oracle@juptr:~$ sqlplus s as sysdba
Step-5: Want to import the dump at nahar user

If nahar does not exists-
SQL> create user nahar identified by nahar
default tablespace users quota unlimited on users;

SQL> grant dba to nahar;

Step-6: Create Directory where the dump I copied

SQL> Create or replace directory
dumps_nahar As '/backup1/dumps_nahar_20091015';

Testing the view is really created or not-
SQL> select OWNER,DIRECTORY_NAME,DIRECTORY_PATH from DBA_DIRECTORIES where DIRECTORY_NAME like '%NAHAR%';

SQL> grant read,write on directory dumps_nahar to nahar;

Step-7: Import the dump

impdp system/password DIRECTORY=dumps_nahar SCHEMAS=prd7 DUMPFILE=nahar_from_Estern_20091015_01.dmp REMAP_SCHEMA=prd7:nahar PARALLEL=3

11.02.2009

Database Status

How large is the database?

col "Database Size" format a20
col "Free space" format a20
col "Used space" format a20


select round(sum(used.bytes) / 1024 / 1024 / 1024 ) || ' GB' "Database Size"
, round(sum(used.bytes) / 1024 / 1024 / 1024 ) -
round(free.p / 1024 / 1024 / 1024) || ' GB' "Used space"
, round(free.p / 1024 / 1024 / 1024) || ' GB' "Free space"
from (select bytes
from v$datafile
union all
select bytes
from v$tempfile
union all
select bytes
from v$log) used
, (select sum(bytes) as p
from dba_free_space) free
group by free.p;

Database Size: 436 GB
Used space: 355 GB
Free space: 81 GB


How many Table's under "Nahar" user?

select count(*) from dba_objects do where do.owner = 'NAHAR'
and lower(object_type)=lower('Table');

Total tables: 490

10.28.2009

Pinter Setting

Suppose,
My printer IP: 192.168.4.101
Queue Name: PS-FL1-U
Manufacturer/Model: HP/LaserJet 1020

Now, I have to follows the steps:

The following steps are for debian users. This should work on ubuntu too.
Other linux distribution/OS users please see corresponding cups documentation.

* As root issue the following command
apt-get install cupsys foomatic-db foomatic-filters-ppds
* Fire up your browser and go http://localhost:631
* Click "Administration"
* Click "Add printer"
* Give a name e.g ."HP". The rest two are optional. Click "Continue"
* Choose "LPD/LPR Host or Printer"
* Put "lpd://printer-ip-address/queue-name" from above table like "lpd://192.168.1.213/PS-FL2-U"
* Select "HP"
* Choose "HP LaserJet 1010 Foomatic/hpijs (en)"
* Click "Add Printer"
* You are done.
* Don't give "Test page" print.
* Print the first page of your document you want to print to test whether the setup is successful.

OEM Basic

I have created a new user USER1. I want to connect OEM for this user. So -
grant connect, resource to user1;
grant select_catalog_role to user1;

To create a new DBControl repository:

emca -config dbcontrol db -repos create

To start a DB Console:
emctl start dbconsole

Managing the agent:
oracle@terminus ~$ set ORACLE_SID=sid
oracle@terminus ~$ echo $ORACLE_SID
THRP
oracle@terminus ~$ emctl stop agent
Stopping Oracle Enterprise Manager 10g Database Control Stopped.
Agent is not running.

oracle@terminus ~$ emctl start agent
Starting agent .... started.
oracle@terminus ~$ emctl start dbconsole
oracle@terminus ~$ emctl status agent

Agent is Running and Ready

When error:
emca -config dbcontrol db -repos recreate


Oracle Enterprise Manager (OEM) is a set of systems management tools provided by Oracle Corporation for managing the Oracle environment and automate tasks.

Database control: OEM application for managing a single Oracle Database.

Grid control: OEM's web based interface for centrally managing all your Oracle environments from a single point.

Implementation: OEM creates a SYSMAN schema in the Oracle DB to store metadata and statistics. SYSMAN also acts as the super-administrator account for first-time login. The default password for SYSMAN is oem_temp.

10.22.2009

ORA-00600

ORA-00600: internal error code, arguments: [kkoljt1], [], [], [], []


I was getting this ERROR by running a query in saturn.
I was also running the same query in terminus, but there was no error.

Then I checked in both server:

1. select banner from v$version;

Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
PL/SQL Release 10.2.0.3.0 - Production
CORE 10.2.0.3.0 Production
TNS for Solaris: Version 10.2.0.3.0 - Production
NLSRTL Version 10.2.0.3.0 - Production


Both was same.

2. show parameter optimizer

@saturn:
optimizer_features_enable string 10.2.0.3

@terminus:
optimizer_features_enable string 10.2.0.2

Then @saturn I run -
alter system set optimizer_features_enable='10.2.0.2';

And, the problem solved. :)

10.19.2009

Tablespaces

CREATE:
CREATE
SMALLFILE TABLESPACE "TEST_NAHAR"
DATAFILE '/oracle/oradata/TEST_NAHAR_01.dbf'
SIZE 10M
REUSE LOGGING
EXTENT MANAGEMENT LOCAL
UNIFORM SIZE 1024K
SEGMENT SPACE MANAGEMENT AUTO;

Syntax-2:

DROP TABLESPACE "DATA02" INCLUDING CONTENTS AND DATAFILES CASCADE CONSTRAINTS;

CREATE TABLESPACE "TS_DATA02"
DATAFILE '/oradata/datafiles/THRP/DF_DATA02.dbf'
SIZE 1G
AUTOEXTEND ON
NEXT 50M
MAXSIZE 30G
BLOCKSIZE 8K;


Syntax-3:
CREATE TABLESPACE "DATA02"
DATAFILE '/oracle/oradata/JUPITER/DATA02_01.dbf'
SIZE 100M
BLOCKSIZE 8K;



DROP:
DROP TABLESPACE TEST_NAHAR
INCLUDING CONTENTS AND DATAFILES CASCADE CONSTRAINTS;

ALTER:

SQL> ALTER TABLESPACE users OFFLINE;
SQL> ALTER TABLESPACE users ONLINE;

DBA_TABLESPACES Details:

If I set
REUSE LOGGING, then LOGGING=LOGGING will set.
If I set BLOCKSIZE 8K, then BLOCKSIZE=8192 will set.
If I set BLOCKSIZE 16K, then BLOCKSIZE=16384 will set.

Default Settings:
LOGGING=LOGGING
EXTENT MANAGEMENT = LOCAL
SEGMENT_SPACE_MANAGEMENT=AUTO

DBA_DATA_FILES Details:
BYTES=10485760 =>SIZE 10M (10*1024*1024)

Q: Which Tablespace contains which datafile?
select t.tablespace_name, d.file_name, t.segment_space_management, t.block_size, t.bigfile
from DBA_TABLESPACES t,DBA_DATA_FILES d
where t.tablespace_name=d.tablespace_name
order by t.tablespace_name;

Or simply,
select d.tablespace_name,d.file_name
from DBA_DATA_FILES d
order by d.tablespace_name;

Q: How to Check OBJECT on Tablespace?
select owner, segment_name, segment_type, tablespace_name
from dba_segments
where lower(segment_name) like lower('%SYS_LOB0000151343C00022%')
order by owner, segment_name;

Q: How to Check all OBJECTs of a Tablespace?
select owner, segment_name, segment_type, tablespace_name
from dba_segments
where lower(tablespace_name) like lower('%DATA02%')
order by owner, segment_name;

10.08.2009

Working with Vi

Positioning the Cursor:

® Move cursor one space right.
¬ Move cursor one space left.
­ Move cursor up one line.
¯ Move cursor down one line.

ctrl-F Move forward one screen.
ctrl-B Move backward one screen.

$ Move cursor to end of line.
^ Move cursor to beginning of line.
:1 Move to first line of file
:$ Move to last line of file
/ Search for a character string.
? Reverse search for a character string.
x Delete the character at the cursor position.
dd Delete the current line.
p Paste data that was cut with x or dd commands.
u Undo.


Entering Input Mode:
a Add text after the cursor.
i Insert text before the cursor.
R Replace text starting at the cursor.
o Insert a new line after the current one.


Entering Command Mode:
esc Switch from Input mode to Command mode.


Exiting or Saving Your File:
:w Write file to disk, without exiting editor.
ZZ Save the file and exit.
:q! Quit without saving.

10.05.2009

Hints

Why using hints?
Oracle comes with an optimizer that promises to optimize a query's execution plan.
When this optimizer is really doing a good job, no hints should be required at all.

Sometimes, however, the characteristics of the data in the database are changing rapidly, so that the optimizer (or more accuratly, its statistics) are out of date. In this case, a hint could help.
It must also be noted, that Oracle allows to lock the statistics when they look ideal which should make the hints meaningless again.

All hints except /*+ rule */


Example:

SELECT /*+ index(t1 t1_abc) index(t2 t2_abc) */ COUNT(*)
FROM t1, t2
WHERE t1.col
1 = t2.col1;


FIRST_ROWS(n):
The FIRST_ROWS hint explicitly chooses the cost-based approach to optimize a statement block with a goal of best response time (minimum resource usage to return first row).

set autotrace trace exp

SELECT table_name FROM dba_tables
WHERE owner = 'SYS' AND table_name LIKE '%$' ORDER BY 1;

SELECT
/*+ FIRST_ROWS(10) */ table_name
FROM dba_tables WHERE owner = 'SYS'
AND table_name LIKE '%$' ORDER BY 1;

Access Method INDEX:

CREATE INDEX ix_customers_gender
ON customers(gender);

set autotrace traceonly explain

SELECT * FROM customers WHERE gender = 'M';

SELECT /*+ INDEX(customers ix_customers_gender) */ *
FROM customers WHERE gender = 'M';

SELECT
/*+ INDEX_ASC(customers ix_customers_gender) */ *
FROM customers WHERE gender = 'M';

SELECT
/*+ INDEX_DESC(customers ix_customers_gender) */ *
FROM customers WHERE gender = 'M';

We can use First row and Index Together:

/*+FIRST_ROWS(20) INDEX(table_alias index_name) */

Links:

http://psoug.org/reference/hints.html
http://www.adp-gmbh.ch/ora/sql/hints/index.html







9.27.2009

Partition Index rebuild - PL/SQL

DECLARE
tab_name VARCHAR2(30);
stmt VARCHAR2(500);
sqlstr VARCHAR2(800);
TYPE TabCurTyp IS REF CURSOR;
ind_cursor TabCurTyp;
indx_name VARCHAR2(35);
part_name VARCHAR2(35);

BEGIN
tab_name := UPPER('&tab_name');
sqlstr:='SELECT distinct uip.index_name, uip.partition_name
FROM USER_IND_PARTITIONS uip, USER_TAB_PARTITIONS utp, USER_INDEXES ui
WHERE uip.partition_name= utp.partition_name
AND ui.index_name = uip.index_name
AND ui.table_name = utp.table_name
AND utp.table_name LIKE '''||tab_name||'%''';

OPEN ind_cursor FOR sqlstr;
LOOP
FETCH ind_cursor INTO indx_name,part_name;
EXIT WHEN ind_cursor%NOTFOUND;
stmt := 'ALTER INDEX ' || indx_name || ' REBUILD PARTITION ' ||part_name ||' ONLINE';
DBMS_OUTPUT.PUT_LINE(stmt);
EXECUTE IMMEDIATE stmt;
END LOOP;
END;
/


Here you only have to put the table name.
Office work- 10 September, 2009.

Single Syntax:

ALTER INDEX index_nm REBUILD PARTITION partition_name;