OCA /OCP Oracle Database 11g A ll-in-One Exam Guide- P20 potx

10 292 0
OCA /OCP Oracle Database 11g A ll-in-One Exam Guide- P20 potx

Đang tải... (xem toàn văn)

Thông tin tài liệu

OCA/OCP Oracle Database 11g All-in-One Exam Guide 146 user interface. For all the commands, you must specify the name of the listener, if it is not the default name of LISTENER. Figures 4-6 and 4-7 show how to check the status of a listener and to stop and start it, issuing the commands either from the operating system prompt or from within the user interface. Note that the status command always tells you the address on which the listener accepts connection requests, the name and location of the listener.ora file that defines the listener, and the name and location of the log file for the listener. Also, in the examples shown in the figures, the listener LIST2 “supports no services.” This is because there are no services statically registered in the listener.ora file for that listener, and no instances have dynamically registered either. Figure 4-8 uses the services command to show the state of the listener after an instance has registered dynamically. Figure 4-6 Using lsnrctl commands from the operating system prompt to check the status and then start the listener LIST2 Chapter 4: Oracle Networking 147 PART I Figure 4-7 Using the lsnrctl user interface to check the status and then stop the listener LIST2 Figure 4-8 The services command shows the services for which the listener will accept connections. OCA/OCP Oracle Database 11g All-in-One Exam Guide 148 In Figure 4-8, the output of the status command tells you that the listener called LISTENER supports three services, all available on the instance orcl11g: • Service orcl11g.jwlnx1.bplc.co.za is the regular database service. The listener can launch dedicated server sessions against it (it hasn’t launched any yet). • Service orcl11gXDB.jwlnx1.bplc.co.za is the XML database protocol server. This lets users connect to the database with protocols other than Oracle NET, such FTP and HTTP. • Service orcl11g_XPT.jwlnx1.bplc.co.za has to do with Dataguard. By default, an 11g database instance will register the XDP and XPT services, but they cannot be used without considerable further configuration. The fact that the services are shown to be “status ready” indicates that they were automatically registered by the PMON process: the listener knows they are ready because PMON said they were. If the services has been statically registered, they would be marked as “status unknown,” indicating that while they are in the listener.ora file, they may not in fact be working. To see all the lsnrctl commands, use the HELP command: C:\>lsnrctl help LSNRCTL for 32-bit Windows: Version 11.1.0.4.0 - Beta on 26-NOV-2007 17:47:16 Copyright (c) 1991, 2006, Oracle. All rights reserved. The following operations are available An asterisk (*) denotes a modifier or extended command: start stop status services version reload save_config trace change_password quit exit set* show* In summary, these commands are • START Start a listener. • STOP Stop a listener. • STATUS See the status of a listener. • SERVICES See the services a listener is offering (fuller information than STATUS). • VERSION Show the version of a listener. • RELOAD Force a listener to reread its entry in listener.ora. • SAVE_CONFIG Write any changes made online to the listener.ora file. • TRACE Enable tracing of a listener’s activity. • CHANGE_PASSWORD Set a password for a listener’s administration. • QUIT Exit from the tool without saving changes to the listener.ora file. • EXIT Exit from the tool and save changes to the listener.ora file. • SET Set various options, such as tracing and timeouts. • SHOW Show options that have been set for a listener. Chapter 4: Oracle Networking 149 PART I Note that all these commands should be qualified with the name of the listener to which the command should be applied. If a name is not supplied, the command will be executed against the listener called LISTENER. Configuring Service Aliases Having decided what name resolution method to use, your next task is to configure the clients to use it. You can do this through Database Control, but since Database Control is a server-side process, you can use it only to configure clients running on the database server. An alternative is to use the Net Manager. This is a stand-alone Java utility, shipped with all the Oracle client-side products. To launch the Net Manager, run netmgr from a Unix prompt, or on Windows you will find it on the Start menu. The Net Manager navigation tree has three branches. The Profile branch is used to set options that may apply to both the client and server sides of Oracle Net and can be used to influence the behavior of all Oracle Net connections. This is where, for example, you can configure detailed tracing of Oracle Net sessions. The Service Naming branch is used to configure client-side name resolution, and the Listeners branch is used to configure database listeners. When you select the Profile branch as shown in Figure 4-9, you are in fact configuring a file called sqlnet.ora. This file exists by default in your ORACLE_ HOME/network/admin directory. It is optional, as there are defaults for every sqlnet.ora directive, but you will usually configure it if only to select the name resolution method. Figure 4-9 Net Manager’s Profile editor OCA/OCP Oracle Database 11g All-in-One Exam Guide 150 In the Profile branch, you will see all the available naming methods, with three (TNSNAMES and EZCONNECT and HOSTNAME) selected by default: these are Local Naming and Easy Connect and Host Naming. The external methods are NIS and CDS. LDAP is Directory Naming. Host Naming is similar to Easy Connect and retained for backward compatibility. Then you need to configure the individual Oracle Net service aliases. This is done in the Service Naming branch, which in fact creates or edits the Local Naming tnsnames.ora file that resides by default in your ORACLE_HOME/network/admin directory. If you are fortunate enough to be using Directory Naming, you do not need to do this; choosing LDAP in the Profile as your naming method is enough. A typical entry in the tnsnames.ora file would be OCP11G = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = jwacer.bplc.co.za)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = ocp11g) ) ) If a user enters the connect string “ocp11g”, this entry will resolve the name to a listener running on the address jwlnx1.bplc.co.za monitoring port 1521, and ask the listener for a session against an instance offering the service ocp11g. To connect with this, use sqlplus system/oracle@ocp11g The equivalent with Easy Connect would be sqlplus system/manager@jwacer.bplc.co.za:1521/ocp11g To test a connect string, use the TNSPING utility. This will accept a connect string, locate the Oracle Net files, resolve the string, and send a message to the listener. If the listener is running and does know about the service requested, the test will return successfully. For example, C:\> tnsping ocp11g TNS Ping Utility for 32-bit Windows: Version 11.1.0.4.0 - Beta on 27-NOV-2007 11 :49:55 Copyright (c) 1997, 2006, Oracle. All rights reserved. Used parameter files: D:\oracle\app\product\11.1.0\db_3\network\admin\sqlnet.ora Used TNSNAMES adapter to resolve the alias Attempting to contact (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP) (HOST = 127.0.0.1)(PORT = 2521))) (CONNECT_DATA = (SERVICE_NAME = ocp11g))) OK (40 msec) Chapter 4: Oracle Networking 151 PART I Note that the output of TNSPING shows the sqlnet.ora file used, the name resolution method used, and then the details of the address contacted. The tool does not go further than the listener; it will not check whether the instance is actually working. Filenames and the TNSADMIN Environment Variable There are three critical files involved in configuring Oracle Net: • The listener.ora file is a server-side file that defines database listeners. It includes the protocols, addresses, and ports on which they will listen for incoming connection requests, and (optionally) a hard-coded list of instances against which they will launch sessions. • The tnsnames.ora file is a client-side file used for name resolution. It is used by user processes to locate database listeners. It may also be used by the instance itself, to locate a listener with which to register. • The sqlnet.ora file is optional and may exist (possibly with different settings) on the server side, the client side, or both. It contains settings that apply to all connections and listeners, such as security rules and encryption. The three Oracle Net files by default exist in the directory ORACLE_HOME/network/ admin. It is possible to relocate them with an environment variable: TNS_ADMIN. An important use of this is on systems that have several Oracle Homes. This is a very common situation. A typical Oracle server machine will have at least three homes: one for the Enterprise Manager Grid Control Agent, one for launching database instances, and one for launching Automatic Storage Management (ASM) instances. (ASM is covered in the second OCP examination.) Client machines may well have several Oracle Homes as well, perhaps one each for the 10g and11g clients. Setting the TNS_ADMIN variable to point to one set of files in one of the Oracle home directories (or indeed in a different directory altogether) means that instead of having to maintain multiple sets of files, you need maintain only one set. To set the variable, on Windows you can use the SET command to set it for one session, set TNS_ADMIN=c:\oracle\net though it will usually be better to set it in the registry, as a string value key in the Oracle Home branch. On Linux and Unix, the syntax will vary depending on the shell, but something like this will usually do: set TNS_ADMIN=/u01/oracle/net; export TNS_ADMIN This command could be placed in each user’s .profile file, or in the /etc/ profile where every user will pick it up. Figure 4-10 traces the flow of logic utilized to resolve a typical client connection request. OCA/OCP Oracle Database 11g All-in-One Exam Guide 152 Figure 4-10 Typical resolution logic for client connection request Chapter 4: Oracle Networking 153 PART I A user typically initiates a connection to the database server by providing a username, a password, and a connect string. If a connect string is absent, the Oracle Net client layer tries to use the ORACLE_SID environment variable or registry variable as a default connect string value. If this is not set, an error usually results. If a connect string is available, the Oracle Net client then tries to figure out what mechanism to utilize to resolve the connect string and it does this by trying to locate the relevant sqlnet.ora file, either in the directory specified by the TNS_ADMIN variable or in the ORACLE_HOME/network/admin directory. If neither the TNS_ADMIN nor ORACLE_HOME variable is set, an error is returned. Typically, sqlnet.ora contains a NAMES.DIRECTORY_PATH directive, which lists, in order of preference, the different connection name resolution mechanisms, like TNSNAMES, LDAP, and EZCONNECT. If TNSNAMES is listed as the first preferred mechanism, Oracle Net then tries to locate the infamous tnsnames.ora file either in the directory specified by the TNS_ADMIN variable or in the ORACLE_HOME/ network/admin directory. The tnsnames.ora file is then used to obtain the network address of the connection string, typically yielding a hostname:port:sid or hostname:port:servicename triad. The Oracle Net client is finally in a position to bind the user process that initiated the connection to the database server. If the connection string contained the “@” symbol, then the listener on the hostname is contacted on the relevant port, for access to the specified instance or service. If the listener is functioning correctly, the user process tries to negotiate a server connection, or else an error is returned. If the connection string does not contain the “@” symbol, a local IPC connection is attempted. If the instance or service is available on the same server as the client user process, then the connection may be successfully made. Database Links So far, Oracle Net has been discussed in the context of users connecting to database instances. Oracle Net can also be used for communications between databases: a user session against one database can execute SQL statements against another database. This is done through a database link. There are several options for creating database links (all to do with security), but a simple example is create database link prodstore connect to store identified by admin123 using 'prod'; This defines a database link from the current database to a remote database identified by the connect string PROD. The link exists in and can only be used by the current user’s schema. When a statement such as select * from orders@prodstore; is issued, the user’s session will launch a session against the remote database, log on to it transparently as user STORE, and run the query there. The results will be sent back to the local database and then returned to the user. OCA/OCP Oracle Database 11g All-in-One Exam Guide 154 Any SQL statements can be executed through a link, provided that the schema to which the link connects has appropriate permissions. For example, consider this scenario: There is a production database, identified by the connect string PROD, which contains a schema STORE, with two tables: ORDERS and PRODUCTS. There is a link to this database as just defined. There is also a development database, identified by the connect string DEV, which also contains the schema STORE. You are connected to a third database called TEST. You need to update the development schema with the production data. First, define a database link to the development database: create database link devstore connect to store identified by devpasswd using 'dev'; Then update the development schema to match the production schema: truncate table orders@devstore; truncate table customers@devstore; insert into orders@devstore select * from orders@prodstore; insert into customers@devstore select * from customers@prodstore; commit; To check whether any rows have been inserted in the production system since the last refresh of development and, if so, insert them into development, you could run this statement: insert into orders@devstore (select * from orders@prodstore minus select * from orders@devstore); If it were necessary to change the name of a customer, you could do it in both databases concurrently with update customers@prodstore set customer_name='Coda' where customer_id=10; update customers@devstore customer_name='Coda' where customer_id=10; commit; When necessary, Oracle will always implement a two-phase commit to ensure that a distributed transaction (which is a transaction that affects rows in more than one database) is treated as an atomic transaction: the changes must succeed in all databases or be rolled back in all databases. Read consistency is also maintained across the whole environment. Exercise 4-1: Configure Oracle Net In this exercise, you will set up a complete Oracle Net environment, using graphical and command-line tools. Differences between Windows and Linux will be pointed out. 1. Create a directory to be used for the Oracle Net configuration files, and set the TNS_ADMIN variable to point to this. It doesn’t matter where the directory is, as long as the Oracle user has permission to create, read, and write it. On Linux: mkdir /u01/oracle/net export TNS_ADMIN=/u01/oracle/net Chapter 4: Oracle Networking 155 PART I Ensure that all work from now is done from a session where the variable has been set. On Windows: mkdir d:\oracle\net Create and set the key TNS_ADMIN as a string variable in the registry in the Oracle Home branch. This will typically be HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\KEY_OraDb11g_home1 2. Check that the variable is being read by using the TNSPING command from an operating system prompt: tnsping orcl This will return an error “TNS-03505: Failed to resolve name” because there are no files in the TNS_ADMIN directory. On Windows, you may need to launch a new command prompt to pick up the new TNS_ADMIN value from the registry. 3. Start the Net Manager. On Linux, run netmgr from an operating system prompt; on Windows, launch it from the Start menu. The top line of the Net Manager window will show the location of the Oracle Net files. If this is not the new directory, then the TNS_ADMIN variable has not been set correctly. 4. Create a new listener: expand the Local branch of the navigation tree, highlight Listeners, and click the + icon. 5. Enter a listener name, NEWLIST, and click OK. 6. Click Add Address. 7. For Address 1, choose TCP/IP as the protocol and enter 127.0.0.1 as the host, 2521 as the port. The illustration that follows shows the result. . in more than one database) is treated as an atomic transaction: the changes must succeed in all databases or be rolled back in all databases. Read consistency is also maintained across the. transparently as user STORE, and run the query there. The results will be sent back to the local database and then returned to the user. OCA/ OCP Oracle Database 11g All-in-One Exam Guide 154 Any. simple example is create database link prodstore connect to store identified by admin123 using 'prod'; This defines a database link from the current database to a remote database identified

Ngày đăng: 06/07/2014, 13:20

Từ khóa liên quan

Mục lục

  • Contents

  • Introduction

  • Part I: Oracle Database 11g Administration

    • Chapter 1 Architectural Overview of Oracle Database 11g

      • Exam Objectives

      • Oracle Product Stack

      • Prerequisite Concepts

      • Single-Instance Architecture

      • Instance Memory Structures

      • Instance Process Structures

      • Database Storage Structures

      • Two-Minute Drill

      • Self Test

      • Self Test Answers

      • Chapter 2 Installing and Creating a Database

        • Exam Objectives

        • Identify the Tools for Administering an Oracle Database

        • Plan an Oracle Database Installation

        • Install the Oracle Software by Using the Oracle Universal Installer (OUI)

        • Create a Database by Using the Database Configuration Assistant

        • Two-Minute Drill

        • Self Test

        • Self Test Answers

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan