faq on oracle

  • Upload
    jameer

  • View
    218

  • Download
    0

Embed Size (px)

Citation preview

  • 8/7/2019 faq on oracle

    1/9

    Topics

    Why should/shouldn't one run Oracle on Unix?

    What is ORATAB and what is it used for? How does one prepare the Oracle environment?

    How does one get Oracle to automatically start when the server boots up?

    How does one list all installed Oracle products?

    Can one export directly to a tape drive?

    Can one archive directly to tape?

    I don't have enough space to export my database! Any suggestions?

    How does one overcome the Unix 2 Gig file limit?

    What can be done to make export/import run faster?

    How does one SELECT a value from a table into a Unix variable?

    How does one SELECT information into a vi-file?

    How does one automate on-line backups?

    What is the purpose of the sgadef.dbf file? Can one see what patches are applied to Oracle?

    How does one monitor and trace Unix processes?

    How does one write a script to do some work on all DBs?

    Can one prevent passwords from appearing in the system process table?

    Why doesn't Oracle release file space when you drop a tablespace?

    How does one relink the Oracle Server executables?

    What does one do with those core files?

    Can one copy Oracle software from one machine to another?

    What Unix environment variables needs to be set?

    What Unix commands can one use when administrating a database?

    Where can one get more info about Unix and Unix vendors?

    Why should/shouldn't one run Oracle on Unix?

    Unix is one of the most important operating systems in use today, perhaps even the most important. Most of the bigOracle databases are running on Unix and Oracle themselves are developing the RDBMS Server on Unix. Thismight changes as Windows NT and other operating systems matures, but fact remains, if one wants reliability andscalability, do it on Unix!

    What is ORATAB and what is it used for?

    The oratab file is normally located in the /etc or /var/opt/oracle directories. Originally ORATAB was used forSQL*Net V1. It contains comments in Unix-style leading pound signs (#), and data lines consisting of entries in thefollowing format:

    database_sid:oracle_home_dir:Y|N

    where database_sid is the system id (SID) of an Oracle instances on the server. Oracle_home_dir is theORACLE_HOME directory associated with this instance. The Y|N flags indicate if the instance shouldautomatically start at boot time (Y=yes, N=no).Besides acting as a registry for what databases and software versions are installed on the server, ORATAB is alsoused for the following purposes:

    Oracle's "dbstart" and "dbshut" scripts use this file to figure out (using the third field, Y or N) whichinstances are to be start up or shut down.

    The "oraenv" utility uses ORATAB to set the correct environment variables.

    One can also easily write scripts that cycle through multiple instances using the information in the oratabfile.

    http://www.orafaq.com/faqunix.htm#WHYUNIXhttp://www.orafaq.com/faqunix.htm#WHYUNIXhttp://www.orafaq.com/faqunix.htm#ORATABhttp://www.orafaq.com/faqunix.htm#ORATABhttp://www.orafaq.com/faqunix.htm#ORAENVhttp://www.orafaq.com/faqunix.htm#ORAENVhttp://www.orafaq.com/faqunix.htm#STARTUPhttp://www.orafaq.com/faqunix.htm#STARTUPhttp://www.orafaq.com/faqunix.htm#PRDLISThttp://www.orafaq.com/faqunix.htm#PRDLISThttp://www.orafaq.com/faqunix.htm#TAPEEXPORThttp://www.orafaq.com/faqunix.htm#TAPEEXPORThttp://www.orafaq.com/faqunix.htm#ARCHIVEhttp://www.orafaq.com/faqunix.htm#ARCHIVEhttp://www.orafaq.com/faqunix.htm#EXPORThttp://www.orafaq.com/faqunix.htm#EXPORThttp://www.orafaq.com/faqunix.htm#FSLIMIThttp://www.orafaq.com/faqunix.htm#FSLIMIThttp://www.orafaq.com/faqunix.htm#FASTEXPhttp://www.orafaq.com/faqunix.htm#FASTEXPhttp://www.orafaq.com/faqunix.htm#UNIXVARhttp://www.orafaq.com/faqunix.htm#UNIXVARhttp://www.orafaq.com/faqunix.htm#SELECTVIhttp://www.orafaq.com/faqunix.htm#SELECTVIhttp://www.orafaq.com/faqunix.htm#AUTBACKUPhttp://www.orafaq.com/faqunix.htm#AUTBACKUPhttp://www.orafaq.com/faqunix.htm#SGADEFhttp://www.orafaq.com/faqunix.htm#SGADEFhttp://www.orafaq.com/faqunix.htm#PATCHhttp://www.orafaq.com/faqunix.htm#PATCHhttp://www.orafaq.com/faqunix.htm#TRACEhttp://www.orafaq.com/faqunix.htm#TRACEhttp://www.orafaq.com/faqunix.htm#ALLDBShttp://www.orafaq.com/faqunix.htm#ALLDBShttp://www.orafaq.com/faqunix.htm#HIDEPSWhttp://www.orafaq.com/faqunix.htm#HIDEPSWhttp://www.orafaq.com/faqunix.htm#FILEFREEhttp://www.orafaq.com/faqunix.htm#FILEFREEhttp://www.orafaq.com/faqunix.htm#RELINKhttp://www.orafaq.com/faqunix.htm#RELINKhttp://www.orafaq.com/faqunix.htm#COREhttp://www.orafaq.com/faqunix.htm#COREhttp://www.orafaq.com/faqunix.htm#SOFTWAREhttp://www.orafaq.com/faqunix.htm#SOFTWAREhttp://www.orafaq.com/faqunix.htm#ENVVARShttp://www.orafaq.com/faqunix.htm#ENVVARShttp://www.orafaq.com/faqunix.htm#COMMNDShttp://www.orafaq.com/faqunix.htm#COMMNDShttp://www.orafaq.com/faqunix.htm#WHEREhttp://www.orafaq.com/faqunix.htm#WHEREhttp://www.orafaq.com/faqunix.htm#WHYUNIXhttp://www.orafaq.com/faqunix.htm#ORATABhttp://www.orafaq.com/faqunix.htm#ORAENVhttp://www.orafaq.com/faqunix.htm#STARTUPhttp://www.orafaq.com/faqunix.htm#PRDLISThttp://www.orafaq.com/faqunix.htm#TAPEEXPORThttp://www.orafaq.com/faqunix.htm#ARCHIVEhttp://www.orafaq.com/faqunix.htm#EXPORThttp://www.orafaq.com/faqunix.htm#FSLIMIThttp://www.orafaq.com/faqunix.htm#FASTEXPhttp://www.orafaq.com/faqunix.htm#UNIXVARhttp://www.orafaq.com/faqunix.htm#SELECTVIhttp://www.orafaq.com/faqunix.htm#AUTBACKUPhttp://www.orafaq.com/faqunix.htm#SGADEFhttp://www.orafaq.com/faqunix.htm#PATCHhttp://www.orafaq.com/faqunix.htm#TRACEhttp://www.orafaq.com/faqunix.htm#ALLDBShttp://www.orafaq.com/faqunix.htm#HIDEPSWhttp://www.orafaq.com/faqunix.htm#FILEFREEhttp://www.orafaq.com/faqunix.htm#RELINKhttp://www.orafaq.com/faqunix.htm#COREhttp://www.orafaq.com/faqunix.htm#SOFTWAREhttp://www.orafaq.com/faqunix.htm#ENVVARShttp://www.orafaq.com/faqunix.htm#COMMNDShttp://www.orafaq.com/faqunix.htm#WHERE
  • 8/7/2019 faq on oracle

    2/9

    How does one prepare the Oracle environment?

    An oraenv script is provided with every Oracle installation. Run it as part of your current environment to set thenecessary environment variables like ORACLE_HOME, ORACLE_SID, etc. Never set the Oracle Home directoryexplicitely in a script.The following example shows how to use oraenv (non-interactively) from a script:

    export ORACLE_SID=ORCL;export ORAENV_ASK=NO. oraenv

    NOTE: the ". " in front of "oraenv" is required to run the script as part of the current shell.

    How do I get Oracle to automatically start when my server boots up?

    Make sure the entry for your database SID in the ORATAB file ends in a capital "Y". Eg:# $ORACLE_SID:$ORACLE_HOME:[N|Y]#

    ORCL:/u01/app/oracle/product/8.0.5:Y

    #The scripts for starting and stopping databases are: $ORACLE_HOME/bin/dbstart and dbshut. SQL*Net (or Net8)is started with the lsnrctl command. Add the following entries to your/etc/rc2.d/S99dbstart (or

    equivalent) file:su - oracle -c "/path/to/$ORACLE_HOME/bin/dbstart" # Start DB'ssu - oracle -c "/path/to/$ORACLE_HOME/bin/lsnrctl start" # Start listenersu - oracle -c "/path/tp/$ORACLE_HOME/bin/namesctl start" # StartOraNames (optional)

    How does one list all installed Oracle products?

    One can display all installed products with version information by executing one of the following commands. ForOracle7 up to 8.0:

    cd $ORACLE_HOME/orainst./inspdver

    For Oracle 8i and above:cd $ORACLE_HOME/installcat unix.rgs

    Can one export directly to a tape drive?

    One can use a tape device name instead of a normal file name. When using a device, one also needs to specify theVOLSIZE= parameter. Look at this example:exp userid/password file=/dev/rmt0 table=emp volsize=1.2G

    Note: The volume size is a number ending with a "m", "k", or "b" (M, K, or B). The default is bytes.

    Can one archive directly to tape?

    Yes, set log_archive_dest = /dev/rmt0:100Min your INIT.ORA file and recycle the database.You can also use ARCHMON (when available) which communicates with the ARCH background process. Whenthe end of tape is reached, ARCH stops and signals ARCHMON to prompt the user for a new tape. WhenARCHMON detects the new tape, it tells the ARCH process to resume the archiving operation. ARCMON requiresregular operator monitoring and intervention.

    $ archmon @P:TEST

    I don't have enough space to export my database! Any suggestions?

    If one cannot afford to buy extra disk space one can run the export and compress utilities simultaneously. This willprevent the need to get enough space for both the export file AND the compressed export file. Eg:

    # Make a pipemknod expdat.dmp p # or mkfifo pipe# Start compress sucking on the pipe in backgroundcompress < expdat.dmp > expdat.dmp.Z Wait a second or two before kicking off the exportsleep 5# Start the exportexp scott/tiger file=expdat.dmp

    Or export accross the network directly into the target database:

  • 8/7/2019 faq on oracle

    3/9

    Host A:

    mknod FIFO.dmp pexp u/p FILE=FIFO.dmp rest_of_parameters...

    Host B:

    mknod FIFO2.dmp p

    rsh host1 dd if=FIFO.dmp > FIFO2.dmp &imp u/p FILE=FIFO2.dmp rest_of_parameters...

    Note: It is important that one verify that the named pipe is ready on each side before you start the process.

    How does one overcome the Unix 2 Gig file limit?

    This example uses the Unix splitcommand to create multiple files, each smaller than the Unix (and imp/exp) 2Gigabyte file size limit. This method can typically be used for import, export and SQL*Loader operations.

    cd /tmp/datarm exp.dmpmknod exp.dmp p # mkfifo on certain Unix flavourssplit -b2047m /tmp/data/exp.dmp &imp scott/tiger file=/tmp/data/exp.dmp commit=y tables=tableX

    What can be done to make export/import run faster?

    The IMP/EXP programs run in two task mode to protect the SGA from potential corruption by user programs. If yourelink these programs in single task mode you can gain much improvement in speed (up to 30%). Although Oraclewon't support this they supposedly use this method themselves.Although running in single-task is faster, it requires more memory since the Oracle executable's text is no longershared between the front-end and background processes. Thus, if you need to transfer large amounts of data betweendatabases, relink the executale for greater efficiency.

    cd $ORACLE_HOME/rdbms/libmake -f ins_rdbms.mk singletask

    # make -f ins_rdbms.mk expst# make -f ins_rdbms.mk impst# make -f ins_rdbms.mk sqlldrst# mv expst $ORACLE_HOME/bin/# mv impst $ORACLE_HOME/bin/# mv sqlldrst $ORACLE_HOME/bin/

    Now use expst and impst instead of imp or exp.

    How does one SELECT a value from a table into a Unix variable?

    One can select a value from a database column directly into a Unix environment variable. Look at the followingshell script examples:

    #!/bin/shVALUE=`sqlplus -silent user/password@instance

  • 8/7/2019 faq on oracle

    4/9

    sqlplus -s >junk1 /nolog /dev/tapedevice$ dd if=/dev/raw_device of=/dev/tape_device BS=8k

  • 8/7/2019 faq on oracle

    5/9

    $ pax -w -f archive.pax *

    5. End backup mode for all the tablespaces.ALTER TABLESPACE ... END BACKUP;

    Note: See thescripts sectionfor some examples.

    What is the purpose of the sgadef.dbf file?The sgadef.dbf file can be found in the ${ORACLE_HOME}/dbs directory. Whatever you do, DO NOT REMOVEIT!!! It tells the Oracle shadow processes the address of the SGA when the process first connects to the database. Ifthe process cannot find this file, it assumes the database is down.Problems can arise when the reverse is true ie. the database is down but the sgadef.dbf file exists, as happens whenthe system crashes. In this case, the memory segment addressed in the file doesn't exist (try ipcs -m to convinceyourself), which results in an error.

    Can one see what patches are applied to Oracle?

    With the Unix "what" command one can see what patches are applied to an executable. The Oracle implementationofwhatis owhat.The 'what' command delves into a file and extracts SCCS version control information from that file, if any exists.For more details, look up 'man what'. Look at this example:

    $ cd $ORACLE_HOME/bin$ owhat oracleOracle patches in /app/oracle/product/7.3.4/bin/oracle:

    sf.c VLFS patch 08/1/96sksa.c VLFS patch 08/1/96sp.c VLFS patch 08/1/96ssf.c VLFS patch 08/1/96

    How does one monitor and trace Unix processes?

    To trace what a Unix process is doing enter:truss -rall -wall -p truss -p $ lsnrctl dbsnmp_start

    NOTE: The "truss" command works on SUN and Sequent. Use "tusc" on HP-UX, "strace" on Linux, "trace" on

    SCO Unix or call your system administrator to find the equivalent command on your system.Monitor your Unix system:Unix message files record all system problems like disk errors, swap errors, NFS problems, etc. Monitor thefollowing files on your system to detect system problems:

    tail -f /var/adm/SYSLOGtail -f /var/adm/messagestail -f /var/log/syslog

    How does one write a script to do some work on all DB's?

    All databases on your machine should be listed in the ORATAB file. One can use this information to do processingon all databases on your machine. Look at this example:

    #!/bin/kshALL_DATABASES=`cat /etc/oratab|grep -v "^#"|grep -v "N$"|cut -f1 -d:

    -s`for DB in $ALL_DATABASESdo

    unset TWO_TASKexport ORACLE_SID=$DBexport ORACLE_HOME=`grep "^${DB}:" /etc/oratab|cut -d: -f2 -s`export PATH=$ORACLE_HOME/bin:$PATHecho "---> Database $ORACLE_SID, using home $ORACLE_HOME"

    sqlplus -s system/${DB}password @

  • 8/7/2019 faq on oracle

    6/9

    doneNOTE: The terminating 'EOF' should normally be in column 1. The '-' before the first EOF above causes the shell tostrip all leading TAB characters (not spaces, only TABs) from that point until (and including the EOF). This lets youindent the code in between using TABs.

    Can one prevent passwords from appearing in the system process table?

    One can prevent Oracle passwords from showing in the Unix process table (ps -ef) when running Oracle utilitieslike sqlplus. Look at the following solutions:

    sqlplus /NOLOG @conn.sql# No messing with ps, no password leak, connect from witin conn.sql

    or...echo "Name : \c"read Nameecho "Password : \c"stty -echoread Passwordstty echoecho ${Name}/${Password} | sqlplus

    or...USER=scottPASSWORD=tiger{ echo ${USER}/${PASSWORD}; cat ${your_script_name_here}; } | sqlplus

    Note: You can also create OPS$... or IDENTIFIED EXTERNALLY users in the database (to use OS authentication)and connect with a "/"

    Why doesn't Oracle release file space when you drop a tablespace?

    Sometimes when you drop a tablespace within Oracle, then remove (rm) the underlying data files, Oracle will notrelease filesystem space until you shut it down. This can be confirmed with the "df -k" command.This is normal behaviour on Unix machines. If a process has a file open for use, the file will be removed, but thespace it occupies will remain in place until all processes referencing it are closed.Use the "fuser" command before deleting Oracle datafiles. If any processes are touching them, you will not get thespace back when you rm the file. If SMON is locking your file, just wait a few minutes until it releases it.

    How does one relink the Oracle Server executables?

    Enter the following Unix commands:cd $ORACLE_HOME/rdbms/libmake -f ins_rdbms.mk install

    From Oracle 8i one can also use the "relink" command in the $ORACLE_HOME/bin directory.

    Can one copy Oracle software from one machine to another?

    Yes, one can copy or FTP the Oracle Software between similar machines. Look at the following example:# use tar to copy files and directorys with permissions and ownershiptar cf - $ORACLE_HOME | rsh "cd $ORACLE_HOME; tar xf -"

    To copy the Oracle software to a different directory on the same server:cd /new/oracle/dir/( cd $ORACLE_HOME; tar cf - . ) | tar xvf -

    NOTE: Remember to relink the Intelligent Agent on the new machine to prevent messages like "Encryption keysupplied is not the one used to encrypt file":

    cd /new/oracle/dir/cd network/libmake -f ins_agent.mk install

    What should one do with those core files?

    Make sure the complete CORE file was written out. System administrators usually limit core size to avoiddangerous core files filling file systems. Core file size can be limited with the "ulimit" or "limit" commands. Look atthese examples:

  • 8/7/2019 faq on oracle

    7/9

    $ ulimit -a # Display limits for your session under sh or ksh$ limit # Display limits for your session under csh or tcsh

    $ ulimit -c SIZE_IN_BLOCKS # Limit core size under sh or ksh$ limit coredumpsize SIZE_IN_KB # Limit core size under csh or tcsh

    If you see a core file lying around, just type "file core" to get some details about it. Example:

    $ file corecore:ELF-64 core file - PA-RISC 2.0 from 'sqlplus' - received SIGABRT

    Run the Unix process debugger to obtain more information about where and why the process abended. Thisinformation is normally requested by Oracle Support for in-depth analysis of the problem. Some example:

    Solaris:

    $ gdb $ORACLE_HOME/bin/sqlplus corebt # backtrace of all stack framesquit

    HP-UX, Solaris, etc:$ adb $ORACLE_HOME/bin/sqlplus core$c$q

    Sequent:

    $ debug -c core $ORACLE_HOME/bin/sqlplusdebug> stackdebug> quit

    Note: Some Unix operating systems use debugger commands like sdb, xdb, dbx, etc. The same principles apply; doa man on the command and go for it!

    What Unix environment variables needs to be set?

    Here are a few basic ORACLE environment variables. More environment variables, can be found in the Oracle forUnix Installations Guides.To check the value of these environment variables enter:

    env | grep -e ORA -e TNS

    LD_LIBRARY_PA

    TH

    Path to library files. Eg: /usr/lib:/usr/openwin/lib:$ORACLE_HOME/lib:/usr/games/lib

    ORACLE_BASE

    Full path name to the base directory for all versionsof Oracle products.

    ORACLE_HOME

    Full path name to the version of ORACLE you arecurrently using. ORACLE_HOME is normallyfound beneath ORACLE_BASE in the directorytree. This variable is used to find executableprograms and message files.

    ORACLE_SID

    ORACLE Server system identifier (SID) or instancename. The database name is used as ORACLE_SID.This is required for all ORACLE products and is setby the coraenv script.

    ORACLE_PATH

    Defines the path names to locate files. If

    ORACLE_PATH is set, the application searches thedirectories specified by $ORACLE_PATH first,then the current directory. If ORACLE_PATH is notset, then the application uses the current directory.This variable is used by SQL*Plus, Forms andMenu.

    ORACLE_TERM

    Defines a terminal definition. If not set, it defaults tothe value of your TERM environment variable.Used by all character mode products.

    ORAENV_ASK

    This will not ask for ORACLE_SID, it will take it asit is specified. This variable is normally set to "NO"before oraenv is invoked from a script.

  • 8/7/2019 faq on oracle

    8/9

    TNS_ADMIN

    Defines the path name to the TNS (TransparentNetwork Substrate) files like TNSNAMES.ORA,SQLNET.ORA etc.

    ORACLE_TRACE

    Trace Oracle's Unix shell scripts as they execute(using set -x).

    TWO_TA

    SK

    The TWO_TASK environment variable specifies aSQL*Net connect string for connecting to a remotemachine in a client/server configuration. SQL*Netwill check the value of TWO_TASK and

    automatically add it to your connect string.For example the following are equivalent:sqlplus scott/tiger@db1

    andexport TWO_TASK=db1; sqlplus scott/tiger

    What Unix commands can one use when administrating a database?

    The Unix command set is so rich that we can never list them all, however, if you are a beginner, you may find thefollowing commands useful. To get a detailed description of any command, just type man command-name.Basic Commnads:

    cdChange the current directory. When you log in, youare in your "home" directory

    lsList files in a directory (like the DOS DIRcommand)

    pwd Print working (current) directory

    cp Copy (duplicate) a file or directory

    rmRemove (delete) a file. Note that rm is permanent,there is no undelete. Be careful "rm -r *" is an easyway to get fired!!!

    mv

    Move or rename a file or directory. Works like cp

    except the old file is deletedmkdir Creates a new (sub) directory

    rmdir Remove a directory

    chmod Change file permissions or access attributes

    man UNIX manual pages

    du Disk usage

    script out.logWrite everything printed on your terminal to fileout.log. Hit CNTL-D to stop.

    More advanced commands for the guru's:

    ps -ef | grep inherit List all running Oracle Listeners

    ps -ef | grep smon List all running Oracle Databases

    ipcs | grep oracle

    Semaphores and shared memory

    segments belonging to oracleRemove with ipcrm, but becarefull!!!

    ls -la . | awk '{total += $5}; END {print total}'Prints the total size (in bytes) ofall files in the current directory

    ls -laR . | awk '{total += $5}; END {printtotal/1024/1024 " Meg"}'

    Prints the total size of files in thecurrent directory andsubdirectories below

    ls -laR | awk '{print $5 "\t" $9}' | sort -n | tailFind the largest files in dir andsubdirecotry.

    System Admin commands:

    Function: Sun: Sequent: HP-UX: AIX: SCO: Linux:

  • 8/7/2019 faq on oracle

    9/9

    Admin menu: admintool menu sam/ glance smit sysadmsh linuxconf

    System Config: /usr/sbin/psrinfo -v showcfg -s ? ? hw ?

    Trace system calls truss trace/truss trace/ tusc ? trace strace

    Shared lib dependancies ldd ? chatr ? ? ?

    Mount CD-Rom: non needed (automount) mount pfs_mount ? mount mount

    System utilization top top2 ? ? cpqmon ?