mercredi 11 janvier 2012

rlwrap : Command History and Auto-Completion for SQL*Plus on Unix/Linux


see http://www.idevelopment.info/data/Oracle/DBA_tips/SQL_PLUS/SQLPLUS_8.shtml
or see http://matthieucornillon.fr/2011/05/rlwrap-pour-sqlplus-auto-completion-historique-etc/

Oracle 11g: automatic startup/shutdown

To configure an instance for automatic startup and shutdown, edit the "/etc/oratab" file and for each instance define the following line :
SID:<value_of_the_oracle_home>:[Y|N]
For exemple, to register for automatic startup the DB11G instance :
DB11G:/opt/oracle/11.2.0:Y
Next, create a file called "/etc/init.d/dbora" as the root user, containing the following :
#!/bin/sh
# chkconfig: 345 99 10
# description: Oracle auto start-stop script.
#
ORACLE_HOME=/opt/oracle/11.2.0
ORACLE_OWNER=oracle

if [ ! -f $ORACLE_HOME/bin/dbstart ]
then
    echo "Oracle startup: cannot start"
    exit
fi

case "$1" in
    'start')
        # Start the Oracle databases:
        # The following command assumes that the oracle login 
        # will not prompt the user for any values
        su - $ORACLE_OWNER -c "$ORACLE_HOME/bin/lsnrctl start"
        su - $ORACLE_OWNER -c $ORACLE_HOME/bin/dbstart
        touch /var/lock/subsys/dbora
        ;;
    'stop')
        # Stop the Oracle databases:
        # The following command assumes that the oracle login 
        # will not prompt the user for any values
        su - $ORACLE_OWNER -c $ORACLE_HOME/bin/dbshut
        su - $ORACLE_OWNER -c "$ORACLE_HOME/bin/lsnrctl stop"
        rm -f /var/lock/subsys/dbora
        ;;
esac
Set the dbora file in the dba group :
$> chgrp dba dbora
Use the chmod command to set the privileges to 750:
$> chmod 750 /etc/init.d/dbora
Associate the dbora service with the appropriate run levels and set it to auto-start using the following command:
$> chkconfig --add dbora

links :
For Oracle 10.2 see http://docs.oracle.com/cd/B19306_01/server.102/b15658/strt_stp.htm#CFAHAHGA
For Oracle 11.2 see http://docs.oracle.com/cd/E11882_01/server.112/e10839/strt_stp.htm#BABGDGHF

Oracle 11g: Exp/imp how to get metadata


The idea is to use exp and imp utilities to extract only DDL in order to duplicate a schema.
To do this, export first the database using exp :
$> export ORACLE_HOME=/opt/oracle/10.2.0
$> export PATH=$PATH:$ORACLE_HOME/bin
$> export ORACLE_SID=MYDB
$> export NLS_LANG=AMERICAN_AMERICA.UTF8
$> exp userid=system file=export.dmp log=export.log owner=<schemaname_to_export> consistent=y

Import the database but specify that metadata will be redirected to a file :
$> imp userid=system file=export.dmp indexfile=metadata.txt fomuser=<schemaname_to_import>