A Oracle DBA's BLOG

Welcome to my ORACLE DBA blog. You will be Amazing!!!

Wednesday, November 7, 2012

Oracle Rename User

This article present easy way to change/rename User name and password.

Select FOR your users

SQL> select user#,name from user$;
Update user name
SQL>update user$ set name=’TESTUSER’ where name=’VEYSI’;
SQL>commit;
Close your database
SQL>shutdown immediate;
SQL>startup;

SQL> alter user TESTUSER identified by TESTUSER;

Oracle rename data file tips

This article present easy way to change/rename datafile_name or Tablespace name_name.
First select your dba_datafile_name and choose a file for renaming.
SQL> SELECT FILE_NAME FROM DBA_DATA_FILES;
 
FILE_NAME
--------------------------------------------------------------------------------
/u01/app/oracle/oradata/orcl/users01.dbf
/u01/app/oracle/oradata/orcl/undotbs01.dbf
/u01/app/oracle/oradata/orcl/sysaux01.dbf
/u01/app/oracle/oradata/orcl/system01.dbf
/u01/app/oracle/oradata/orcl/test01.dbf
 

Now close your database;

 
SQL>shutdown immediate;
Now change the name of file
linux> mv /u01/app/oracle/oradata/orcl/test01.dbf ' '/u01/app/oracle/oradata/orcl/veysi01.dbf


Mount your database


SQL> Startup  mount;


Rename datafile


SQL>ALTER DATABASE   
RENAME file      
   '/u01/app/oracle/oradata/orcl/test01.dbf' 
TO 
   '/u01/app/oracle/oradata/veysi01.dbf'

sql>alter database open;

Renaming Tablespace

ALTER TABLESPACE TEST RENAME TO INTERBASE;


Saturday, August 25, 2012

Travelling America USA

At my second degree i decided to go to USA summer vacation, Actually as a student it was a little difficulty Finally i got Visa and My first airport station  was Parish and i was More excited in there i just felt like I'm flying with plane :) At last i saw my self at America, i got many experiences there and a lot of pictures.

New york Time square

New Orleans Jazz Festival

Washington DC


BROOKLYN BRIDGE


From Empire City New york

Looking New york From top on empire city

Niagara Falls


Apple Store internview with Steve Jobs :)

I met with Iroman :) 


Tuesday, June 5, 2012

Create Oracle database listener Using Netca and manually

This article presents creating a simple Oracle Listener service. DBA's can create Listener manually however Oracle Net Configuration Assistant provide us simple way.


First Method Manually Create the listener

Manually create the listener.ora file and start the listener from command line.


LISTENER_TEST =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST =orcl.localdomain )(PORT = 1522))
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1522))
    )
  )
 
ADR_BASE_LISTENER_ORACLEDB1 = /u01/app/oracle
 


[oracle@orcl admin]$ lsnrctl stop LISTENER_TEST
[oracle@orcl admin]$ lsnrctl status LISTENER_TEST



 Second method Start the Oracle Net Configuration Assistant (NETCA)


Choose Listener configuration And Click Next


 Here Add (to add new listener) Reconfigure(exist listener), delete(exist) Rename(exist).
Choose Add And click next


So, Give new listener Name  For example Listener_test

The important thing you must Select TCP here. Click next

The exist port is 1521 however user for different listener different port for example 1522 

 Asking for another listener to configure Choose No and click Next

Choose new listener to be started and click next


Almost its done! Click next


Click Finish
After all you we'll see the script of new listener.


AS You see there are two listener script my first and second listener.
Have a nice job! :)

Tuesday, May 1, 2012

Manual Oracle database creation Script

Today i will show how create a database Oracle syntax manually . We know that during installation oracle database is created Auto. Also we can create it by DBCA command auto however its good to know creating by your hand J


Before you create the database make sure you have done the planning about the size of the database, number of tablespaces and redo log files you want in the database.


Select the standard database block size.

Lets Begin...
First Change Instance name Export Oracle SID
export ORACLE_HOME=/path/to/oracle/home
oracle@... > export ORACLE_SID=test_orcl
Check it
oracle@...> echo $ORACLE_HOME
Create a init.ora
# $ORACLE_HOME/dbs/init<sid>.ora

control_files = (/path/to/control1.ctl,/path/to/control2.ctl,/path/to/control3.ctl)
undo_management = AUTO
undo_tablespace = UNDOTBS1
db_name = test
db_block_size = 8192
sga_max_size = 1073741824 #one gig
sga_target = 1073741824 #one gig

u01/app/oracle/product/11.2.0/dbhome_1/dbs/init_test.ora
and set init.ora make sure that
DB_NAME=test_orcl

(remember the parameter file name should of the format init<sid>.ora and it should be in ORACLE_HOME/dbs  directory)
3.  Create a password file

$ORACLE_HOME/bin/orapwd file=$ORACLE_HOME/dbs/pwd<sid>.ora password=oracle entries=5

Start the instance

sqlplus / as sysdba
startup nomount
 Create the database
 SQL> create database Test_orcl

logfile group 1 ('/u01/app/oracle/oradata/redo1.log') size 50M,
            group 2 ('/u01/app/oracle/oradata/redo2.log') size 50M,
            group 3 ('/u01/app/oracle/oradata /redo3.log') size 50M

character set WE8ISO8859P1

national character set utf8

datafile '/u01/ app/oracle/oradata/system.dbf' size 500M

autoextend on next 10M maxsize unlimited extent management local

sysaux datafile '/u01/app/oracle/oradata/sysaux.dbf' size 100M autoextend on

next 10M maxsize unlimited

undo tablespace undotbs1 datafile '/u01/app/oracle/oradata /undotbs1.dbf' size 100M
default temporary tablespace temp tempfile '/u01/app/oracle/oradata /temp01.dbf' size 100M;
SQL> CREATE TABLESPACE users DATAFILE ‘/u01/app/oracle/oradata/deneme/users01.dbf’ SIZE 25M AUTOEXTEND ON NEXT 1280K MAXSIZE UNLIMITED EXTENT MANAGEMENT LOCAL;
Run catalog and catproc 
@?/rdbms/admin/catalog.sql
@?/rdbms/admin/catproc.sql
 
Change passwords
alter user sys identified by sys_password;
alter user system identified by sys_password;

SQL> alter database mount;
SQL> alter database open;
SQL> select instance_name,version,status,database_status from v$instance;

INSTANCE_NAME   VERSION       STATUS         DATABASE_STATUS
—————-            —————–    ————           —————–
test_orcl                    11.2.0.1.0          STARTED          ACTIVE



Saturday, April 7, 2012

TNS Listener Configuration for Oracle

Today I will mention Oracle Listener and prepare for database.
Listener is provide connection between databases at different location.

Generally standard Listener port is 1521.
Scenario:
When Oracle installed Listener_name is Listener and port is 1521. If more databases are located on the same machine then using different listener and port more beneficial.
At this Scenario I’ll use Listener_name: My_Listener and port:1525

    1.   Preparation Database
At first we are going to look default configuration status when database is up.  For this we must create
init.ora from spfile (server parameter file or binary parameter
file)

SQL> create pfile='/tmp/test_pfile.ora' from spfile;

Open the “test_pfile” and save the following command
 *.local_listener='MY_LISTENER'
SHUTDOWN IMMEDIATE the database.

We have to make this test_pfile as Oracle Spfile in order to Up database.

SQL> create spfile from pfile='/tmp/test_pfile.ora';


   2.   Preparation LISTENER.ORA

Now we have to change listener.ora file.
When you open Listener.ora you will see the default setting change like following
MY_LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
(ADDRESS = (PROTOCOL = TCP)(HOST = machine_name)(PORT = 1525))
)
)

Here write the machine_name and change port number..

After the setting Listener would be changed like following.:

Thursday, April 5, 2012

Oracle Linux useful Command

Today i will show how to use Linux commands And Useful for Oracle DBA.

man
To show command knowledge

man(manual):

 To show contents
ls(list):
 To show hiding contents
ls -a :
 To show one under the other
ls -l :
 To show size and more information's
