Apress.Expert.Oracle.Database.Architecture.9i.and.10g.Programming.Techniques.and.Solutions.Sep.2005

rekharaghuram
from rekharaghuram More from this publisher
05.11.2015 Views

CHAPTER 3 ■ FILES 103 Password Files The password file is an optional file that permits remote SYSDBA or administrator access to the database. When you attempt to start up Oracle, there is no database available that can be consulted to verify passwords. When you start up Oracle on the “local” system (i.e., not over the network, but from the machine the database instance will reside on), Oracle will use the OS to perform the authentication. When Oracle was installed, the person performing the installation was asked to specify the “group” for the administrators. Normally on UNIX/Linux, this group will be DBA by default and OSDBA on Windows. It can be any legitimate group name on that platform, however. That group is “special,” in that any user in that group can connect to Oracle “as SYSDBA” without specifying a username or password. For example, in my Oracle 10g Release 1 install, I specified an ora10g group. Anyone in the ora10g group may connect without a username/password: [ora10g@localhost ora10g]$ sqlplus / as sysdba SQL*Plus: Release 10.1.0.3.0 - Production on Sun Jan 2 20:13:04 2005 Copyright (c) 1982, 2004, Oracle. All rights reserved. Connected to: Oracle Database 10g Enterprise Edition Release 10.1.0.3.0 - Production With the Partitioning, OLAP and Data Mining options SQL> show user USER is "SYS" That worked—I’m connected, and I could now start up this database, shut it down, or perform whatever administration I wanted to. However, suppose I wanted to perform these operations from another machine, over the network. In that case, I would attempt to connect using @tns-connect-string. However, this would fail: [ora10g@localhost admin]$ sqlplus /@ora10g_admin.localdomain as sysdba SQL*Plus: Release 10.1.0.3.0 - Production on Sun Jan 2 20:14:20 2005 Copyright (c) 1982, 2004, Oracle. All rights reserved. ERROR: ORA-01031: insufficient privileges Enter user-name: OS authentication won’t work over the network for SYSDBA, even if the very unsafe (for security reasons) parameter REMOTE_OS_AUTHENT is set to TRUE. So, OS authentication won’t work and, as discussed earlier, if you’re trying to start up an instance to mount and open a database, then there by definition is “no database” at the other end of the connection yet, in which to look up authentication details. It is the proverbial chicken and egg problem. Enter the password file. The password file stores a list of usernames and passwords that are allowed to remotely authenticate as SYSDBA over the network. Oracle must use this file to authenticate them and not the normal list of passwords stored in the database. So, let’s correct our situation. First, we’ll start up the database locally so we can set the REMOTE_LOGIN_PASSWORDFILE. Its default value is NONE, meaning there is no password file; there

104 CHAPTER 3 ■ FILES are no “remote SYSDBA logins.” It has two other settings: SHARED (more than one database can use the same password file) and EXCLUSIVE (only one database uses a given password file). We’ll set ours to EXCLUSIVE, as we want to use it for only one database (i.e., the normal use): SQL> alter system set remote_login_passwordfile=exclusive scope=spfile; System altered. This setting cannot be changed dynamically while the instance is up and running, so we’ll have to restart for this to take effect. The next step is to use the command-line tool (on UNIX and Windows) named orapwd: [ora10g@localhost dbs]$ orapwd Usage: orapwd file= password= entries= force= where file - name of password file (mand), password - password for SYS (mand), entries - maximum number of distinct DBA and OPERs (opt), force - whether to overwrite existing file (opt), There are no spaces around the equal-to (=) character. to create and populate the initial password file. The command we’ll use is $ orapwd file=orapw$ORACLE_SID password=bar entries=20 That created a password file named orapwora10g in my case (my ORACLE_SID is ora10g). That is the naming convention for this file on most UNIX platforms (see your installation/OS admin guide for details on the naming of this file on your platform), and it resides in the $ORACLE_HOME/dbs directory. On Windows, this file is named PW%ORACLE_SID%.ora and is located in the %ORACLE_HOME%\database directory. Now, currently the only user in that file is in fact the user SYS, even if there are other SYSDBA accounts on that database (they are not in the password file yet). Using that knowledge, however, we can for the first time connect as SYSDBA over the network: [ora10g@localhost dbs]$ sqlplus sys/bar@ora10g_admin.localdomain as sysdba SQL*Plus: Release 10.1.0.3.0 - Production on Sun Jan 2 20:49:15 2005 Copyright (c) 1982, 2004, Oracle. All rights reserved. Connected to an idle instance. SQL> We have been authenticated, so we are in—we can now successfully start up, shut down, and remotely administer this database using the SYSDBA account. Now, we have another user, OPS$TKYTE, who has been granted SYSDBA, but will not be able to connect remotely yet: [ora10g@localhost dbs]$ sqlplus 'ops$tkyte/foo' as sysdba SQL*Plus: Release 10.1.0.3.0 - Production on Sun Jan 2 20:51:07 2005 Copyright (c) 1982, 2004, Oracle. All rights reserved. Connected to: Oracle Database 10g Enterprise Edition Release 10.1.0.3.0 - Production With the Partitioning, OLAP and Data Mining options SQL> show user

