Presentation is loading. Please wait.

Presentation is loading. Please wait.

Enabling Distributed Transactions

Similar presentations


Presentation on theme: "Enabling Distributed Transactions"— Presentation transcript:

1 Enabling Distributed Transactions

2 Oracle Database 10g: Administration Workshop II 4-2
Objectives After completing this lesson, you should be able to: Verify network configuration Explain the differences between remote transactions and distributed transactions Establishing communication between databases through database links Oracle Database 10g: Administration Workshop II 4-2

3 Oracle Net Services Review
Application Oracle Net RDBMS Oracle Net Listener TCP/IP network Client Database server sqlnet.ora tnsnames.ora listener.ora Oracle Net Services Review Oracle Net is a component of Oracle Net Services. It resides on the client computer and the Oracle Database server. Oracle Net is responsible for establishing and maintaining the connection between the client application and the server, as well as exchanging messages between them using industry-standard protocols. The listener is a separate process that runs on the database server computer. It receives incoming client connection requests and forwards these requests to the target database service. A single listener can listen on behalf of multiple databases, and multiple listeners can listen on behalf of a single database to perform load balancing. A listener is configured with one or more listening protocol addresses, information about supported services, and parameters that control its run-time behavior. The listener configuration is stored in a configuration file named listener.ora. When you install the Enterprise or Standard Edition of Oracle Database, Oracle Net Configuration Assistant automatically configures a default listener named LISTENER with a TCP/IP listening protocol address. During a custom installation, Oracle Net Configuration Assistant prompts you to provide a listener name and protocol address. For all installations, a listening IPC protocol address for external procedure calls is automatically configured. Oracle Database 10g: Administration Workshop II 4-3

4 Connecting to an Oracle Database
finance.us.flowers.com Database server Connecting to an Oracle Database A service is a network resource that performs work on behalf of clients. A database can have one or more services associated with it. You can also have a service that represents multiple database instances. To represent a database as a service, you use a service name, a logical representation of a database. The service name is typically the same as the global database name, a name comprising the database name and domain name. If you are not sure what the global database name is, you can obtain it from the value of the database initialization parameter SERVICE_NAMES or by querying the GLOBAL_NAME data dictionary view. To connect to a database service, clients use a connect descriptor that provides the location of the database and the name of the database service. The following example shows a connect descriptor that enables clients to connect to a database service called finance.us.flowers.com. (DESCRIPTION= (ADDRESS=(PROTOCOL=tcp)(HOST=flowers-server)(PORT=1521)) (CONNECT_DATA= (SERVICE_NAME=finance.us.flowers.com))) Oracle Database 10g: Administration Workshop II 4-4

5 Client Application Connectivity to the Oracle Server
flowers-server Oracle Database finance.us. flowers.com Network Connection sqlplus Client Application Connectivity to the Oracle Server Users initiate a connection request by providing a connect string. A connect string includes a username and password, appended with a universal followed by a connect identifier. A connect identifier can be the connect descriptor itself or a name that resolves to a connect descriptor. One of the most common connect identifiers is a net service name, a simple name for a service. You can store net service names in: A local network configuration file named tnsnames.ora A centralized LDAP-compliant directory server A supported non-Oracle naming service, such as Network Information Service (NIS) External Naming or Distributed Computing Environment (DCE) Cell Directory Services (CDS) You can also use Easy Connect for the connect identifier. A connect identifier that uses Easy Connect would take the form of: <hostname>:<listener port>/<service name> The listener port and service name are optional. If the listener port is not provided, then Oracle Net assumes the default port of 1521 is being used. If the service name is not provided Oracle Net assumes the database service name is the same as the specified host name. Oracle Database 10g: Administration Workshop II 4-5

6 Server-Server Connectivity
Detroit CREATE DATABASE LINK fin_flowers CONNECT TO hr IDENTIFIED BY hr USING 'FINANCE'; SELECT * FROM Oracle Net Physical Network Link Pittsburgh Oracle Net Server-Server Connectivity A database link defines a communication path from one database to another. When an application uses a database link to access a remote database, the Oracle database establishes a session in the remote database on behalf of the local application request. Database links are referenced as part of a table name in a remote or distributed SQL statement. The above example shows a remote query using the database link fin_flowers. The user session connected to the Detroit database retrieves data from the FINANCE database in Pittsburgh using a database link and Oracle Net. Oracle Database 10g: Administration Workshop II 4-6