ls -lh :
 To show last update
ls -lrt : 
Cd
 To go other folder
cd :

/ : Linux above folder
To go above folder
Cd .. :

pwd
 To show own folder
pwd :

To create folder

mkdir

 To delete folder
rm

rm :
 to delete all
rm -R :


rmdir
 To delete empty folder
rmdir :

TO COPY FOLDER 
cp
 To move Folder 
mv
  
To show file or text 
cat | more
  
To Gzip Folder 
gzip
  
TO GUNZIP FOLDER 
gunzip

 To find folder
find

TO GIVE ALIAS 
Alias

 alias Nick_name=”<command >”  


mounting disk:

1- create a folder where to mounted.
mkdir /media/newdisk
mkdir /DATA


if we want to mount with FAT32:
mount -t vfat -o umask=ooo /dev/hdb1 /media/newdisk

if we want to mount with NTFS
mount -t ntfs -o umask=0222 /dev/hdb1 /media/newdisk

if we want to mount  CDROM:
mount -t iso_name -r /dev/cdrom /media/cdrom


if we want to mount with  OCFS2:
mount -t ocfs2 -o noatime,_netdev,datavolume,nointr /dev/emcpowera1 /DATA


if we want to mount with  EXT3:
mount -t ext3 /dev/sdb1 /software


unmounting disk:

umount -l /dev/sdb1
umount /DATA


Partitioning

fdisk /dev/sdb


Formatting


if we want to format with EXT3:
mkfs -t ext3 /dev/sdb1
if we want to format with  OCFS2:
mkfs.ocfs2 -b 4K -C 128K -N 5 -L /DATA /dev/emcpowera1

FILE SYSTEM CHECK

fsck.ocfs2 -n /dev/sdf2
fsck.ocfs2 -y /dev/sdf2 –>repair
List drives

df -h


tmpfs increase

mount -t tmpfs shmfs -o size=3g /dev/shm


Getting user id

id username
id oracle


Set user folder

chown -R oracle:dba /oracle

Change folder permission


chmod 775 file_name


Checking installed “rpm” packages

rpm -qa | grep “package name”


Rpm download 

rpm -ivh package

Rpm update


rpm -Uvh package


Rpm Delete

rpm -e package


Checking Oracle installing requires packages 
—————————————————————————————————————-

rpm -q binutils compat-db compat-libstdc++-33 libgcc glibc glibc-devel glibc-headers gcc gcc-c++ libgcc libstdc++ cpp make libaio ksh elfutils-libelf make sysstat libaio libaio-devel setarch libXp unixODBC –qf “%{NAME}-%{VERSION}-%{RELEASE} (%{ARCH})\n”|sort

Date of rpm

rpm -qa –last | more

CPIO extract


cat cpio_file | cpio -idmv

Create MD5 In order To copy or move validate folder


md5sum file > file.md5


Checking moved MD5 

md5sum -c file.md5

Folder transfer between servers


scp 192.168.192.168:oracle/veysi.pw /

 scp /oracle/full.dmp ora11g@192.168.192.166:/export #copy folder

Search folder

grep -ins 192.168.192.168(Text) -A2 -B1 list1.log


Get Process value

ps -ef |grep veysi|wc


Change Date

date -s “21 MAR 2010 02:04:00″


SEMAPHORE

ipcs -s
ipcrm

Trace OS process


strace -p pid


List Tar zip 

tar -tf java_patch.tar


Add a file or folder to Tar zip 

tar -rf java_patch.tar jre


Create Tar zip 

tar -cf java_patch.tar jdk


Change user ID 

usermod -u UID user


Delete folder after killed process 

echo “”>veysi_ora_7001.trc

Give easy path to folder


ln -s path kısayol_adı


Show status SELinux 

sestatus


To show version of download rmp package

echo ocfs2-`uname -r`


i/o static list

iostat 3


checking RAC node date: 

ssh rac1 date; ssh rac2 date; date


without using root password to get information

/etc/SUDOERS
ora11g localhost=NOPASSWD:/bin/mount,/bin/umount
ora11g talipdb=NOPASSWD:/bin/mount,/bin/umount