104<br />

CHAPTER 3 ■ FILES<br />

are no “remote SYSDBA logins.” It has two other settings: SHARED (more than one database can<br />

use the same password file) <strong>and</strong> EXCLUSIVE (only one database uses a given password file).<br />

We’ll set ours to EXCLUSIVE, as we want to use it for only one database (i.e., the normal use):<br />

SQL> alter system set remote_login_passwordfile=exclusive scope=spfile;<br />

System altered.<br />

This setting cannot be changed dynamically while the instance is up <strong>and</strong> running, so we’ll<br />

have to restart for this to take effect. The next step is to use the comm<strong>and</strong>-line tool (on UNIX<br />

<strong>and</strong> Windows) named orapwd:<br />

[ora10g@localhost dbs]$ orapwd<br />

Usage: orapwd file= password= entries= force=<br />

where<br />

file - name of password file (m<strong>and</strong>),<br />

password - password for SYS (m<strong>and</strong>),<br />

entries - maximum number of distinct DBA <strong>and</strong> OPERs (opt),<br />

force - whether to overwrite existing file (opt),<br />

There are no spaces around the equal-to (=) character.<br />

to create <strong>and</strong> populate the initial password file. The comm<strong>and</strong> we’ll use is<br />

$ orapwd file=orapw$ORACLE_SID password=bar entries=20<br />

That created a password file named orapwora10g in my case (my ORACLE_SID is ora10g).<br />

That is the naming convention for this file on most UNIX platforms (see your installation/OS<br />

admin guide for details on the naming of this file on your platform), <strong>and</strong> it resides in the<br />

$ORACLE_HOME/dbs directory. On Windows, this file is named PW%ORACLE_SID%.ora <strong>and</strong> is located<br />

in the %ORACLE_HOME%\database directory.<br />

Now, currently the only user in that file is in fact the user SYS, even if there are other<br />

SYSDBA accounts on that database (they are not in the password file yet). Using that knowledge,<br />

however, we can for the first time connect as SYSDBA over the network:<br />

[ora10g@localhost dbs]$ sqlplus sys/bar@ora10g_admin.localdomain as sysdba<br />

SQL*Plus: Release 10.1.0.3.0 - Production on Sun Jan 2 20:49:15 2005<br />

Copyright (c) 1982, 2004, <strong>Oracle</strong>. All rights reserved.<br />

Connected to an idle instance.<br />

SQL><br />

We have been authenticated, so we are in—we can now successfully start up, shut down,<br />

<strong>and</strong> remotely administer this database using the SYSDBA account. Now, we have another user,<br />

OPS$TKYTE, who has been granted SYSDBA, but will not be able to connect remotely yet:<br />

[ora10g@localhost dbs]$ sqlplus 'ops$tkyte/foo' as sysdba<br />

SQL*Plus: Release 10.1.0.3.0 - Production on Sun Jan 2 20:51:07 2005<br />

Copyright (c) 1982, 2004, <strong>Oracle</strong>. All rights reserved.<br />

Connected to:<br />

<strong>Oracle</strong> <strong>Database</strong> 10g Enterprise Edition Release 10.1.0.3.0 - Production<br />

With the Partitioning, OLAP <strong>and</strong> Data Mining options<br />

SQL> show user

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!