﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-Decode360's Blog技术</title><link>http://www.blogjava.net/wxqxs/category/33739.html</link><description>菜鸟也疯狂...</description><language>zh-cn</language><lastBuildDate>Wed, 22 Apr 2009 09:57:36 GMT</lastBuildDate><pubDate>Wed, 22 Apr 2009 09:57:36 GMT</pubDate><ttl>60</ttl><item><title>Oracle OS认证与口令文件认证详解</title><link>http://www.blogjava.net/wxqxs/news/2009/04/22/267002.html</link><dc:creator>decode360</dc:creator><author>decode360</author><pubDate>Wed, 22 Apr 2009 08:04:00 GMT</pubDate><guid>http://www.blogjava.net/wxqxs/news/2009/04/22/267002.html</guid><wfw:comment>http://www.blogjava.net/wxqxs/comments/267002.html</wfw:comment><comments>http://www.blogjava.net/wxqxs/news/2009/04/22/267002.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/wxqxs/comments/commentRss/267002.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/wxqxs/services/trackbacks/267002.html</trackback:ping><description><![CDATA[
		<div id="wrapper">
				<div id="header">
						<h1>
								<a title="http://www.lansz.com/html/2008/06/oracle_os_pwfile_authentication.html&#xA;永久链接到 Oracle OS认证与口令文件认证详解" href="http://www.lansz.com/html/2008/06/oracle_os_pwfile_authentication.html" rel="bookmark">
										<font title="http://www.lansz.com/html/2008/06/oracle_os_pwfile_authentication.html" face="Courier New" size="2">Oracle OS认证与口令文件认证详解</font>
								</a>
						</h1>
				</div>
				<div id="container">
						<div id="content">
								<div class="post" id="postitem">
										<div class="postmeta">
												<font face="Courier New" size="2">作者：</font>
												<a title="http://www.lansz.com/&#xA;蓝蓝de天" href="http://www.lansz.com/">
														<font title="http://www.lansz.com/" face="Courier New" size="2">lansz</font>
												</a>
												<font face="Courier New" size="2"> | 可以转载, 转载时务必以超链接形式标明文章原始出处和作者信息及版权声明<br />链接：</font>
												<a title="http://www.lansz.com/html/2008/06/oracle_os_pwfile_authentication.html&#xA;永久链接到 Oracle OS认证与口令文件认证详解" href="http://www.lansz.com/html/2008/06/oracle_os_pwfile_authentication.html">
														<font title="http://www.lansz.com/html/2008/06/oracle_os_pwfile_authentication.html" face="Courier New" size="2">http://www.lansz.com/html/2008/06/oracle_os_pwfile_authentication.html</font>
												</a>
												<font face="Courier New" size="2">
												</font>
										</div>
										<div class="postentry">
												<h2>
														<font face="Courier New" size="2">本文概述与实验环境</font>
												</h2>
												<p>
														<font face="Courier New">
																<font size="2">
																		<strong>概述：</strong>本文只讨论OS认证和口令文件认证方式的配置方法，如何配置以及使用OS认证和口令文件认证方式验证SYSDBA/SYSOPER权限。</font>
														</font>
												</p>
												<p>
														<font face="Courier New">
																<font size="2">
																		<strong>实验环境：</strong>Oracle 10.1 + Windows 2003 和 Oracle 10.2 + RHEL 4</font>
														</font>
												</p>
												<h2>
														<font face="Courier New" size="2">特殊权限与Oracle登陆认证管理</font>
												</h2>
												<p>
														<font face="Courier New" size="2">在开始学Oracle的时候有件事一直让我感觉很奇怪，就是为什么在数据没有起来的时候只要登录到安装Oracle的操作系统中直接用sqlplus / as sysdba就能登陆到数据库中然后对数据库进行启动停止之类的操作。后来看到关于Oracle口令文件相关资料的时候才豁然开朗：数据库认证信息并不一定存在数据库中的，这点和SQL Server很是不一样。</font>
												</p>
												<p>
														<font face="Courier New" size="2">在Oracle中有两类特殊的权限SYSDBA和SYSOPER，当DBA需要对数据库进行维护管理操作的时候必须具有这两类特殊权限之中的一种。<span style="COLOR: #0000ff"><strong>在数据库没有打开的时候，使用数据库内建的账号是无法登陆数据库的，但是拥有SYSDBA或是SYSOPER权限的用户是可以登陆的</strong></span>。认证用户是否拥有两类特殊权限的方法有两种：OS认证和口令文件认证。</font>
												</p>
												<h2>
														<font face="Courier New" size="2">OS认证和口令文件认证方法</font>
												</h2>
												<p style="TEXT-ALIGN: center">
														<font face="Courier New" size="2">
																<img style="VERTICAL-ALIGN: middle" height="277" alt="" src="http://download.oracle.com/docs/cd/B19306_01/server.102/b14231/img/admin001.gif" width="465" />
														</font>
												</p>
												<p style="TEXT-ALIGN: center">
														<font face="Courier New" size="2">Oracle特殊权限认证方法<br />（来源：Oracle® Database Administrator’s Guide 10g Release 2）</font>
												</p>
												<p>
														<font face="Courier New" size="2">Oracle数据库究竟使用OS认证还是口令文件认证来进行管理取决于下面三个因素：</font>
												</p>
												<ul>
														<li>
																<font face="Courier New" size="2">SQLNET.ORA参数文件中的参数SQLNET.AUTHENTICATION_SERVICES设置 </font>
														</li>
														<li>
																<font face="Courier New" size="2">PFILE(SPFILE)参数文件中的参数REMOTE_LOGIN_PASSWORDFILE设置 </font>
														</li>
														<li>
																<font face="Courier New" size="2">口令文件orapw$SID(Linux) | PWD$SID.ora(Windows) </font>
														</li>
												</ul>
												<p>
														<span style="COLOR: #0000ff">
																<font face="Courier New" size="2">Oracle权限认证的基本顺序是这样的，先由SQLNET.AUTHENTICATION_SERVICES的设置值来决定是使用OS认证还是口令文件认证，如果使用口令文件认证的话就要看后面两个条件了：如果REMOTE_LOGIN_PASSWORDFILE参数设置为非NONE而且口令文件存在的话就能正常使用口令文件认证，否则将会失败。</font>
														</span>
												</p>
												<h2>
														<font face="Courier New" size="2">SQLNET.AUTHENTICATION_SERVICES参数</font>
												</h2>
												<p>
														<font face="Courier New" size="2">在SQLNET.ORA（位于$ORACLE_HOME/NETWORK/ADMIN目录中）文件中，需要修改时直接用文本编辑器打开修改就行了，对于不同的操作系统SQLNET.AUTHENTICATION_SERVICES的取值会有些不一样，通常我们会用到下面的一些设置值：</font>
												</p>
												<ul>
														<li>
																<font face="Courier New">
																		<font size="2">
																				<strong>SQLNET.AUTHENTICATION_SERVICES = (ALL)</strong>
																		</font>
																</font>
														</li>
												</ul>
												<p style="TEXT-INDENT: 21.1pt">
														<font face="Courier New" size="2">对Linux系统，支持OS认证和口令文件认证。</font>
												</p>
												<p style="TEXT-INDENT: 21.1pt">
														<font face="Courier New" size="2">对Windows系统，实际实验是不支持此参数，验证失败。</font>
												</p>
												<ul>
														<li>
																<font face="Courier New">
																		<font size="2">
																				<strong>SQLNET.AUTHENTICATION_SERVICES = (NTS)</strong>
																		</font>
																</font>
														</li>
												</ul>
												<p style="TEXT-INDENT: 21.1pt">
														<font face="Courier New" size="2">此设置值仅用于Windows NT系统，此设置同时支持OS认证和口令文件认证，只有在设置了(NTS)值之后运行在Windows系统上的Oracle才支持OS认证。</font>
												</p>
												<ul>
														<li>
																<font face="Courier New">
																		<font size="2">
																				<strong>SQLNET.AUTHENTICATION_SERVICES = (NONE)</strong>
																		</font>
																</font>
														</li>
												</ul>
												<p style="TEXT-INDENT: 21.1pt">
														<font face="Courier New" size="2">此设置值在Windows和Linux是作用一样的，指定Oracle只使用口令文件认证。</font>
												</p>
												<ul>
														<li>
																<font face="Courier New">
																		<font size="2">
																				<strong>不设置此参数或SQLNET.AUTHENTICATION_SERVICES =</strong>
																		</font>
																</font>
														</li>
												</ul>
												<p style="TEXT-INDENT: 21.1pt">
														<font face="Courier New" size="2">对Linux系统，默认支持OS认证和口令文件认证。</font>
												</p>
												<p style="TEXT-INDENT: 21.1pt">
														<font face="Courier New" size="2">对Windows系统，默认只支持口令文件认证，不支持OS认证。</font>
												</p>
												<h2>
														<font face="Courier New" size="2">OS认证实现</font>
												</h2>
												<p>
														<font face="Courier New" size="2">Oracle使用操作系统中的两个用户组来控制OS认证，在不同的操作系统中这两个用户组的名称是不一样的，一般来说他们是OSDBA 和 OSOPER，这两个用户组都是在Oracle安装的时候创建的。下面列出不同系统中这两个用户组的名字：<br /></font>
												</p>
												<table bordercolor="black" cellspacing="0" cellpadding="5" border="1">
														<font face="Courier New">
																<br />
																<font size="2">
																</font>
														</font>
														<thead align="middle" bgcolor="gray">
																<font face="Courier New">
																		<br />
																		<font size="2">
																		</font>
																</font>
																<tr>
																		<th>
																				<font face="Courier New" size="2">Operating System Group<br /></font>
																		</th>
																		<th>
																				<font face="Courier New" size="2">UNIX User Group<br /></font>
																		</th>
																		<th>
																				<font face="Courier New">
																						<font size="2">UNIX User Group<br /></font>
																				</font>
																		</th>
																</tr>
														</thead>
														<font face="Courier New">
																<br />
																<font size="2">
																</font>
														</font>
														<tbody>
																<tr align="middle">
																		<font face="Courier New">
																				<br />
																				<font size="2">
																				</font>
																		</font>
																		<td>
																				<font face="Courier New" size="2">OSDBA<br /></font>
																		</td>
																		<td>
																				<font face="Courier New" size="2">dba<br /></font>
																		</td>
																		<td>
																				<font face="Courier New" size="2">ORA_DBA<br /></font>
																		</td>
																</tr>
																<tr align="middle">
																		<font face="Courier New">
																				<br />
																				<font size="2">
																				</font>
																		</font>
																		<td>
																				<font face="Courier New" size="2">OSOPER<br /></font>
																		</td>
																		<td>
																				<font face="Courier New" size="2">oper<br /></font>
																		</td>
																		<td>
																				<font face="Courier New" size="2">ORA_OPER<br /></font>
																		</td>
																</tr>
														</tbody>
												</table>
												<p>
														<font face="Courier New" size="2">OSDBA用户组的用户可以使用SYSDBA权限登陆数据库，OSOPER用户组的的用户可以使用SYSOPER权限来登陆数据库。使用sqlplus可以用下面方法登陆</font>
												</p>
												<div class="hl-surround">
														<div class="hl-main">
																<font face="Courier New">
																		<font size="2">
																				<span style="COLOR: green">CONNECT</span>
																				<span style="COLOR: gray"> / </span>
																				<span style="COLOR: green">AS</span>
																				<span style="COLOR: gray">
																				</span>
																				<span style="COLOR: blue">SYSDBA</span>
																		</font>
																</font>
																<span style="COLOR: gray">
																		<br />
																</span>
																<font face="Courier New">
																		<font size="2">
																				<span style="COLOR: green">CONNECT</span>
																				<span style="COLOR: gray"> / </span>
																				<span style="COLOR: green">AS</span>
																				<span style="COLOR: gray">
																				</span>
																				<span style="COLOR: blue">SYSOPER</span>
																		</font>
																</font>
														</div>
												</div>
												<p>
														<font face="Courier New" size="2">拥有OS权限的用户登陆数据库时不再需要输入用户名和密码，因此使用下面的命令也是可以正常登陆的：</font>
												</p>
												<div class="hl-surround">
														<div class="hl-main">
																<font face="Courier New">
																		<font size="2">
																				<span style="COLOR: green">CONNECT</span>
																				<span style="COLOR: gray">
																				</span>
																				<span style="COLOR: blue">ANY_USER_NAME</span>
																				<span style="COLOR: gray">/</span>
																				<span style="COLOR: blue">ANY_PASSWORD</span>
																				<span style="COLOR: gray">
																				</span>
																				<span style="COLOR: green">AS</span>
																				<span style="COLOR: gray">
																				</span>
																				<span style="COLOR: blue">SYSDBA</span>
																		</font>
																</font>
																<span style="COLOR: gray">
																		<br />
																</span>
																<font face="Courier New">
																		<font size="2">
																				<span style="COLOR: green">CONNECT</span>
																				<span style="COLOR: gray">
																				</span>
																				<span style="COLOR: blue">ANY_USER_NAME</span>
																				<span style="COLOR: gray">/</span>
																				<span style="COLOR: blue">ANY_PASSWORD</span>
																				<span style="COLOR: gray">
																				</span>
																				<span style="COLOR: green">AS</span>
																				<span style="COLOR: gray">
																				</span>
																				<span style="COLOR: blue">SYSOPER</span>
																		</font>
																</font>
														</div>
												</div>
												<p>
														<font face="Courier New" size="2">因此要创建一个新的OS认证帐号步骤是：</font>
												</p>
												<p style="TEXT-INDENT: 21.1pt">
														<font face="Courier New" size="2">
														</font>
												</p>
												<ol>
														<li>
																<font face="Courier New" size="2">建立一个OS用户 </font>
														</li>
														<li>
																<font face="Courier New" size="2">将用户加入到OSDBA或是OSOPER用户组 </font>
														</li>
														<li>
																<font face="Courier New" size="2">用新增加的用户登陆系统，然后输入sqlplus / AS SYSDBA进行登陆 </font>
														</li>
												</ol>
												<h2>
														<font face="Courier New" size="2">REMOTE_LOGIN_PASSWORDFILE参数</font>
												</h2>
												<p>
														<font face="Courier New" size="2">REMOTE_LOGIN_PASSWORDFILE系统参数的设置制定了数据库使用口令文件的方法，此参数可以设置的值有三个：</font>
												</p>
												<ul>
														<li>
																<font face="Courier New">
																		<font size="2">
																				<strong>REMOTE_LOGIN_PASSWORDFILE = NONE</strong>
																		</font>
																</font>
														</li>
												</ul>
												<p style="TEXT-INDENT: 21.1pt">
														<font face="Courier New" size="2">不使用口令文件</font>
												</p>
												<ul>
														<li>
																<font face="Courier New">
																		<font size="2">
																				<strong>REMOTE_LOGIN_PASSWORDFILE = EXCLUSIVE</strong>
																		</font>
																</font>
														</li>
												</ul>
												<p style="TEXT-INDENT: 21.1pt">
														<font face="Courier New" size="2">使用口令文件，但只有一个数据库实例可用使用</font>
												</p>
												<ul>
														<li>
																<font face="Courier New">
																		<font size="2">
																				<strong>REMOTE_LOGIN_PASSWORDFILE = SHARED</strong>
																		</font>
																</font>
														</li>
												</ul>
												<p style="TEXT-INDENT: 21.1pt">
														<font face="Courier New" size="2">多个数据库实例共用一个口令文件，这种设置下是不能增加其他数据库用户作为特殊权限用户到口令文件中的。</font>
												</p>
												<p>
														<font face="Courier New" size="2">REMOTE_LOGIN_PASSWORDFILE参数属于初始化参数，只能在init.ora/pfile中指定或是在数据库打开状态下使用下面语句修改，然后重新启动数据库。</font>
												</p>
												<div class="hl-surround">
														<div class="hl-main">
																<font face="Courier New">
																		<font size="2">
																				<span style="COLOR: green">ALTER</span>
																				<span style="COLOR: gray">
																				</span>
																				<span style="COLOR: #00008b">SYSTEM</span>
																				<span style="COLOR: gray">
																				</span>
																				<span style="COLOR: green">SET</span>
																				<span style="COLOR: gray">
																				</span>
																				<span style="COLOR: blue">REMOTE_LOGIN_PASSWORDFILE</span>
																				<span style="COLOR: gray">=</span>
																				<span style="COLOR: blue">EXCLUSIVE</span>
																				<span style="COLOR: gray">
																				</span>
																				<span style="COLOR: green">SCOPE</span>
																				<span style="COLOR: gray">=</span>
																				<span style="COLOR: blue">SPFILE</span>
																				<span style="COLOR: gray">;</span>
																		</font>
																</font>
														</div>
												</div>
												<p>
														<font face="Courier New" size="2">要检查当前REMOTE_LOGIN_PASSWORDFILE的设定值在登陆Oracle后输入下面的命令</font>
												</p>
												<div class="hl-surround">
														<div class="hl-main">
																<font face="Courier New">
																		<font size="2">
																				<span style="COLOR: green">SQL</span>
																				<span style="COLOR: gray">&gt; </span>
																				<span style="COLOR: blue">show</span>
																				<span style="COLOR: gray">
																				</span>
																				<span style="COLOR: green">parameter</span>
																				<span style="COLOR: gray">
																				</span>
																				<span style="COLOR: blue">remote</span>
																		</font>
																</font>
																<span style="COLOR: gray">
																		<br />
																</span>
																<span style="COLOR: #ffa500">
																		<font face="Courier New" size="2">/** 这是输出结果，看remote_login_passwordfile一行<br />NAME                                 TYPE        VALUE<br />------------------------------------ ----------- ------------------------------<br />remote_archive_enable                string      true<br />remote_dependencies_mode             string      TIMESTAMP<br />remote_listener                      string<br />remote_login_passwordfile            string      EXCLUSIVE<br />remote_os_authent                    boolean     FALSE<br />remote_os_roles                      boolean     FALSE<br />SQL&gt;<br />*/</font>
																</span>
														</div>
												</div>
												<h2>
														<font face="Courier New" size="2">口令文件和口令文件认证</font>
												</h2>
												<p>
														<font face="Courier New" size="2">口令文件存放着被授予SYSDBA或SYSOPER权限的用户的用户名和密码。它是一个加密的文件，用户不能修改这个文件，<br />在Linux系统中口令文件一般保存在$ORACLE_HOME/dbs目录下，文件名为orapw$SID；在Windows系统中口令文件一般保存在$ORACLE_HOME/database目录下，文件名为PWD$SID.ora。</font>
												</p>
												<p>
														<font face="Courier New" size="2">使用口令文件认证的基本步骤是：</font>
												</p>
												<p style="TEXT-INDENT: 21.1pt">
														<font face="Courier New" size="2">
														</font>
												</p>
												<ol>
														<li>
																<font face="Courier New" size="2">使用orapwd工具生成口令文件 </font>
														</li>
														<li>
																<font face="Courier New" size="2">设置REMOTE_LOGIN_PASSWORDFILE为EXCLUSIVE或是SHARED </font>
														</li>
														<li>
																<font face="Courier New" size="2">使用SYS登陆数据库，创建新的数据库用户 </font>
														</li>
														<li>
																<font face="Courier New" size="2">使用GRANT命令授予新创建的用户SYSDBA/SYSOPER权限 </font>
														</li>
												</ol>
												<p>
														<strong>
																<font face="Courier New" size="2">1、使用orapwd工具生成口令文件</font>
														</strong>
												</p>
												<p>
														<font face="Courier New" size="2">我们可以使用Oracle提供的工具orapwd来创建或者重新初始化一个口令文件：</font>
												</p>
												<div class="hl-surround">
														<div class="hl-main">
																<font face="Courier New" size="2">[oracle@RHEL4 dbs]$ orapwd<br />Usage: orapwd file=&lt;fname&gt; password=&lt;password&gt; entries=&lt;users&gt; force=&lt;y/n&gt;<br /><br />  where<br />    file - name of password file (mand),<br />    password - password for SYS (mand),<br />    entries - maximum number of distinct DBA and     force - whether to overwrite existing file (opt),<br />OPERs (opt),<br />  There are no spaces around the equal-to (=) character.<br />[oracle@RHEL4 ~]$ orapwd file='$ORACLE_HOME/dbs/orapw$ORACLE_SID' password=pwd entries=10 force=y<br />[oracle@RHEL4 ~]$</font>
														</div>
												</div>
												<p>
														<font face="Courier New" size="2">注意：使用orapwd重新生成口令文件之后以保存的授予的其他用户的SYSDBA或是SYSOPER权限将会丢失，需要重新的GRANT。</font>
												</p>
												<p>
														<font face="Courier New" size="2">设定的entries值是不能修改的，如果要修改entries的话需要重新生成口令文件，在生成口令文件之前可以先通过V$PWFILE_USERS视图查询出当前被授予SYSDBA/SYSOPER权限的用户，然后在重新生成口令文件以后重新对这些用户授予SYSDBA/SYSOPER权限</font>
												</p>
												<p>
														<strong>
																<font face="Courier New" size="2">2、设置REMOTE_LOGIN_PASSWORDFILE为EXCLUSIVE或是SHARED</font>
														</strong>
												</p>
												<div class="hl-surround">
														<div class="hl-main">
																<font face="Courier New">
																		<font size="2">
																				<span style="COLOR: green">ALTER</span>
																				<span style="COLOR: gray">
																				</span>
																				<span style="COLOR: #00008b">SYSTEM</span>
																				<span style="COLOR: gray">
																				</span>
																				<span style="COLOR: green">SET</span>
																				<span style="COLOR: gray">
																				</span>
																				<span style="COLOR: blue">REMOTE_LOGIN_PASSWORDFILE</span>
																				<span style="COLOR: gray">=</span>
																				<span style="COLOR: blue">EXCLUSIVE</span>
																				<span style="COLOR: gray">
																				</span>
																				<span style="COLOR: green">SCOPE</span>
																				<span style="COLOR: gray">=</span>
																				<span style="COLOR: blue">SPFILE</span>
																				<span style="COLOR: gray">;</span>
																		</font>
																</font>
														</div>
												</div>
												<p>
														<strong>
																<font face="Courier New" size="2">3、使用SYS登陆数据库，创建新的数据库用户</font>
														</strong>
												</p>
												<div class="hl-surround">
														<div class="hl-main">
																<font face="Courier New">
																		<font size="2">
																				<span style="COLOR: green">CREATE</span>
																				<span style="COLOR: gray">
																				</span>
																				<span style="COLOR: green">USER</span>
																				<span style="COLOR: gray">
																				</span>
																				<span style="COLOR: blue">test</span>
																				<span style="COLOR: gray">
																				</span>
																				<span style="COLOR: blue">IDENTIFIED</span>
																				<span style="COLOR: gray">
																				</span>
																				<span style="COLOR: green">BY</span>
																				<span style="COLOR: gray">
																				</span>
																				<span style="COLOR: blue">test</span>
																				<span style="COLOR: gray">;</span>
																		</font>
																</font>
														</div>
												</div>
												<p>
														<strong>
																<font face="Courier New" size="2">4、使用GRANT命令授予新创建的用户SYSDBA/SYSOPER权限</font>
														</strong>
												</p>
												<div class="hl-surround">
														<div class="hl-main">
																<font face="Courier New">
																		<font size="2">
																				<span style="COLOR: green">GRANT</span>
																				<span style="COLOR: gray">
																				</span>
																				<span style="COLOR: blue">SYSDBA</span>
																				<span style="COLOR: gray">
																				</span>
																				<span style="COLOR: green">TO</span>
																				<span style="COLOR: gray">
																				</span>
																				<span style="COLOR: blue">test</span>
																				<span style="COLOR: gray">.</span>
																		</font>
																</font>
														</div>
												</div>
												<p>
														<font face="Courier New" size="2">每次在Oracle系统里面使用GRANT SYSDBA/SYSOPER授予新用户特殊权限或是ALTER USER命令修改拥有SYSDBA/SYSOPER权限的用户密码的时候，Oracle都会自动的修改口令文件，增加或是修改相应的项目，这样保证在数据没有打开的情况拥有特殊权限的用户能正常的登陆数据库以进行管理操作。</font>
												</p>
												<h2>
														<font face="Courier New" size="2">实验</font>
												</h2>
												<p>
														<font face="Courier New" size="2">上面长篇大论的说了那么多，下面我们来做实验验证一下。实验都是基于Linux系统来做的，做实验之前先使用下面的命令创建一个口令文件：</font>
												</p>
												<div class="hl-surround">
														<div class="hl-main">
																<font face="Courier New" size="2">[oracle@RHEL4 ~]$ orapwd file='$ORACLE_HOME/dbs/orapw$ORACLE_SID' password=pwd entries=10 force=y</font>
														</div>
												</div>
												<h3>
														<font face="Courier New" size="2">1、验证OS认证</font>
												</h3>
												<p>
														<font face="Courier New" size="2">设置SQLNET.ORA中参数SQLNET.AUTHENTICATION_SERVICES = (ALL)或是不设置，REMOTE_LOGIN_PASSWORDFILE = NONE，然后进行下面的操作。</font>
												</p>
												<p>
														<font face="Courier New" size="2">本地使用下面两种方式登陆，都能成功</font>
												</p>
												<div class="hl-surround">
														<div class="hl-main">
																<font face="Courier New" size="2">[oracle@RHEL4 dbs]$ sqlplus / as sysdba<br /><br />SQL*Plus: Release 10.2.0.1.0 - Production on Sun Jun 7 15:06:55 2008<br /><br />Copyright (c) 1982, 2005, Oracle.  All rights reserved.<br /><br /><br />Connected to:<br />Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production<br />With the Partitioning, OLAP and Data Mining options<br /><br />SQL&gt;</font>
														</div>
												</div>
												<div class="hl-surround">
														<div class="hl-main">
																<font face="Courier New" size="2">[oracle@RHEL4 dbs]$ sqlplus aaa/bbb as sysdba<br /><br />SQL*Plus: Release 10.2.0.1.0 - Production on Sun Jun 7 15:16:25 2008<br /><br />Copyright (c) 1982, 2005, Oracle.  All rights reserved.<br /><br /><br />Connected to:<br />Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production<br />With the Partitioning, OLAP and Data Mining options<br /><br />SQL&gt;</font>
														</div>
												</div>
												<p>
														<font face="Courier New" size="2">远程使用口令文件方式登陆，失败</font>
												</p>
												<div class="hl-surround">
														<div class="hl-main">
																<font face="Courier New" size="2">D:\Oracle\SQLPlus10.2&gt; sqlplus sys/pwd@192.168.0.201/orcl as sysdba<br /><br />SQL*Plus: Release 10.2.0.4.0 - Production on Sat Jun 7 19:06:55 2008<br /><br />Copyright (c) 1982, 2007, Oracle.  All Rights Reserved.<br /><br />ERROR:<br />ORA-01017: invalid username/password; logon denied<br /><br />Enter user-name:</font>
														</div>
												</div>
												<h3>
														<font face="Courier New" size="2">2、两种认证都失效</font>
												</h3>
												<p>
														<font face="Courier New" size="2">设置SQLNET.ORA中参数SQLNET.AUTHENTICATION_SERVICES = (NONE)，REMOTE_LOGIN_PASSWORDFILE = NONE，然后进行下面的操作。</font>
												</p>
												<p>
														<font face="Courier New" size="2">本地使用下面两种方式登陆，都失败</font>
												</p>
												<div class="hl-surround">
														<div class="hl-main">
																<font face="Courier New" size="2">[oracle@RHEL4 ~]$ sqlplus / as sysdba<br /><br />SQL*Plus: Release 10.2.0.1.0 - Production on Sat Jun 7 19:22:05 2008<br /><br />Copyright (c) 1982, 2005, Oracle.  All rights reserved.<br /><br />ERROR:<br />ORA-01031: insufficient privileges<br /><br />Enter user-name:</font>
														</div>
												</div>
												<div class="hl-surround">
														<div class="hl-main">
																<font face="Courier New" size="2">[oracle@RHEL4 ~]$ sqlplus sys/pwd as sysdba<br /><br />SQL*Plus: Release 10.2.0.1.0 - Production on Sat Jun 7 19:22:46 2008<br /><br />Copyright (c) 1982, 2005, Oracle.  All rights reserved.<br /><br />ERROR:<br />ORA-01017: invalid username/password; logon denied<br /><br />Enter user-name:</font>
														</div>
												</div>
												<p>
														<font face="Courier New" size="2">远程使用口令文件方式登陆，失败</font>
												</p>
												<div class="hl-surround">
														<div class="hl-main">
																<font face="Courier New" size="2">D:\Oracle\SQLPlus10.2&gt; sqlplus sys/pwd@192.168.0.201/orcl as sysdba<br /><br />SQL*Plus: Release 10.2.0.4.0 - Production on Sat Jun 7 19:06:55 2008<br /><br />Copyright (c) 1982, 2007, Oracle.  All Rights Reserved.<br /><br />ERROR:<br />ORA-01017: invalid username/password; logon denied<br /><br />Enter user-name:</font>
														</div>
												</div>
												<h3>
														<font face="Courier New" size="2">3、验证口令文件认证</font>
												</h3>
												<p>
														<font face="Courier New" size="2">设置SQLNET.ORA中参数SQLNET.AUTHENTICATION_SERVICES = (NONE)不设置，REMOTE_LOGIN_PASSWORDFILE = EXCLUSIVE或SHARED，然后进行下面的操作。</font>
												</p>
												<p>
														<font face="Courier New" size="2">本地使用验证OS认证，失败</font>
												</p>
												<div class="hl-surround">
														<div class="hl-main">
																<font face="Courier New" size="2">[oracle@RHEL4 ~]$ sqlplus / as sysdba<br /><br />SQL*Plus: Release 10.2.0.1.0 - Production on Sat Jun 7 19:16:56 2008<br /><br />Copyright (c) 1982, 2005, Oracle.  All rights reserved.<br /><br />ERROR:<br />ORA-01031: insufficient privileges<br /><br />Enter user-name:</font>
														</div>
												</div>
												<p>
														<font face="Courier New" size="2">本地验证口令文件认证，成功</font>
												</p>
												<div class="hl-surround">
														<div class="hl-main">
																<font face="Courier New" size="2">[oracle@RHEL4 ~]$ sqlplus sys/pwd as sysdba<br />SQL*Plus: Release 10.2.0.1.0 - Production on Sat Jun 7 19:26:48 2008<br /><br />Copyright (c) 1982, 2005, Oracle.  All rights reserved.<br /><br />Connected to:<br />Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production<br />With the Partitioning, OLAP and Data Mining options<br /><br />SQL&gt;</font>
														</div>
												</div>
												<p>
														<font face="Courier New" size="2">远程使用口令文件认证，成功</font>
												</p>
												<div class="hl-surround">
														<div class="hl-main">
																<font face="Courier New" size="2">D:\Oracle\SQLPlus10.2&gt; sqlplus sys/pwd@192.168.0.201/orcl as sysdba<br /><br />SQL*Plus: Release 10.2.0.4.0 - Production on Sat Jun 7 19:21:18 2008<br /><br />Copyright (c) 1982, 2007, Oracle.  All Rights Reserved.<br /><br />Connected to:<br />Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production<br />With the Partitioning, OLAP and Data Mining options<br /><br />SYS@192.168.0.201/orcl&gt;</font>
														</div>
												</div>
												<h3>
														<font face="Courier New" size="2">4、两种认证都成功</font>
												</h3>
												<p>
														<font face="Courier New" size="2">设置SQLNET.ORA中参数SQLNET.AUTHENTICATION_SERVICES = (ALL)，REMOTE_LOGIN_PASSWORDFILE = EXCLUSIVE，然后进行下面的操作。</font>
												</p>
												<p>
														<font face="Courier New" size="2">本地使用验证OS认证，成功</font>
												</p>
												<div class="hl-surround">
														<div class="hl-main">
																<font face="Courier New" size="2">[oracle@RHEL4 ~]$ sqlplus / as sysdba<br /><br />SQL*Plus: Release 10.2.0.1.0 - Production on Sat Jun 7 19:30:33 2008<br /><br />Copyright (c) 1982, 2005, Oracle.  All rights reserved.<br /><br />Connected to:<br />Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production<br />With the Partitioning, OLAP and Data Mining options<br /><br />SQL&gt;</font>
														</div>
												</div>
												<p>
														<font face="Courier New" size="2">远程使用口令文件认证，成功</font>
												</p>
												<div class="hl-surround">
														<div class="hl-main">
																<font face="Courier New" size="2">D:\Oracle\SQLPlus10.2&gt; sqlplus sys/pwd@192.168.0.201/orcl as sysdba<br /><br />SQL*Plus: Release 10.2.0.4.0 - Production on Sat Jun 7 19:27:11 2008<br /><br />Copyright (c) 1982, 2007, Oracle.  All Rights Reserved.<br />Connected to:<br /><br />Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production<br />With the Partitioning, OLAP and Data Mining options<br /><br />SYS@192.168.0.201/orcl&gt;</font>
														</div>
												</div>
												<h3>
														<font face="Courier New" size="2">5、将SYSDBA/SYSOPER权限授权给其它数据库帐户</font>
												</h3>
												<p>
														<font face="Courier New" size="2">先查看口令文件的修改时间</font>
												</p>
												<div class="hl-surround">
														<div class="hl-main">
																<font face="Courier New" size="2">[oracle@RHEL4 dbs]$ ll orapworcl<br />-rw-r-----  1 oracle oinstall  2560 Jun  7 19:04 orapworcl</font>
														</div>
												</div>
												<p>
														<font face="Courier New" size="2">用SYS登陆数据库，创建新用户test，并赋予SYSDBA权限</font>
												</p>
												<div class="hl-surround">
														<div class="hl-main">
																<font face="Courier New" size="2">[oracle@RHEL4 dbs]$ sqlplus / as sysdba<br /><br />SQL*Plus: Release 10.2.0.1.0 - Production on Sat Jun 7 21:41:36 2008<br /><br />Copyright (c) 1982, 2005, Oracle.  All rights reserved.<br /><br />Connected to:<br />Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production<br />With the Partitioning, OLAP and Data Mining options<br /><br />SQL&gt;</font>
														</div>
												</div>
												<div class="hl-surround">
														<div class="hl-main">
																<font face="Courier New">
																		<font size="2">
																				<span style="COLOR: green">SQL</span>
																				<span style="COLOR: gray">&gt;</span>
																				<span style="COLOR: green">create</span>
																				<span style="COLOR: gray">
																				</span>
																				<span style="COLOR: green">user</span>
																				<span style="COLOR: gray">
																				</span>
																				<span style="COLOR: blue">test</span>
																				<span style="COLOR: gray">
																				</span>
																				<span style="COLOR: blue">identified</span>
																				<span style="COLOR: gray">
																				</span>
																				<span style="COLOR: green">by</span>
																				<span style="COLOR: gray">
																				</span>
																				<span style="COLOR: blue">test</span>
																		</font>
																</font>
																<font face="Courier New">
																		<font size="2">
																				<span style="COLOR: gray">;<br /></span>
																				<span style="COLOR: green">User</span>
																				<span style="COLOR: gray">
																				</span>
																				<span style="COLOR: blue">created</span>
																		</font>
																</font>
																<font face="Courier New">
																		<font size="2">
																				<span style="COLOR: gray">.<br /></span>
																				<span style="COLOR: green">SQL</span>
																				<span style="COLOR: gray">&gt;</span>
																				<span style="COLOR: green">grant</span>
																				<span style="COLOR: gray">
																				</span>
																				<span style="COLOR: blue">sysdba</span>
																				<span style="COLOR: gray">
																				</span>
																				<span style="COLOR: green">to</span>
																				<span style="COLOR: gray">
																				</span>
																				<span style="COLOR: blue">test</span>
																		</font>
																</font>
																<font face="Courier New">
																		<font size="2">
																				<span style="COLOR: gray">;<br /></span>
																				<span style="COLOR: green">Grant</span>
																				<span style="COLOR: gray">
																				</span>
																				<span style="COLOR: blue">succeeded</span>
																				<span style="COLOR: gray">.</span>
																		</font>
																</font>
														</div>
												</div>
												<div class="hl-surround">
														<div class="hl-main">
																<font face="Courier New" size="2">SQL&gt;exit<br />Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production<br />With the Partitioning, OLAP and Data Mining options</font>
														</div>
												</div>
												<p>
														<font face="Courier New" size="2">再看口令文件，已经修改了</font>
												</p>
												<div class="hl-surround">
														<div class="hl-main">
																<font face="Courier New" size="2">[oracle@RHEL4 dbs]$ ll orapworcl<br />-rw-r-----  1 oracle oinstall  2560 Jun  7 21:42 orapworcl</font>
														</div>
												</div>
												<p>
														<font face="Courier New" size="2">再用新的test帐号登陆，能成功的登陆</font>
												</p>
												<div class="hl-surround">
														<div class="hl-main">
																<font face="Courier New" size="2">D:\Oracle\SQLPlus10.2&amp;gt;sqlplus test/test@192.168.0.201/orcl as sysdba<br /><br />SQL*Plus: Release 10.2.0.4.0 - Production on Sat Jun 7 21:32:37 2008<br /><br />Copyright (c) 1982, 2007, Oracle.  All Rights Reserved.<br /><br />Connected to:<br />Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production<br />With the Partitioning, OLAP and Data Mining options<br /><br />SYS@192.168.0.201/orcl&gt;</font>
														</div>
												</div>
												<p>
														<font face="Courier New" size="2">说明：如果要取消SYSDBA权限只需要运行下面的语句就可以了</font>
												</p>
												<div class="hl-surround">
														<div class="hl-main">
																<font face="Courier New">
																		<font size="2">
																				<span style="COLOR: green">SQL</span>
																				<span style="COLOR: gray">&gt; </span>
																				<span style="COLOR: green">revoke</span>
																				<span style="COLOR: gray">
																				</span>
																				<span style="COLOR: blue">sysdba</span>
																				<span style="COLOR: gray">
																				</span>
																				<span style="COLOR: green">from</span>
																				<span style="COLOR: gray">
																				</span>
																				<span style="COLOR: blue">test</span>
																				<span style="COLOR: gray">;</span>
																		</font>
																</font>
														</div>
												</div>
												<h2>
														<font face="Courier New" size="2">常见问题说明</font>
												</h2>
												<h3>
														<font face="Courier New" size="2">1、如何查找拥有SYSDBA或是SYSOPER权限的用户</font>
												</h3>
												<p>
														<font face="Courier New" size="2">使用视图V$PWFILE_USERS，结果集中的SYSDB和SYSOP分别代表是否有SYSDBA和SYSOPER权限。</font>
												</p>
												<div class="hl-surround">
														<div class="hl-main">
																<font face="Courier New">
																		<font size="2">
																				<span style="COLOR: green">SQL</span>
																				<span style="COLOR: gray">&gt; </span>
																				<span style="COLOR: green">select</span>
																				<span style="COLOR: gray"> * </span>
																				<span style="COLOR: green">from</span>
																				<span style="COLOR: gray">
																				</span>
																				<span style="COLOR: blue">v</span>
																				<span style="COLOR: gray">$</span>
																				<span style="COLOR: blue">pwfile_users</span>
																		</font>
																</font>
																<span style="COLOR: gray">
																		<font face="Courier New" size="2">;<br /></font>
																</span>
																<span style="COLOR: #ffa500">
																		<font face="Courier New" size="2">/**<br />USERNAME                       SYSDB SYSOP<br />------------------------------ ----- -----<br />SYS                            TRUE  TRUE<br />TEST                           TRUE  FALSE<br />*/</font>
																</span>
														</div>
												</div>
												<h3>
														<font face="Courier New" size="2">2、授予权限时出现”ORA-01994: GRANT failed: password file missing or disabled”</font>
												</h3>
												<p>
														<font face="Courier New" size="2">出现这种情况是因为没有创建口令文件，或者是口令文件放置的目录不正确，Oracle找不到。只要重建或将口令文件置于$ORACLE_HOME/dbs/目录中就可以了。</font>
												</p>
												<h3>
														<font face="Courier New" size="2">3、忘记了SYS帐号的密码怎么办？</font>
												</h3>
												<p>
														<font face="Courier New" size="2">如果数据库启用的OS认证登陆，则可以用OS认证登陆数据库，然后使用下面的命令进行修改</font>
												</p>
												<div class="hl-surround">
														<div class="hl-main">
																<font face="Courier New">
																		<font size="2">
																				<span style="COLOR: green">alter</span>
																				<span style="COLOR: gray">
																				</span>
																				<span style="COLOR: green">user</span>
																				<span style="COLOR: gray">
																				</span>
																				<span style="COLOR: blue">SYS</span>
																				<span style="COLOR: gray">
																				</span>
																				<span style="COLOR: blue">identified</span>
																				<span style="COLOR: gray">
																				</span>
																				<span style="COLOR: green">by</span>
																				<span style="COLOR: gray">
																				</span>
																				<span style="COLOR: blue">pwd</span>
																				<span style="COLOR: gray">;</span>
																		</font>
																</font>
														</div>
												</div>
												<p>
														<font face="Courier New" size="2">如果没有启用OS认证登陆，则需要用orapwd重建口令文件</font>
												</p>
												<div class="hl-surround">
														<div class="hl-main">
																<font face="Courier New" size="2">orapwd file='$ORACLE_HOME/dbs/orapw$ORACLE_SID' password=pwd entries=10 force=y</font>
														</div>
												</div>
												<p>
														<font face="Courier New" size="2">其中的password项所指定的就是SYS的密码</font>
												</p>
												<h2>
														<font face="Courier New" size="2">参考文档</font>
												</h2>
												<ul>
														<li>
																<a title="http://download.oracle.com/docs/cd/B19306_01/server.102/b14231/toc.htm" href="http://download.oracle.com/docs/cd/B19306_01/server.102/b14231/toc.htm">
																		<font title="http://download.oracle.com/docs/cd/B19306_01/server.102/b14231/toc.htm" face="Courier New" size="2">Oracle® Database Administrator’s Guide 10g Release 2 (10.2)</font>
																</a>
																<font face="Courier New" size="2">
																</font>
														</li>
														<li>
																<a title="http://space.itpub.net/231499/viewspace-63849" href="http://space.itpub.net/231499/viewspace-63849">
																		<font title="http://space.itpub.net/231499/viewspace-63849" face="Courier New" size="2">小议SQLNET.AUTHENTICATION_SERVICES</font>
																</a>
																<font face="Courier New" size="2"> by space6212 </font>
														</li>
														<li>
																<a title="http://www.eygle.com/archives/2004/06/passwordfile.htm" href="http://www.eygle.com/archives/2004/06/passwordfile.htm">
																		<font title="http://www.eygle.com/archives/2004/06/passwordfile.htm" face="Courier New" size="2">Oracle中password file的作用及说明</font>
																</a>
																<font face="Courier New" size="2"> by eygle </font>
														</li>
												</ul>
										</div>
										<!--	
		-->
										<div class="postfeedback">
												<font face="Courier New" size="2">发表于 </font>
												<a title="http://www.lansz.com/html/2008/06/oracle_os_pwfile_authentication.html?m=20080608" href="http://www.lansz.com/html/2008/06/oracle_os_pwfile_authentication.html?m=20080608">
														<font title="http://www.lansz.com/html/2008/06/oracle_os_pwfile_authentication.html?m=20080608" face="Courier New" size="2">2008-06-08</font>
												</a>
												<font face="Courier New" size="2"> @ 00:37:07 · 归类于 </font>
												<a title="http://www.lansz.com/html/category/oracle/orabasics&#xA;显示Basics的所有日志" href="http://www.lansz.com/html/category/oracle/orabasics" rel="category tag">
														<font title="http://www.lansz.com/html/category/oracle/orabasics" face="Courier New" size="2">Basics</font>
												</a>
												<font face="Courier New" size="2">, </font>
												<a title="http://www.lansz.com/html/category/oracle&#xA;显示Oracle的所有日志" href="http://www.lansz.com/html/category/oracle" rel="category tag">
														<font title="http://www.lansz.com/html/category/oracle" face="Courier New" size="2">Oracle</font>
												</a>
												<font face="Courier New" size="2"> · 浏览(620) </font>
										</div>
								</div>
								<h2 id="comments">
										<font face="Courier New" size="2">
										</font> </h2>
						</div>
				</div>
		</div>
		<script type="text/javascript"><![CDATA[
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
]]&gt;</script>
		<script src="http://www.google-analytics.com/ga.js" type="text/javascript">
		</script>
		<script type="text/javascript"><![CDATA[
var pageTracker = _gat._getTracker("UA-4683432-1");
pageTracker._initData();
pageTracker._trackPageview();
]]&gt;</script>
<img src ="http://www.blogjava.net/wxqxs/aggbug/267002.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/wxqxs/" target="_blank">decode360</a> 2009-04-22 16:04 <a href="http://www.blogjava.net/wxqxs/news/2009/04/22/267002.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>甲骨文收购程序管理软件商ClearApp</title><link>http://www.blogjava.net/wxqxs/news/2008/09/05/227105.html</link><dc:creator>wxqxs</dc:creator><author>wxqxs</author><pubDate>Fri, 05 Sep 2008 00:28:00 GMT</pubDate><guid>http://www.blogjava.net/wxqxs/news/2008/09/05/227105.html</guid><wfw:comment>http://www.blogjava.net/wxqxs/comments/227105.html</wfw:comment><comments>http://www.blogjava.net/wxqxs/news/2008/09/05/227105.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/wxqxs/comments/commentRss/227105.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/wxqxs/services/trackbacks/227105.html</trackback:ping><description><![CDATA[
		<p>         【IT168技术资讯】<br />        甲骨文公司(Oracle)周二宣布，计划收购应用程序管理软件制造商ClearApp公司。 </p>
		<p>　　这桩收购案可望在今年年底前完成，目标是强化甲骨文旗下的Enterprise Manager系列产品。</p>
		<p>　　ClearApp的技术可协助客户管理依据服务导向架构(service-oriented architecture；SOA)平台而打造的应用程序。</p>
		<p>　　ClearApp的软件协助企业以更宏观的视野，一览公司以各种相关应用程序组件组成的商业服务。</p>
		<p>　　甲骨文应用程序与系统管理副总裁Leng Leng Tan说：「随着客户部署更多SOA应用程序，以更有效率的方式管理这些应用程序的任务变得更重要。」</p>
		<p>　　这笔交易的条件未对外公布。</p>
<img src ="http://www.blogjava.net/wxqxs/aggbug/227105.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/wxqxs/" target="_blank">wxqxs</a> 2008-09-05 08:28 <a href="http://www.blogjava.net/wxqxs/news/2008/09/05/227105.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>数据库设计常见10大错误 </title><link>http://www.blogjava.net/wxqxs/news/2008/08/13/221726.html</link><dc:creator>wxqxs</dc:creator><author>wxqxs</author><pubDate>Wed, 13 Aug 2008 07:24:00 GMT</pubDate><guid>http://www.blogjava.net/wxqxs/news/2008/08/13/221726.html</guid><wfw:comment>http://www.blogjava.net/wxqxs/comments/221726.html</wfw:comment><comments>http://www.blogjava.net/wxqxs/news/2008/08/13/221726.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/wxqxs/comments/commentRss/221726.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/wxqxs/services/trackbacks/221726.html</trackback:ping><description><![CDATA[
		<font size="2">　　 尽管软件发展中的热点技术层出不穷，不断地变化，有一些东西却一直未曾改变，其中之一就是开发人员对数据库的使用和设计开发。 </font>
		<p>
				<font size="2">　　 你可能会兴奋地紧跟时尚创建一个AJAX Web界面，或者使用最近迷人的Windows用户界面，但是透过这些各种各样的外观界面，你可能依然需要从后台数据库中提取或存取所需要的数据——这一点就如同十多年以前人们对数据库的操作是一样的。 </font>
		</p>
		<p>
				<font size="2">　　 然而，令人吃惊的是，现在还有很多开发者依然在不断地重复着很多年以前就存在的数据库使用和开发上的错误。或许是有太多的开发者只是来学习如何使用一个数据库，而不是真正的去研究它。以下是笔者作为一个开发者，个人在平时的开发工作中所精选出的数据库开发者常犯的十大错误，以飨读者和同行。 </font>
		</p>
		<p>
				<font size="2">　　 <strong>1、选择了错误的数据库 </strong></font>
		</p>
		<p>
				<font size="2">　　 不是所有的数据库都可以用来完成你的任务，这意味着当你在使用数据库来做任何开发工作和其他事情前，你必须选择合适的数据库。例如，我们经常看到一些Access数据库没有能力处理的大容量数据集，对于SQL Server来说却像玩小孩子的游戏一样轻松地完成处理。但是，对于只需要处理几百行数据的需求，有的人却花钱来购买SQL Server。这些都是错误的做法。 </font>
		</p>
		<p>
				<font size="2">　　 广泛地来说，在当今市场中的数据库可以分为三个层次：桌面和嵌入数据库——适合于处理小型任务；一些大型数据库产品的“Express”版也是不错的，可以处理数G条数据；而真正的企业级数据库，像SQL Server、Oracle和DB2的数据处理能力是非常惊人的，你可以毫不犹豫地把数据抛给它们。 </font>
		</p>
		<p>
				<font size="2">　　 因此，在你选择数据库前，你需要对于你的数据进行一次客观真实的分析，从而选择适合你的开发工作和实际需求的数据库产品。 </font>
		</p>
		<p>
				<font size="2">　　 <strong>2、选择了太多的数据库 </strong></font>
		</p>
		<p>
				<font size="2">　　 诸如ODBC、JDBC和OLEDB等应用程序编程接口的出现，大大促进和提升了数据库独立性，也就是说，开发人员可以这样来编写你的应用程序：你可以让你的应用程序支持使用任何数据库来进行数据存储。 </font>
		</p>
		<p>
				<font size="2">　　 然而，这种情况是要付出一些代价的，我曾经看到有的开发团队为了追求应用程序的数据库“无关性”，专门编写了应用程序将所有的SQL语句转换成一些底层的语言，以便让所有的数据库都能理解并执行，但是，这样做的同时也丧失了现有数据库的一些高级功能。 </font>
		</p>
		<p>
				<font size="2">　　 那么为什么这么做呢？可能是出于这样的考虑：某些客户在将来的使用中可能想切换到Oracle或DB2或FoxPro，或其他的什么数据库，采用上面的这种做法或许是现在先准备好了，“未雨绸缪”。 </font>
		</p>
		<p>
				<font size="2">　　 对于此，另一种相反的做法是：当你开始开发一个新产品的时候，选择一个存储引擎并开始在此基础上编写你的应用程序。如果你的产品足够好，人们会安装你指定的数据库，因此你不用浪费时间和精力来支持一种“假想”的用户需求。 </font>
		</p>
		<p>
				<font size="2">　　 <strong>3、了解你的数据 </strong></font>
		</p>
		<p>
				<font size="2">　　 在我们使用数据库的过程中会碰到很多需要考虑的问题，例如有些客户编号可能并不是我们通常认为的七位，而是六位；而有一些公司和企业出于保护个人隐私的考虑，可能不一定非要求员工输入他们的身份证号码或者银行帐号，因此这中数据类型在数据库搭建和开发中必须设置成可以为空（NULL）。 </font>
		</p>
		<p>
				<font size="2">　　 也就是说，数据库开发和设计不能脱离实际情况进行，不能远离实际业务规则。对数据库开发者来说，必须要完全了解用户真正输入数据的需求是什么，并根据这些数据来合理地设计数据字段的大小、类型以及什么规则，等等。否则，等待你的将是一次又一次地返回头来进行修改工作。因此，你要学会在开始的时候就对你需要处理的数据具有非常全面、深入的了解，要尽量考虑到各种意外的情况。 </font>
		</p>
		<p>
				<font size="2">　　 <strong>4、数据库不像Excel一样人人会用 </strong></font>
		</p>
		<p>
				<font size="2">　　 现在有一种认识上的误区，尤其是在一些小单位的管理者眼中，他们总认为任何开发者都知道如何去合理地搭建一个数据库。 </font>
		</p>
		<p>
				<font size="2">　　 很明显，这种误解让我很困惑。既然你不会假定任何开发者都知道如何用C#编程或创建一个Web服务，那么为什么要假定每个开发者都是数据库专家呢？ </font>
		</p>
		<p>
				<font size="2">　　 这种假设所带来的最后结果是，太多的数据库被一些甚至从来没有听说过术语规范化（term normalization）的人所设计。很多数据库的功能根本没有被合理地运用，如果你是这样一个开发者的话，那么在你设计数据库之前，你需要加强这方面的培训和学习了。高效的数据库设计是你必须了解和掌握的技巧，而不要奢望可以通过失败的教训来了解到这一点。 </font>
		</p>
		<p>
				<font size="2">　　 <strong>5、第三范式并不是至高无上 </strong></font>
		</p>
		<p>
				<font size="2">　　 另一方面，开发人员对数据库的一知半解可能是一件比较危险的事情。我看到过很多数据库被设计得过于死板，这些数据库的设计者坚持把所有东西都放在查询表中。 </font>
		</p>
		<p>
				<font size="2">　　 是的，数据库开发者需要知道规范化的规则，但是你也需要知道什么时候要停止去用规范化，什么时候逆规范化反而可能会带来更好的效果。</font>
		</p>
		<div>
				<font size="2"> <strong>6、隐藏应用逻辑的“黑匣子”</strong> <br /><br />    存储过程和触发器是两个非常伟大的功能。当你有多个客户访问一个数据库的时候，它们可以帮助你确保对数据的一致性处理。 <br /><br />    不过，它们也可能会变成一个隐藏应用逻辑的“黑匣子”，让Web和瘦客户端开发者无法查看和调试这些逻辑。在大多数情况下，数据库代码不能像其他应用程序代码一样被进行代码测试和代码调试。 <br />    <br />因此，当你要将代码放到数据库中的时候，花点时间来问一下自己：这些代码是否真的适合放在数据库中？ <br /><br />  </font>
				<font size="2">
						<strong>  7、备份！备份！备份！ <br /></strong>
						<br />    你的数据库需要备份吗？当然需要！ <br /><br />    我们为什么要把数据存在数据库中的原因之一就是想长久地保存它们。然而，我却经常碰到这样的情况，有的开发人员却因为这样或那样的原因——例如硬件故障、黑客或数据库错误——因为没有备份而导致珍贵的数据永远丢失。因此在你开始开发之前，就应该制定一个数据备份计划，包括备份的频率、备份的类型，以及离线备份的频率等等，而不应该在数据丢失后才想起备份的重要。 <br /><br />    我不希望“亡羊补牢”的故事发生在各位数据库程序员的身上。 <br /><br />   </font>
				<font size="2">
						<strong> 8、你需要版本控制 <br /></strong>
						<br />    说到备份，你需要担心的不仅仅是数据的变化，还有数据库的修改。你需要跟踪并记录下这些数据库版本的变化，以便在任何需要的时候重新创建这个数据库。如果你想真正专业化的开发软件，你需要在你的数据库设计中增加版本控制。 <br /><br />    举个例子来说，如果你想调试某个软件版本中的客户漏洞，但是你无法恢复到该软件版本所对应的数据库版本的话，调试可能不会正常进行。因此数据库开发者必须要做好版本控制，否则可能因此带来很多以后的麻烦。 <br /><br />    <strong>9、使用数据库自带的工具</strong> <br /><br />    现代数据库中已经不仅仅是一些让你存放数据的工具。它们还具有很多潜在的工具来使得管理数据库更容易。 <br /><br />    举个例子来说，SQL Server中有工具可以检测SQL语句中潜在的攻击，甚至包括了一个向导，来告诉你该使用什么样的索引才能使你的查询上更高效，甚至可以模拟在真实服务器上的实际负载。 <br /><br />    通过这些工具，我们的确在有的时候加速了数据库运行的速度，降低了CPU的利用率，但是实际情况是，很多人只有在一些专家顾问告诉他们后才知道在数据库中存在这样的工具。如果你不知道在你的数据库中存在什么样的工具，以及这些工具能帮你做什么，那么你花的钱就没有得到应有的回报。 <br /><br /> </font>
				<font size="2">
						<strong>   10、不要因为你有一个锤子就认为什么都是钉子 <br /><br /></strong>    现在有一种潮流，一些开发人员把应用程序用到的所有数据都存储在数据库中。我曾经看到有的应用程序试图创建一个完全数据元驱动（metadata-driven）的用户界面，它把元数据和用户偏好的数据都存放在相同的数据库中。显然这会让开发人员的生活变得复杂和降低性能。 <br /><br />    某些数据可能的确适合存放在本地文件中，而不是存放在网络的客户—服务器数据库中。当你存储数据的时候，你需要分析一下你的数据适合存放在什么地方，是数据库？注册表？文本文件？还是XML文件？然后为其选择最适合的存储类型。“不要因为你有一个锤子就认为什么都是钉子”，不要因为有一个数据库，就把所有东西都扔到数据库中——现在还存在一种对XML文件的过度滥用，也是同样的情况。</font>
		</div>
<img src ="http://www.blogjava.net/wxqxs/aggbug/221726.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/wxqxs/" target="_blank">wxqxs</a> 2008-08-13 15:24 <a href="http://www.blogjava.net/wxqxs/news/2008/08/13/221726.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>