Last log in 

last | more


Send file to Via E-mail

mail -s “file_name” muh.veysi.47@hotmail.com < sqlnet.log


Finding word in folder

grep -ins word *

To kill more process using process_name


ps -ef |grep “process_name” |awk ‘{print ” kill -9 ” $2}’>/tmp/kill.sh


To watch process_name every 3 second

watch -n 2 “ps -ef | grep process_name | grep -v ps”


Open Log file
tail -f /var/log/messages


Thursday, March 29, 2012

Oracle Enterprise Manager (OEM) 11g Start/Stop

Starting and Stopping the Oracle Enterprise Manager (OEM)

 Oracle Enterprise Management is Web-Based tool to manage Oracle Database.OEM using for perform administrative task abd view performance statistics. 


How to use Database Control
a) ORACLE_HOME/bin/emctl start dbconsole  [To start DB Control]
b) ORACLE_HOME/bin/emctl status dbconsole [To check status of DB Control]
c) ORACLE_HOME/bin/emctl stop dbconsole   [To stop DB Control]

If you didnt install OEM through installation Oracle Database 11g Then You need downloand OEL and installa it by your self.
So,i will write a article about that next days.
In this article i will take part of starting and stoping options of OEM.

Firstly we have to go OEM directory $ORACLE_HOME/bin/ 

Status OEM
[oracle@orcl bin]$ emctl status dbconsole
Oracle Enterprise Manager 11g Database Control Release 11.2.0.1.0
Copyright (c) 1996, 2009 Oracle Corporation.  All rights reserved.
https://orcl.localdomain:1158/em/console/aboutApplication
Oracle Enterprise Manager 11g is not running.
------------------------------------------------------------------
Logs are generated in directory /u01/app/oracle/product/11.2.0/db_1/orcl.localdomain_orcl/sysman/log
Starting OEM
emctl start dbconsole;
Oracle Enterprise Manager 11g Database Control Release 11.2.0.1.0
Copyright (c) 1996, 2009 Oracle Corporation.  All rights reserved.
https://orcl.localdomain:1158/em/console/aboutApplication
Starting Oracle Enterprise Manager 11g Database Control............ started.
------------------------------------------------------------------
Logs are generated in directory /u01/app/oracle/product/11.2.0/db_1/orcl.localdomain_orcl/sysman/log
Stoping OEM
emctl stop dbconsole
Oracle Enterprise Manager 11g Database Control Release 11.2.0.1.0
Copyright (c) 1996, 2009 Oracle Corporation.  All rights reserved.
https://orcl.localdomain:1158/em/console/aboutApplication
Stopping Oracle Enterprise Manager 11g Database Control ...
 ...  Stopped.




Thursday, March 8, 2012

Installing RLWRAP command on linux

In this article we shell see how to install Rlwrap(read line wrapper) which very useful program on Linux and use it.
So, all you need download Rlwrap.tar.gz from this site and complete it.
1) Download Rlwrap/

Or if you are on ubuntu OS use: sudo apt-get install rlwrap

2)
[oracle@orcl tmp]$   tar -xvf rlwrap-0.37.tar
rlwrap-0.37/
rlwrap-0.37/completions/
rlwrap-0.37/completions/testclient
rlwrap-0.37/completions/coqtop
rlwrap-0.37/doc/
rlwrap-0.37/doc/rlwrap.man.in
rlwrap-0.37/doc/Makefile.am

3) Now trun to root user and configure Rlwrap
[oracle@orcl rlwrap-0.37]$./configure
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make sets $(MAKE)... (cached) yes
checking whether build environment is sane... yes.................................................................................................................................................................................

Now do:
    make (or gmake)  to build rlwrap
    make check       for instructions how to test it
    make install     to install it
4) Now we have to use make
# make
# make check
# make install
5) this step i'll set bash_profile in order to use rlwrap
[oracle@orcl ]$ vi .bash_profile

alias sql='rlwrap sqlplus'
alias dgmgrl='rlwrap dgmgrl'
alias rman='rlwrap rman'
alias lsnrctl='rlwrap lsnrctl'
alias asmcmd='rlwrap asmcmd'
alias adrci='rlwrap adrci'
alias impdp='rlwrap impdp'
alias expdp='rlwrap expdp'
And set it [oracle@orcl ]$. .bash_profile

Now you can use the alias for easy way :) 

I think, DBAs Love that rlwrap :)







Thursday, March 1, 2012

Startup And Shutdown Oracle Database Options

STARTUP ve SHUTDOWN

Before making Oracle Database available for any valid user, you must start up a database,
So startup have 3 mode 

1.NoMount mode,
2.Mount mode,
3.Open mode

Startup
When startup command is issued. Oracle looks for the parameter file in following order. SGA+BACKGROUND PROCESS Spifie<SID>.ora, init<SID>.ora

If we want to know the database on which instance. 
 " select open_mode from v$database " Using this command.

[oracle@orcl ~]$ su - oracle

[oracle@orcl ~]$ env | grep ORA
ORACLE_SID=ORCL
ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1
You can connect using either “/ as sysdba” or an oracle account that has DBA privilege.


[oracle@orcl ~]$ sqlplus '/ as sysdba'
SQL*Plus: Release 11.2.0.1.0 - Production on Sun Feb 20 10:40:28 2012
Copyright (c) 1982, 2009, Oracle.  All Rights Reserved.
Connected to an idle instance.
SQL>


 

SQL>startup; --> At first the database will go on "NOMOUNT" mode.
Then will go 
            MOUNT and at the final mode will be OPEN




NOMOUNT MODE: Oracle is reading paramater files (INITORA, SPFILE). 

It allocating memory(SGA), Starting backgraound processes. 

We can use "STARTUP QUIET"command in order to pass this option.
 SQL> startup nomount;
ORACLE instance started.

Total System Global Area  276197376 bytes
Fixed Size                  1335980 bytes
Variable Size             171969876 bytes
Database Buffers           96468992 bytes
Redo Buffers                6422528 bytes


MOUNT MODE: .The most important this is Oracle is reading Control files whichs instance mounted. Oracle check datafile and Log files. If there were any corruptions Oracle wont be open.

 ALTER DATABASE MOUNT; This command can be used when database is in nomount.



Database altered.
SQL> ALTER DATABASE OPEN; This comman can be used when database is in mounted. it will check datafiles and redolog files.


Database altered.
1) STARTUP [MOUNT/NOMOUNT/OPEN] RESTRICT; --> This comman is using for priviled User except this user others cant be connected in this mode How ever if any user have RESTRICTED SESSION role then its not up on that user.
SQL> ALTER SYSTEM  ENABLE RESTRICTED SESSION; For valid Restrict mode
SQL> ALTER SYSTEM  DISABLE RESTRICTED SESSION; For unvalid Restrict mode

select logins from v$instance; This select will show us the instance mode.


SQL> ALTER SYSTEM QUIESCE RESTRICTED; This command will wait until the active user 
finish trunsactions.
SQL> ALTER SYSTEM UNQUIESCE; 
SQL> select active_state from v$instance;

2) STARTUP [MOUNT/NOMOUNT/OPEN] FORCE; --> Database will be "SHUTDOWN ABORT" and then Opened again.
3) STARTUP [MOUNT/NOMOUNT/OPEN] EXCLUSIVE; -->This command will functionally identical to Above.


SHUTDOWN


1) SHUTDOWN [NORMAL]; --> The database waits for all users to disconnect, 
Oracle waits for all users to exit their sessions before shutting down the database
Oracle closes the data files and terminates the background processes. Oracle’s SGA is deallocated.
SQL> shutdown
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>
2) SHUTDOWN IMMEDIATE; --> Oracle immediately disconnects all users. Oracle terminates all currently executing transactions.Oracle terminates the background processes and deallocates memory. No instance recovery is required on startup.
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL>
3) SHUTDOWN ABORT; --> Oracle doesn’t roll back the terminated transactions. Oracle doesn’t write the redo log buffers and data buffers to disk.This doesn’t wait for anything. 

SQL> shutdown abort
ORACLE instance shut down.
SQL>