 




<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>SA-DBA &#187; shortcut</title>
	<atom:link href="http://itknowledgeexchange.techtarget.com/oracle-dba/tag/shortcut/feed/" rel="self" type="application/rss+xml" />
	<link>http://itknowledgeexchange.techtarget.com/oracle-dba</link>
	<description>Oracle Database Administrator in San Antonio</description>
	<lastBuildDate>Tue, 14 Jul 2009 13:55:54 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Environmental consistency .. is that even a real phrase?</title>
		<link>http://itknowledgeexchange.techtarget.com/oracle-dba/environmental-consistency-is-that-even-a-real-phrase/</link>
		<comments>http://itknowledgeexchange.techtarget.com/oracle-dba/environmental-consistency-is-that-even-a-real-phrase/#comments</comments>
		<pubDate>Tue, 14 Jul 2009 13:40:36 +0000</pubDate>
		<dc:creator>Richard Evans</dc:creator>
				<category><![CDATA[alias]]></category>
		<category><![CDATA[export]]></category>
		<category><![CDATA[kshrc]]></category>
		<category><![CDATA[profil]]></category>
		<category><![CDATA[shortcut]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Script]]></category>
		<category><![CDATA[SQLPATH]]></category>
		<category><![CDATA[SQLPLUS]]></category>

		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/oracle-dba/?p=127</guid>
		<description><![CDATA[Whether it is or isn&#8217;t doesn&#8217;t really matter&#8230; what I mean by environmental consistency is basically just making your life easier by installing, configuring, testing, developing, etc, the same way. This is one of the reasons why I love Response Files in Oracle. Another thing we do pretty well around here is configuring our environment [...]]]></description>
				<content:encoded><![CDATA[<p>Whether it is or isn&#8217;t doesn&#8217;t really matter&#8230; what I mean by environmental consistency is basically just making your life easier by installing, configuring, testing, developing, etc, the same way. This is one of the reasons why I love Response Files in Oracle. Another thing we do pretty well around here is configuring our environment variables the same. </p>
<p>I have a .kshrc and a .profile that I copy to every Oracle DB Zone and the only parameter I edit is the ORACLE_SID.  I&#8217;m sure there is still room for improvement here &#8212; off the topic of my head, I guess I could grep the /var/opt/oracle/oratab to find the SID and put that in for ORACLE_SID &#8212; but here is the way we set things up.<br />
<code><br />
[oracle: /oracle] cat .profile<br />
stty istrip<br />
stty erase</p>
<p># Oracle Variables...<br />
ORACLE_BASE=/oracle<br />
ORACLE_SID=CTM1<br />
ORACLE_HOME=/oracle/${ORACLE_SID}/102_64<br />
NLS_DATE_FORMAT='DD-Mon-YYYY HH24:MI:SS'<br />
NLS_LANG=american_america.US7ASCII<br />
SQLPATH=/group/oracle/sql<br />
PATH=/group/oracle/sh:$ORACLE_HOME/bin:/usr/bin:/usr/sbin:/etc:/usr/ccs/bin:/usr/ucb:/etc:$ORACLE_BASE/$ORACLE_SID/admin/scripts/sh:/usr/openwin/bin:$ORACLE_HOME/OPatch:/usr/local/bin:.</p>
<p>export ORACLE_BASE ORACLE_SID ORACLE_HOME SQLPATH NLS_LANG NLS_DATE_FORMAT PATH</p>
<p># tell us what zone we're in when we login.<br />
ZN=`uname -n`<br />
echo "Zone name is ${ZN}"</p>
<p># Display user, SID, and current working directory as the command prompt.<br />
export PS1='[$LOGNAME: $PWD] '<br />
. ./.kshrc<br />
</code><br />
And we do the same thing with our .kshrc. We try to references environment variables whenever possible. The less we hardcode, the less we have to change when we setup a new machine!<br />
<code><br />
[oracle: /oracle] cat .kshrc<br />
export EDITOR=vi<br />
alias l='ls -ltr'<br />
alias bdump='cd /oracle/$ORACLE_SID/oratrace/bdump'<br />
alias arch='cd /oracle/$ORACLE_SID/oraarch'<br />
alias udump='cd /oracle/$ORACLE_SID/oratrace/udump'<br />
alias scrp='cd /group/oracle/sh'<br />
alias sql='cd /group/oracle/sql'<br />
alias par='cd $HOME/scripts/parms'<br />
alias out='cd /RMAN/scripts/logs/$ORACLE_SID'<br />
alias dbs='cd $ORACLE_HOME/dbs'<br />
alias net='cd $ORACLE_HOME/network/admin'<br />
alias alert='vi /oracle/$ORACLE_SID/oratrace/bdump/alert_$ORACLE_SID.log'<br />
alias oraenv='. $ORACLE_HOME/bin/oraenv'<br />
alias ohome='cd $ORACLE_HOME'<br />
alias tail_alert='tail -f /oracle/$ORACLE_SID/oratrace/bdump/alert_${ORACLE_SID}.log'<br />
alias alert500='tail -500 /oracle/$ORACLE_SID/oratrace/bdump/alert_${ORACLE_SID}.log | more'<br />
alias rdbms='cd $ORACLE_HOME/rdbms/admin'<br />
alias sw='cd /group/software/oracle/stage/102_64'<br />
</code></p>
<p>My favorite part out of this whole mess is the SQLPATH variable. This is a great variable that lets you execute SQL scripts from a different location by simply using &#8220;@&#8221; as if it were in your current working directory.</p>
<p>According to the <a href="http://download.oracle.com/docs/cd/B19306_01/server.102/b14357/ch2.htm#sthref347">SQL*Plus User&#8217;s Guide and Reference</a>, SQLPATH is:</p>
<p><em>Environment variable or Windows registry entry to specify the location of SQL scripts. SQL*Plus searches for SQL scripts, including login.sql, in the current directory and then in the directories specified by SQLPATH, and in the subdirectories of SQLPATH directories. SQLPATH is a colon separated list of directories. There is no default value set in UNIX installations.</p>
<p>In Windows, SQLPATH is defined in a registry entry during installation. For more information about the SQLPATH registry entry, see SQLPATH Registry Entry.</em></p>
<p>What I do is put my most-commonly used scripts into the directory defined in SQLPATH and then I can call it from anywhere. Obviously this has to be a directory that is accessible across zones (servers) <img src='http://itknowledgeexchange.techtarget.com/oracle-dba/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Keep in mind Oracle will FIRST look at your current working directory and then query the SQLPATH. So if you have a script by the same name in each directory you&#8217;ll drive yourself nuts when it isn&#8217;t working as you&#8217;d expect! I speak from experience. <img src='http://itknowledgeexchange.techtarget.com/oracle-dba/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>So here is an example of how I check current sessions:<br />
<code><br />
[oracle: /oracle] ls -al get_session.sql<br />
get_session.sql: No such file or directory<br />
[oracle: /oracle] sqlplus / as sysdba</p>
<p>SQL*Plus: Release 10.2.0.4.0 - Production on Tue Jul 14 08:18:15 2009</p>
<p>Copyright (c) 1982, 2007, Oracle.  All Rights Reserved.</p>
<p>Connected to:<br />
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production<br />
With the Partitioning, Data Mining and Real Application Testing options</p>
<p>SQL&gt; @get_session<br />
Sessions on database AD1<br />
PID      SID      SER#     BOX           USERNAME        OS_USER      PROGRAM                             SQL_ADDRESS      SQL_HASH_VALUE<br />
-------- -------- -------- ------------- --------------- ------------ ----------------------------------- ---------------- --------------<br />
12140    196      5604     oraad1        SYSMAN          oracle       emagent@oraad1 (TNS V1-V3)          00                            0<br />
12261    182      12004    omsapp        DBSNMP                       OMS                                 00                            0<br />
12726    424      9074     oraad1        DBSNMP          oracle       emagent@oraad1 (TNS V1-V3)          00                            0<br />
13101    431      54       oraad1        DBSNMP          oracle       emagent@oraad1 (TNS V1-V3)          00                            0<br />
16456    396      29816    oraad1        SYS             oracle       rman@oraad1 (TNS V1-V3)             00                            0<br />
</code></p>
<p>I&#8217;m sorry, the output isn&#8217;t quite as pretty as I&#8217;d like but I think it conveys my point.  Using a couple quick variables and commands I can maintain a consistent environment.</p>
<p>The get_session.sql script is something I&#8217;ve &#8220;acquired&#8221; from years of DBA&#8217;ing via Google <img src='http://itknowledgeexchange.techtarget.com/oracle-dba/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>Here it is:<br />
<code><br />
SQL&gt; l<br />
  1  select substr(a.spid,1,9) pid<br />
  2       , substr(b.sid,1,5) sid<br />
  3       , substr(b.serial#,1,5) ser#<br />
  4       , substr(b.machine,1,9) box<br />
  5       , substr(b.username,1,10) username<br />
  6       , substr(b.osuser,1,9) os_user<br />
  7       , substr(b.program,1,30) program<br />
  8       , b.sql_address sql_address<br />
  9       , b.sql_hash_value sql_hash_value<br />
 10    from v$session b, v$process a --, v$sqlarea c<br />
 11   where b.paddr = a.addr<br />
 12     and type='USER'<br />
 13*  order by spid<br />
</code></p>
<p>I do the same thing with a user.sql script:<br />
<code><br />
[oracle: /oracle] ls -al user.sql<br />
user.sql: No such file or directory<br />
[oracle: /oracle] sqlplus / as sysdba<br />
SQL&gt; @user.sql<br />
Enter value for 1:<br />
old   3:  where username like upper('%&amp;1%')<br />
new   3:  where username like upper('%%')</p>
<p>USERNAME     PROFILE        ACCOUNT_STATUS     CREATED<br />
------------ -------------- ------------------ --------------------<br />
DBSNMP       DEFAULT        OPEN               23-Oct-2005 08:47:09<br />
PERFSTAT     DEFAULT        OPEN               26-Sep-2008 16:32:34<br />
RMAN         DEFAULT        OPEN               23-Oct-2005 08:47:10<br />
SYS          DEFAULT        OPEN               15-Dec-2003 09:43:18<br />
SYSMAN       DEFAULT        OPEN               11-Feb-2009 10:37:41<br />
SYSTEM       DEFAULT        OPEN               15-Dec-2003 09:43:18<br />
ORACLE_OCM   DEFAULT        EXPIRED &amp; LOCKED   01-Jul-2009 14:06:09<br />
OUTLN        DEFAULT        EXPIRED &amp; LOCKED   23-Oct-2005 08:47:09<br />
TSMSYS       DEFAULT        EXPIRED &amp; LOCKED   28-Jun-2008 00:52:53<br />
WMSYS        DEFAULT        EXPIRED &amp; LOCKED   23-Oct-2005 08:47:10</p>
<p>SQL&gt; l<br />
  1  select username, profile,  account_status, created<br />
  2    from dba_users<br />
  3*  where username like upper('%&amp;1%')<br />
</code></p>
<p>What I like about this script is if you do not enter a username then it&#8217;ll display all of the users. The results are as narrow or as broad as you want. I have more columns in this script, like password hash, but that&#8217;s not information I care to give out. I think you understand <img src='http://itknowledgeexchange.techtarget.com/oracle-dba/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>I hope this gives you an idea of what you can do with such a simple variable.  The more simple and cleaner you can make your environment the better off you&#8217;ll be. </p>
<p>What do you do to simplify your environment? Are there variables and aliases that you setup that I&#8217;ve missed? I&#8217;d like to hear about them!</p>
<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/oracle-dba/environmental-consistency-is-that-even-a-real-phrase/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