7 Types of Database Links
Database links have three dimensions: Global, public, and private Fixed user, connected user, current user Shared or nonshared Types of Database Links When you create a private or public database link, you can determine which schema on the remote database the link will establish connections to by creating fixed user, current user, and connected user database links. Global links are defined when using Oracle Names Server and are not covered in this course. Shared and nonshared links are covered in the Oracle9i Database: Distributed Systems eStudy class. Oracle Database 10g: Administration Workshop II 4-7

8 Creating Database Links
3 2 Creating Database Links You can use the Oracle Enterprise Manager Database Control Console to create a database link. 1. From the Administration page, select Database Links from the Schema section. 2. The Database Links page allows you to search for existing database links or create a new one. 3. On the Create Database Link page you specify the database link name, the service name, and whether the database link is public or universally available. You can also designate how users connect to the linked database. On the Database Links page, if you select a database link and click View, the details of the database link are displayed. There is also a Test button that you can use to test whether the link to the remote database is active. 1 Oracle Database 10g: Administration Workshop II 4-8

9 Creating Database Links
Create a private link that uses the net service name ‘PGH_SALES’: Create a public database link for the database service ORCL: Use the private database link in a query: CREATE DATABASE LINK hq.sales.acme.com CONNECT TO hr IDENTIFIED BY hr USING 'pgh_sales'; CREATE PUBLIC DATABASE LINK orcl USING 'ORCL'; Creating Private Links You must have the CREATE DATABASE LINK system privilege to create private links. To create public links, you will need CREATE PUBLIC DATABASE LINK privilege. Simplified Syntax CREATE [PUBLIC] DATABASE LINK linkname CONNECT TO user IDENTIFIED BY password USING 'connect string' The connect string refers to the service name of a remote database. If you specify only the database name, then Oracle Database implicitly appends the database domain to the connect string to create a complete service name. Therefore, if the database domain of the remote database is different from that of the current database, then you must specify the complete service name. Guidelines You cannot create a database link in a schema other than your own. You can use a private database link only if you are the owner. SELECT * FROM Oracle Database 10g: Administration Workshop II 4-9

10 Oracle Database 10g: Administration Workshop II 4-10
Dropping Links Drop a link when the application no longer uses it Redefine a link when: Security breaches demand it Physical databases must be moved Network protocols change Node names change DROP [PUBLIC] DATABASE LINK linkname; Dropping Database Links You can drop a database link just as you can drop a table or view. If the link is private, then it must be in your schema. If the link is public, then you must have the DROP PUBLIC DATABASE LINK system privilege. There is no ALTER DATABASE LINK command, so if a database link needs to be changed, you must first drop the link and then recreate it. Oracle Database 10g: Administration Workshop II

11 Oracle Database 10g: Administration Workshop II 4-11
Data Dictionary Views DBA_DB_LINKS USER_DB_LINKS ALL_DB_LINKS V$DBLINK ALL_DB_LINKS This view lists all the database links in the database. V$DBLINK This view describes all the open database links for the current user session. These database links contain transactions that must be committed or rolled back before the database link is closed. Column Description OWNER Owner of the database link DB_LINK Name of the database link USERNAME Name of the user to log in as HOST Connect string (or the fully qualified global database name) CREATED Creation time of the database link Oracle Database 10g: Administration Workshop II

12 Oracle Database 10g: Administration Workshop II 4-12
Remote Query The user is connected to a local database and a database link is used to query data from a single remote database. The local database sends the entire query to the remote database to be processed. Oracle Database 10g: Administration Workshop II

13 Executing a Remote Query
Detroit Oracle Net SELECT * FROM Physical Network Link Pittsburgh Oracle Net Executing a Remote Query A remote query uses a database link to access data from a remote database. The user is connected to a local database (in Detroit). The user issues a query against a table using a database link. The connect identifier in the database link (FINANCE) is used to determine the location of the remote database. A session is opened on the remote database and data is fetched across the network. To provide location transparency for the remote table, you can create a synonym for the remote table. For example: CREATE PUBLIC SYNONYM finance_emps FOR Users connected to the Detroit database no longer need to know where the data is located and can instead use the synonym to access the remote table. SELECT * FROM finance_emps; Oracle Database 10g: Administration Workshop II

14 Oracle Database 10g: Administration Workshop II 4-14
Distributed Query The user is connected to a local database and issues a query involving tables from at least two databases. The query is always executed from a local database. The local database decomposes the query into subqueries to be sent to each remote database. The local database retrieves data from remote databases and performs any necessary post-processing. Oracle Database 10g: Administration Workshop II

15 Executing a Distributed Query
SELECT e.last_name,j.job_title FROM e, j, job_history h WHERE e.job_id = j.job_id AND e.employee_id = h.employee_id AND h.end_date >= SYSDATE-30; Local database Toronto SELECT employee_id, end_date FROM job_history; Pittsburgh SELECT last_name, job_id FROM employees; Detroit Executing a Distributed Query Assume the above distributed query is issued at the Toronto database, to locate the name and title of all employees whose jobs have changed in the last 30 days. The illustration on the slide provides an example of how the query can be decomposed into subqueries at each participating database. SELECT job_id, job_title FROM jobs; Oracle Database 10g: Administration Workshop II

16 Distributed and Remote Transactions
INSERT INTO VALUES ('CEO','Chief Executive Officer',18000,34000); UPDATE SET job_id = 'CEO' WHERE last_name = 'Hart'; COMMIT; Distributed and Remote Transactions The Oracle Database fully supports data manipulation transactional statements that can be remote or distributed, just as a query can be a remote or a distributed query. The code example above shows how to create a new job with the INSERT command, and transfer an employee to the new position by using the UPDATE command. If all statements of a transaction reference only a single remote node, the transaction is remote, not distributed. 2-PC (Two-Phase Commit) The two-phase commit mechanism is used to coordinate the committing or rolling back of the changes in a transaction as a self-contained unit. This mechanism is automatically used during all distributed transactions. Oracle Database's two-phase commit mechanism: Guarantees that all database servers participating in a distributed transaction perform the same action: commit or rollback. Protects implicit DML operations performed by integrity constraints, remote procedure calls, and triggers. Oracle Database 10g: Administration Workshop II

17 In-Doubt Transactions
Detroit Pittsburgh UPDATE UPDATE COMMIT; Local Database 1. UPDATE 2. UPDATE 3. Toronto database becomes unavailable. 4. Commit fails Toronto In-Doubt Transactions If a failure occurs in the middle of processing a distributed transaction, you may have part of the transaction committed at one site, but not committed at another. Because one of the databases is unavailable, the transaction cannot be completely committed or completely rolled back. This is known as an in-doubt transaction. The database RECO process automatically resolves the in-doubt transactions when the failure is corrected and the participating database becomes available. Until RECO can resolve the transaction, the data involved remains locked for both reads and writes. Data reads are blocked because the database does not know which version of the data to display for a query. In the majority of cases, the database resolves the in-doubt transaction automatically. You should only need to manually resolve an in-doubt transaction in the following situations: The in-doubt transaction has locks on critical data or undo segments The cause of the machine, network, or software failure cannot be repaired quickly Manual resolution of in-doubt transactions can be complicated. The general steps are: 1. Identify the transaction identification number for the in-doubt transaction. 2. Query the DBA_2PC_PENDING and DBA_2PC_NEIGHBORS views to determine whether the databases involved in the transaction have committed. 3. If necessary, force a commit using the COMMIT FORCE statement or a rollback using the ROLLBACK FORCE statement. Oracle Database 10g: Administration Workshop II

18 Oracle Database 10g: Administration Workshop II 4-19
Summary In this lesson, you should have learned about: Client-server and server-server architectures Network configuration files and processes Differences between remote queries and distributed queries Establishing communication between databases through database links Oracle Database 10g: Administration Workshop II


Download ppt "Enabling Distributed Transactions"

Similar presentations


Ads by Google