đề thi quản trị cơ sở dữ liệu phân tán 8

155 581 0
đề thi quản trị cơ sở dữ liệu phân tán 8

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

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Bai tap dia2\ddbs\oracle\test* Lenh SQL Update set Insert into Merger into (xem VD dưới) Có thể gan bí danh lênh SQL (xem VD dưới) Có thể nhúng câu lệnh SQL vào lệnh SQL (xem VD dưới) VD: MERGER INTO jobs j USING (SELECT * FROM ac) a ON (j.NUM=a.NUM) Có thể dùng SQL hay PL/SQL để thực thao tác Nếu dùng PL/SQL đảm bảo an ninh, cho phức tap, portable, mở rộng coi dtuong Oracle dùng CÁc đối tượng PL/SQL DBA : • Ddanh vấn đề đối tượng PL/SQL • Khuyến cáo việc sử dụng PL/SQL tương ứng • Nạp dtuong PL/SQL vào csdl • Trợ giúp người phát triển PL/SQL Các đối tượng dùng trợ giúp SEARCH để khảo sát Hàm: trả gtri định kiểu đó-thuộc lược đồ nào- Thân hàm nằm AS END; Thủ tục : thực thao tác – thuộc lược đồ nào- Thân thủ tục nằm AS END; Gói- Tập hợp nhiều thủ tục hàm(bản thân Oracle có 350 gói pvu DBA ứng dụng )- Thân gói nằm AS END;- Có thể xem nội dung gói nhờ lệnh DISCRIBE Trigger- Hàm/thủ tục cho skien (DML: INSERT, UPDATE, DELETE /DDL: CREATE, DROP, ALTER, GRANT, REVOKE, RENAME /csdl: LOGON, LOGOFF, STARTUP, SHUTDOWN, SERVERERROR) – Thuộc lược đồ nào- phục vụ thao tác liệu Giải giao dịch Lệnh COMMIT lệnh ROLLBACK Giải tương tranh Khóa • • • • Khóa mức cao cho tương tranh liệu: Khóa mức dòng cho inserts, updates, deletes Tvan không yêu cầu khóa Quản trị xếp hàng đợi tự động Khóa giữ kết thúc giao dịch (với thao tác COMMIT / ROLLBACK ) Khóa DML: Mối khóa giao dịch DML yêu cầu khóa: (VD lệnh UPDATE) • • Khóa dòng dành riêng(EXCLUSIVE) cho dòng/các dòng cập nhật Khóa mức bảng dòng dành riêng(ROW EXCLUSIVE ) cho bang chứa dòng Cơ chế hàng đợi Bám vết của: • • • Các phiên chờ khóa Các chế độ khóa yêu cầu Thứ tự phiên chờ khóa Nguyên nhân đụng độ khóa • • • Uncommitted changes Long-running transactions Unnecessarily high locking levels Các phien đụng độ khóa: (Định danh khóa chết/sau pgiai khóa chết) • • Select Blocking Sessions from the Performance page: o - đồ họa: Click lket ID phiên để xem ttin khóa phiên, bao gồm câu lệnh SQL o Đê giải đụng độ khóa:  Có phiên giữ khóa commit hay rollback  Kết thúc phiên giữ khóa resort cuối cung o Có kill session Disable/Enable SQL trace Có thể dùng câu lệnh SQL (select từ v$session với gtri sid blocking_session, sau alter ) o SQL> select sid, serial#, username from v$session where sid in (select blocking_session from v$session) Kqua đưa sid, serial#,username o Hủy phiên: SQL> alter system kill session '144,8982' immediate; • Khóa chết: hủy phiên??? Retain(noun:retention):giữ lại, chặn LES9-Or After completing this lesson, you should be able to the following: o Explain DML and undo data generation o Monitor and administer undo data o Describe the difference between undo data and redo data o Configure undo retention o Guarantee undo retention o Use the Undo Advisor Các lệnh DML o o Bao gồm : INSERT, MERGER, UPDATE, DELETE Thực lệnh RB COMMIT === Dlieu Undo là: • Bản dlieu gốc, dlieu trước tdoi • Đc chặn cho giao dịch tdoi dlieu • Đc giữ lại nhât giao dịch kthuc • ĐC dùng để hỗ trợ o Các ttac RB o Nquan đọc tvan flashback o Pchoi từ giao dịch sco • Các giao dịch liệu undo Transactions and Undo Data • Mỗi giao dịch gán đến segment undo • Mỗi segment undo pvu nhiều giao dịch lúc Lưu thông tin undo: Các thông tin undo lưu segment undo, segment lưu không gian bảng undo Các không gian bảng undo : • ĐƯợC dùng cho segment undo • Có xem xét phục hồi dbiet • Có thể liên hiệp với thể đơn • Yêu cầu chúng không gian bảng undo ghi thời cho thể cho thời điểm Undo Data Versus Redo Data Ghi lại Sử dụng cho Lưu Bảo vệ tránh Undo Undo thay đổi Quay lại hay Đọc không quán Các undo segment Đọc không quán hệ thống đa nsd Redo Lặp lại thay đổi Đi tiếp việc tdoi dlieu Các file Nhật ký redo Mất mát liệu Gsat Undo: Thường ycau qtri không nhiều Pvi gsat bao gồm: • Không gian tự không gian bảng • Các lỗi “snapshoot too old” Quản trị Undo: Quản trị Undo nên bao gồm : • Không gian lỗi không gian bảng undo • Kthuoc không gian bảng undo phải • Đảm bảo giao dịch lớn chuyển giao chu kỳ • Các lỗi “Snapshoot too old” • Cấu hình khoảng trì undo tương ứng • Kthuoc không gian bảng • Đảm bảo trì undo Sử dụng quản trị undo tdong : UNDO_MANAGEMENT=AUTO UNDO_TABLESPACE=UNDOTBS1 Cấu hình trì Undo : UNDO_RETENTION đặc tả (theo giây) tổng thông tin undo chuyển giao trì Thời điểm phải tlap tso khi: • Không gian bảng undo có tchon AUTOEXTEND phép • Ta muốn tlap trì undo cho LOB • Ta muốn đảm bảo trì Đảm bảo trì undo • Kthuoc không gian bảng • Sử dụng Undo Advisor Guaranteeing Undo Retention • Một giao dịch phát sinh nhiều undo không gian sẵn có lỗi • Câu lệnh SELECT chạy 15 phút hay thường an toàn Sizing the Undo Tablespace : Thay đổi khoảng thời gian/không gian bảng undo Using the Undo Advisor: khảo sát undo theo đồ thị Transaction Management Dnghia gdich mta ta qtri giao dịch nào: Nội dung chương: • • • Introduction to Transactions Overview of Transaction Management Overview of Autonomous Transactions Gthieu giao dịch (Introduction to Transactions) Một giao dịch đơn vị công việc logic chứa hay vài câu lệnh SQL giao dịch đơn vị nguyên tử Ảnh hưởng câu lệnh SQL giao dịch chuyển giao (ap dụng cho csdl) hay rollback tất cả(không làm cho csdl) Một giao dịch bắt đầu với câu lệnh SQL có khả vận hành Một giao dịch kết thúc thực tường minh COMMIT hay ROLLBACK lệnh không tường minh DDL Minh họa khái niệm giao dịch việc gửi, rút tiền từ ngân hàng: • • • Giảm số tiền tài khoản Tăng số tiền kiểm tra tài khoản Ghi giao dịch vào jounal giao dịch Oracle cần cho phép bối cảnh Nếu câu lệnh SQL thực để dtri tkhoan theo cân đối đúng, ahuong giao dịch adung cho csdl Tuy nhiên, nwus vấn đề không đủ tiền, sai tkhoan, hay cố pcung ngăn ngừa câu lệnh giao dịch không hoàn tất, toàn giao dịch phải rollback cho cân đối tài khoản Figure 4-1illustrates the banking transaction example Figure 4-1 A Banking Transaction Description of "Figure 4-1 A Banking Transaction" Vận hành điều khiển giao dịch (Statement Execution and Transaction Control) Một câu lệnh SQL chạy thành công khác với giao dịch thành công Vận hành thành công, câu lệnh đơn: • • • Dịch Xem SQL có hợp lệ không Chạy không lỗi đơn vị nguyên tử VD, dòng cập nhật nhiều dòng thay đổì Tuy nhiên giao dịch chứa câu lệnh chuyển giao , giao dịch ROLLBACK thay đổi lệnh undo CHUYểN GIAO có nghĩa nsd yêu cầu tường minh không tường minh thay đổi giao dịch thực thường trực Một yêu cầu tường minh xuất nsd công bố lệnh COMMIT Một yêu cầu không tường minh xuất sau kết thúc bình thường ứng dụng hay thao tác dnghia liệu(DDL) Sụ thay đổi lệnh SQL giao dịch trở nên thường trực nhìn thấy nsd khác sau giao dịch chuyển giao.Các tvan công bố sau chuyển giao giao dịch nhìn thấy thay đổi chuyển giao Ta dặt tên giao dịch dùng câu lệnh the SET TRANSACTION NAME trước bắt đầu giao dịch.Điều làm dễ dàng giám sát giao dịch dài pgiai giao dịch nghi ngờ Rollback mức câu lệnh(Statement-Level Rollback) Nếu chạy câu lệnh SQL bị lỗi, ảnh ưởng câu lệnh ROLLBACK , coi lệnh chưa thực thao tác ROLLBACK mức câu lệnh Các lỗi phát vận hành câu lệnh SQL gây ROLLBACK mức câu lệnh VD, đưa gtri vao trường khóa Câu lệnh SQL kéo theo khóa chết(cạnh tranh liệu) gây ROLLBACK mức câu lệnh Các lỗi phát dịch câu lệnh SQL, sai cú pháp, chưa chạy không coi ROLLBACK mức câu lệnh Lệnh SQL gây lỗi làm mết liệu công việc thực Nó không gây liệu công việc trước giao dịch thời Nêu câu lệnh DDL chuyển giao không tường minh thực trước undo Chú ý : Nsd tham chiếu trực tiếp đên điểm an toàn câu lệnh ROLLBACK Định vị không gian khả tiếp (Resumable Space Allocation) Oracle cung cấp phương tiện cho việc treo, sau tiếp tục vận hành thao tác csdl lớn kiện lỗi định vị không gian Điều cho phép người quản trị hành động thay cho việc server csdl Oracle trả lỗi nsd Sau điều kiện lỗi sửa đổi, thao tác treo tự động tiếp tục Câu lệnh chạy chế độ khả tiếp tục client hiệu lực hóa tường minh ngữ nghĩa cho phiên dùng câu lệnh ALTER SESSION Định vị không gian khả tiếp bị treo điều kiện sau xuất : • • Hết không gian điều kiện Mở rộng cực đại tới • Cô ta không gian vượt điều kiện Với định vị không gian không khả tiếp, điều kiện dẫn đến lỗi ROLLBACK Việc treo câu lệnh thu tự động việc treo giao dịch Như vậy, tài nguyên giao dịch treo bị giữ qua việc treo tiếp tục câu lệnh Khi điều kiện lỗi mất(VD, nsd can thiệp hay không gian giải phóng tvan) câu lệnh treo tự động vận hành tiếp tục Tổng quan qtri gdich(Overview of Transaction Management) Giao dịch Oracle bắt đầu lệnh SQL thực thi tính đến Một câu lệnh SQL khả thi câu lệnh SQL phát sinh lời gọi đến thể hiện, bao gồm leenhjDDDL DML Khi giao dịch bắt đầu, Oracle gán giao dịch đến không gian bảng undo có sẵn để lưu lối vào rollback cho giao dịch Giao dịch kết thúc xuất trong: • • • • Nsd công bố câu lệnh ROLLBACK hay COM mệnh đề SAVEPOINT Khi nsd chạy lệnh CREATE, DROP, RENAME, hay ALTER Nếu giao dịch hthoi chứa lệnh DML, trước hết Oracle chuyển giao cac giao dịch chạy chuyển giao câu lệnh DDL giao dịch đơn, nsd ngắt khởi Oracle Giao dịch thời chuyển giao tiến trình kết thúc bất thường Giao dịch ROLLBACK Sau giao dịch kết thúc, câu lệnh SQL khả thi tự động giao dịch liền sau Chú ý: Các ứng dụng nên thường xuyên chuyển giao tminh hay undo giao dịch trước kết thúc chương trình Chuyển giao giao dịch (Commit Transactions) Chuyển giao có ng hĩa thay đổi thường trực thực câu lệnh SQL giao dịch Trước giao dịch thay đổi liệu chuyển giao, xuất hiện: • • • Oracle phat sinh thông tin undo Thông tin undo chứa gtri liệu cũ thay đổi câu lệnh giao dịch Oracle phát sinh lối vào nhật ký redo đệm SGA Nhật ký redo chứa thay đổi với khối liệu thay đổi vơi khối rollback Các thay đổi đến đĩa trước giao dịch chuyển giao Các thay đổi làm với đệm csdl SGA Các thay đổi đến đĩa trước giao dịch chuyển giao Chú ý : Sự thay đổi cho giao dịch chuyển giao, lưu đệm SGA, không thiết ghi vào file csdl tiến trình nên ghi csdl(DBWW n) Việc ghi xảy trước hay sau chuyển giao giao dịch , lúc hiệu csdl Khi giao dịch chuyển giao, xảy ra(4): Bảng giao dịch nội tai cho ghi không gian bảng undo mà giao dịch chuyển giao, số thay đổi hệ thống (SCN) giao dịch gán ghi vào bảng Tiến trình ghi nhật ký(LGWR) viết lối vào redo đệm nhật ký redo vào file nhật ký redo Nó ghi SCN giao dịch vào nhật ký redo Skien nguyên tử cấu thành chuyển giao giao dịch Oracle giải phóng khóa giữ dòng bảng Oracle đánh dấu giao dịch hoàn tất Note: Hành vi mặc định cho LGWR ghi redo vào file nhật ký redo online cách đồng cho giao dịch chờ redo chuyển đến đĩa trước quay chuyển giao cho nsd Tuy nhiên, với ứng dụng trễ giao dịch chậm hơn, người lập trình dta redo ghi không đồng giao dịch không cần phải chờ cho redo lên đĩa Rollback giao dịch (Rollback of Transactions) ROLLBACK có nghĩa undo thay đổi cho liệu thực câu lệnh SQL giao dịch không chuyển giao Oracle sử dung không gian bảng undo (hay sment rollback ) để lưu gtri cũ Nhật ký redo chứa ghi thay đổi Oracle cho ta rollback toàn hay phần đên điểm an toàn Mọi kiểu rollback dùng chung thủ tục: • • • • • • Rollback Rollback Rollback Rollback Rollback thường Rollback mức câu lệnh(do lỗi câu lệnh hay vận hành khóa chết) đến điểm an toàn giao dịch yêu cầu nsd giao dịch kết thúc không bình thường tiến trình giao dịch biết thể kết thúc không bình giao dịch không chuyển giao phục hồi Khi rollback giao dịch toàn bộ(không có điểm an toàn tchieu), xuất hiện: o o o Oracle undo thay đổi tạo câu lệnh SQL giao dịch cách dùng không gian bảng undo tương ứng Oracle giải phóng khóa giao dịch liệu Giao dịch kết thúc Các điểm an toàn giao dịch (Savepoints In Transactions) Ta công bố dấu hiệu gọi điểm an toàn ngữ cảnh giao dịch Các điểm an toàn chia giao dịch thành giao dịch nhỏ Dùng điểm an toàn, ta đánh dấu công việc điểm giao dịch dài Rồi ta có tchon sau việc ROLLBACK công việc trước điểm thời giao dịch sau điểm an toàn công bố giao dịch.VD, ta dùng điểm an toàn qua chuỗi cập nhật phức tạp , ta gặp lỗi, ta không cần đệ trình lại câu lệnh Điểm an toàn hữu dụng chương trình ứng dụng Nếu thủ tục chứa vài hàm, ta tao điểm an toàn trước hàm bắt đầu Nếu hàm cố, dễ dàng trả lại liệu cho trạng thái trước hàm băt đầu va chạy lại hàm với tham số xem xét lại hay thực thi hoạt động phục hồi Sau ROLLBACK điểm an toàn , Oracle giải phóng khóa liệu dành câu lệnh ROLLBACK Các giao dịch khác chờ tài nguyên bị khóa trước xử lý.Các giao dịch khác muốn cập nhật dòng bị khóa trước làm Khi giao dịch ROLLBACK đên điểm an toàn , điều sau xuất hiện: 1/Oracle quay lại câu lệnh chạy sau điểm an toàn Các khóa bảng chia xẻ-Share Table Locks (S) Đc đòi hỏi tự động cho bảng đặc tả câu lệnh sau: LOCK TABLE table IN SHARE MODE; Các thao tác cho phép:Khóa bảng chia xẻ giữ giao dịch cho phép giao dịch khác truy vấn bảng, khóa hàng với SELECT FOR., hay chạy lệnh LOCK TABLE IN SHARE thành công Ko có cập nhật phép giao dịch khác Nhiều giao dịch khóa bảng chia xẻ với bảng tương tranh Trong trường hợp này, không co giao dịch cập nhật bảng(thạm chí giao dịch giữ khóa dòng kết lệnh SELECT với mệnh đề FOR UPDATE) Vì thế, giao dịch có khóa chia xẻ cập nhật bảng giao dịch khác có khóa chia xẻ bảng Các thao tác cấm: Khóa bảng chia xẻ giữ giao dịch ngăn ngừa giao dịch khác thay đổi bảng chạy lệnh sau: LOCK TABLE table IN SHARE ROW EXCLUSIVE MODE; LOCK TABLE table IN EXCLUSIVE MODE; LOCK TABLE table IN ROW EXCLUSIVE MODE; Các khóa bảng dành riêng dòng chia xẻ-Share Row Exclusive Table Locks (SRX) Còn gọi khóa dành riêng nhỏ chia xẻ share-subexclusive table lock, SSX Nghiêm ngặt so với khóa bảng chia xẻ Khóa SRX chiếm bảng sau: LOCK TABLE table IN SHARE ROW EXCLUSIVE MODE; Các thao tác cho phép:Chỉ có giao dịch thời điểm chiếm giữ khóa bảng dành riêng bảng cho Một khóa bảng dành riêng giữ giao dịch cho phép giao dịch khác truy vấn hay khóa dòng đặc tả dùng SELECT dùng mệnh đề FOR UPDATE, không cập nhật bảng Các thao tác cấm: Ngăn ngừa giao dịch khác chiếm khóa bảng dòng dành riêng thay đổi bảng Một khóa bảng dòng dành riêng cấm giao dịch khác giành quyền chia xẻ, chia xẻ dòng dành riêng khóa bảng riêng, ngăn ngừa giao dịch khác không vhanh lệnh sau: LOCK TABLE table IN SHARE MODE; LOCK TABLE table IN SHARE ROW EXCLUSIVE MODE; LOCK TABLE table IN ROW EXCLUSIVE MODE; LOCK TABLE table IN EXCLUSIVE MODE; Các khóa bảng dành riêng-Exclusive Table Locks (X) Là cdo khóa bảng nghiêm ngặt khóa bảng, cho phép giao dịch giữ khóa truy nhập viết đến bảng khóa bảng dành riêng bị đòi hỏi cho bảng : LOCK TABLE table IN EXCLUSIVE MODE; Các thao tác Cho phép: Các thao tác cấm: Permitted Operations: Only one transaction can obtain an exclusive table lock for a table An exclusive table lock permits other transactions only to query the table Prohibited Operations: An exclusive table lock held by a transaction prohibits other transactions from performing any type of DML statement or placing any type of lock on the table Các khóa DML yêu cầu tự động cho câu lệnh DML-DML Locks Automatically Acquired for DML Statements The previous sections explained the different types of data locks, the modes in which they can be held, when they can be obtained, when they are obtained, and what they prohibit The following sections summarize how Oracle automatically locks data on behalf of different DML operations Table 13-4 summarizes the information in the following sections Table 13-4 Locks Obtained By DML Statements DML Statement SELECT FROM INSERT INTO Row Locks? Mode of Table Lock X RX table table DML Statement UPDATE table DELETE FROM table SELECT FROM OF LOCK TABLE table table IN FOR UPDATE Row Locks? Mode of Table Lock X RX X RX X RS ROW SHARE MODE RS ROW EXCLUSIVE MODE RX SHARE MODE S SHARE EXCLUSIVE MODE SRX EXCLUSIVE MODE X X: exclusive RX: row exclusive RS: row share S: share SRX: share row exclusive Khóa mặc định cho truy vấn-Default Locking for Queries Queries are the SQL statements least likely to interfere with other SQL statements because they only read data INSERT, UPDATE, and DELETE statements can have implicit queries as part of the statement Queries include the following kinds of statements: SELECT INSERT SELECT ; UPDATE ; DELETE ; They not include the following statement: SELECT FOR UPDATE OF ; The following characteristics are true of all queries that not use the FOR UPDATE clause: • • A query acquires no data locks Therefore, other transactions can query and update a table being queried, including the specific rows being queried Because queries lacking FOR UPDATE clauses not acquire any data locks to block other operations, such queries are often referred to in Oracle as nonblocking queries A query does not have to wait for any data locks to be released; it can always proceed (Queries may have to wait for data locks in some very specific cases of pending distributed transactions.) Khóa mặc định cho -Default Locking for INSERT, UPDATE, DELETE, and SELECT FOR UPDATE The locking characteristics of INSERT, UPDATE, DELETE, and SELECT FOR UPDATE statements are as follows: • • • The transaction that contains a DML statement acquires exclusive row locks on the rows modified by the statement Other transactions cannot update or delete the locked rows until the locking transaction either commits or rolls back The transaction that contains a DML statement does not need to acquire row locks on any rows selected by a subquery or an implicit query, such as a query in a WHERE clause A subquery or implicit query in a DML statement is guaranteed to be consistent as of the start of the query and does not see the effects of the DML statement it is part of A query in a transaction can see the changes made by previous DML statements in the same transaction, but cannot see the changes of other transactions begun after its own transaction • In addition to the necessary exclusive row locks, a transaction that contains a DML statement acquires at least a row exclusive table lock on the table that contains the affected rows If the containing transaction already holds a share, share row exclusive, or exclusive table lock for that table, the row exclusive table lock is not acquired If the containing transaction already holds a row share table lock, Oracle automatically converts this lock to a row exclusive table lock Các khóa từ điển liệu-DDL Locks A data dictionary lock (DDL) protects the definition of a schema object while that object is acted upon or referred to by an ongoing DDL operation Recall that a DDL statement implicitly commits its transaction For example, assume that a user creates a procedure On behalf of the user's single-statement transaction, Oracle automatically acquires DDL locks for all schema objects referenced in the procedure definition The DDL locks prevent objects referenced in the procedure from being altered or dropped before the procedure compilation is complete Oracle acquires a dictionary lock automatically on behalf of any DDL transaction requiring it Users cannot explicitly request DDL locks Only individual schema objects that are modified or referenced are locked during DDL operations The whole data dictionary is never locked DDL locks fall into three categories: exclusive DDL locks, share DDL locks, and breakable parse locks Các khóa từ điển liệu danh riêng-Exclusive DDL Locks Most DDL operations, except for those listed in the section, "Share DDL Locks" require exclusive DDL locks for a resource to prevent destructive interference with other DDL operations that might modify or reference the same schema object For example, a DROP TABLE operation is not allowed to drop a table while an ALTER TABLE operation is adding a column to it, and vice versa During the acquisition of an exclusive DDL lock, if another DDL lock is already held on the schema object by another operation, the acquisition waits until the older DDL lock is released and then proceeds DDL operations also acquire DML locks (data locks) on the schema object to be modified Các khóa DDL chia xẻ-Share DDL Locks Some DDL operations require share DDL locks for a resource to prevent destructive interference with conflicting DDL operations, but allow data concurrency for similar DDL operations For example, when a CREATE PROCEDURE statement is run, the containing transaction acquires share DDL locks for all referenced tables Other transactions can concurrently create procedures that reference the same tables and therefore acquire concurrent share DDL locks on the same tables, but no transaction can acquire an exclusive DDL lock on any referenced table No transaction can alter or drop a referenced table As a result, a transaction that holds a share DDL lock is guaranteed that the definition of the referenced schema object will remain constant for the duration of the transaction A share DDL lock is acquired on a schema object for DDL statements that include the following statements: AUDIT, NOAUDIT, COMMENT, CREATE [OR REPLACE] VIEW/ PROCEDURE/PACKAGE/PACKAGE BODY/FUNCTION/ TRIGGER, CREATE SYNONYM, and CREATE TABLE (when the CLUSTER parameter is not included) Các khóa dịch có khả bẻ gẫy-Breakable Parse Locks A SQL statement (or PL/SQL program unit) in the shared pool holds a parse lock for each schema object it references Parse locks are acquired so that the associated shared SQL area can be invalidated if a referenced object is altered or dropped A parse lock does not disallow any DDL operation and can be broken to allow conflicting DDL operations, hence the name breakable parse lock A parse lock is acquired during the parse phase of SQL statement execution and held as long as the shared SQL area for that statement remains in the shared pool See Also: Chapter 6, "Dependencies Among Schema Objects" Khoảng thời gian khóa DDL Duration of DDL Locks The duration of a DDL lock depends on its type Exclusive and share DDL locks last for the duration of DDL statement execution and automatic commit A parse lock persists as long as the associated SQL statement remains in the shared pool Các khóa bó DDL- DDL Locks and Clusters A DDL operation on a cluster acquires exclusive DDL locks on the cluster and on all tables and materialized views in the cluster A DDL operation on a table or materialized view in a cluster acquires a share lock on the cluster, in addition to a share or exclusive DDL lock on the table or materialized view The share DDL lock on the cluster prevents another operation from dropping the cluster while the first operation proceeds Các khóa chốt khóa nội - Latches and Internal Locks Latches and internal locks protect internal database and memory structures Both are inaccessible to users, because users have no need to control over their occurrence or duration The following section helps to interpret the Enterprise Manager LOCKS and LATCHES monitors Chốt - Latches Latches are simple, low-level serialization mechanisms to protect shared data structures in the system global area (SGA) For example, latches protect the list of users currently accessing the database and protect the data structures describing the blocks in the buffer cache A server or background process acquires a latch for a very short time while manipulating or looking at one of these structures The implementation of latches is operating system dependent, particularly in regard to whether and how long a process will wait for a latch Các khóa nội - Internal Locks Internal locks are higher-level, more complex mechanisms than latches and serve a variety of purposes Các khóa cache từ điển - Dictionary Cache Locks These locks are of very short duration and are held on entries in dictionary caches while the entries are being modified or used They guarantee that statements being parsed not see inconsistent object definitions Dictionary cache locks can be shared or exclusive Shared locks are released when the parse is complete Exclusive locks are released when the DDL operation is complete Các khóa quản trị log quản trị file - File and Log Management Locks These locks protect various files For example, one lock protects the control file so that only one process at a time can change it Another lock coordinates the use and archiving of the redo log files Datafiles are locked to ensure that multiple instances mount a database in shared mode or that one instance mounts it in exclusive mode Because file and log locks indicate the status of files, these locks are necessarily held for a long time Các khóa không gian bảng phân đoạn rollback Tablespace and Rollback Segment Locks These locks protect tablespaces and rollback segments For example, all instances accessing a database must agree on whether a tablespace is online or offline Rollback segments are locked so that only one instance can write to a segment Khóa liệu tường minh(thủ công) - Explicit (Manual) Data Locking Oracle always performs locking automatically to ensure data concurrency, data integrity, and statement-level read consistency However, you can override the Oracle default locking mechanisms Overriding the default locking is useful in situations such as these: • Applications require transaction-level read consistency or repeatable reads In other words, queries in them must produce consistent data for the duration of the transaction, not reflecting changes by other transactions You can achieve transaction-level read consistency by using explicit locking, read-only transactions, serializable transactions, or by overriding default locking • Applications require that a transaction have exclusive access to a resource so that the transaction does not have to wait for other transactions to complete Oracle's automatic locking can be overridden at the transaction level or the session level At the transaction level, transactions that include the following SQL statements override Oracle's default locking: • • The SET TRANSACTION ISOLATION LEVEL statement The LOCK TABLE statement (which locks either a table or, when used with views, the underlying base tables) • The SELECT FOR UPDATE statement Locks acquired by these statements are released after the transaction commits or rolls back At the session level, a session can set the required transaction isolation level with the ALTER SESSION statement Note: If Oracle's default locking is overridden at any level, the database administrator or application developer should ensure that the overriding locking procedures operate correctly The locking procedures must satisfy the following criteria: data integrity is guaranteed, data concurrency is acceptable, and deadlocks are not possible or are appropriately handled See Also: Oracle Database SQL Reference for detailed descriptions of the SQL statements LOCK TABLE and SELECT FOR UPDATE Các dịch vụ quản trị khóa Oracle - Oracle Lock Management Services With Oracle Lock Management services, an application developer can include statements in PL/SQL blocks that: • • Request a lock of a specific type Give the lock a unique name recognizable in another procedure in the same or in another instance • Change the lock type • Release the lock Because a reserved user lock is the same as an Oracle lock, it has all the Oracle lock functionality including deadlock detection User locks never conflict with Oracle locks, because they are identified with the prefix UL The Oracle Lock Management services are available through procedures in the DBMS_LOCK package See Also: • • Oracle Database Application Developer's Guide - Fundamentals for more information about Oracle Lock Management services Oracle Database PL/SQL Packages and Types Reference for information about DBMS_LOCK Tổng quan dẫn dắt truy vấn - Overview of Oracle Flashback Query Oracle Flashback Query lets you view and repair historical data You can perform queries on the database as of a certain wall clock time or user-specified system change number (SCN) Flashback Query uses Oracle's multiversion read-consistency capabilities to restore data by applying undo as needed Oracle Database 10g automatically tunes a parameter called the undo retention period The undo retention period indicates the amount of time that must pass before old undo information—that is, undo information for committed transactions—can be overwritten The database collects usage statistics and tunes the undo retention period based on these statistics and on undo tablespace size Using Flashback Query, you can query the database as it existed this morning, yesterday, or last week The speed of this operation depends only on the amount of data being queried and the number of changes to the data that need to be backed out You can query the history of a given row or a transaction Using undo data stored in the database, you can view all versions of a row and revert to a previous version of that row Flashback Transaction Query history lets you examine changes to the database at the transaction level You can audit the rows of a table and get information about the transactions that changed the rows and the times when it was changed With the transaction ID, you can transaction mining through LogMiner to get complete information about the transaction See Also: • Oracle Database Administrator's Guide for more information on the automatic tuning of undo retention and on LogMiner • "Automatic Undo Retention" You set the date and time you want to view Then, any SQL query you run operates on data as it existed at that time If you are an authorized user, then you can correct errors and back out the restored data without needing the intervention of an administrator With the AS OF SQL clause, you can choose different snapshots for each table in the query Associating a snapshot with a table is known as table decoration If you not decorate a table with a snapshot, then a default snapshot is used for it All tables without a specified snapshot get the same default snapshot For example, suppose you want to write a query to find all the new customer accounts created in the past hour You could set operations on two instances of the same table decorated with different AS OF clauses DML and DDL operations can use table decoration to choose snapshots within subqueries Operations such as INSERT TABLE AS SELECT and CREATE TABLE AS SELECT can be used with table decoration in the subqueries to repair tables from which rows have been mistakenly deleted Table decoration can be any arbitrary expression: a bind variable, a constant, a string, date operations, and so on You can open a cursor and dynamically bind a snapshot value (a timestamp or an SCN) to decorate a table with See Also: • • "Overview of Oracle Flashback Features" for an overview of all Oracle Flashback features Oracle Database SQL Reference for information on the AS OF clause Cacsi lợi dẫn dắt truy vấn - Flashback Query Benefits This section lists some of the benefits of using Flashback Query • Application Transparency Packaged applications, like report generation tools that only queries, can run in Flashback Query mode by using logon triggers Applications can run transparently without requiring changes to code All the constraints that the application needs to be satisfied are guaranteed to hold good, because there is a consistent version of the database as of the Flashback Query time • Application Performance If an application requires recovery actions, it can so by saving SCNs and flashing back to those SCNs This is a lot easier and faster than saving data sets and restoring them later, which would be required if the application were to explicit versioning Using Flashback Query, there are no costs for logging that would be incurred by explicit versioning • Online Operation Flashback Query is an online operation Concurrent DMLs and queries from other sessions are allowed while an object is queried inside Flashback Query.The speed of these operations is unaffected Moreover, different sessions can flash back to different Flashback times or SCNs on the same object concurrently The speed of the Flashback Query itself depends on the amount of undo that needs to be applied, which is proportional to how far back in time the query goes • Easy Manageability There is no additional management on the part of the user, except setting the appropriate retention interval, having the right privileges, and so on No additional logging has to be turned on, because past versions are constructed automatically, as needed Note: • • Flashback Query does not undo anything It is only a query mechanism You can take the output from a Flashback Query and perform an undo yourself in many circumstances Flashback Query does not tell you what changed LogMiner does that • Flashback Query can undo changes and can be very efficient if you know the rows that need to be moved back in time You can use it to move a full table back in time, but this is very expensive if the table is large since it involves a full table copy • Flashback Query does not work through DDL operations that modify columns, or drop or truncate tables • LogMiner is very good for getting change history, but it gives you changes in terms of deltas (insert, update, delete), not in terms of the before and after image of a row These can be difficult to deal with in some applications Một vài ứng dụng truy vấn dẫn dắt - Some Uses of Flashback Query This section lists some ways to use Flashback Query • Self-Service Repair Perhaps you accidentally deleted some important rows from a table and wanted to recover the deleted rows To the repair, you can move backward in time and see the missing rows and re-insert the deleted row into the current table • E-mail or Voice Mail Applications You might have deleted mail in the past Using Flashback Query, you can restore the deleted mail by moving back in time and re-inserting the deleted message into the current message box • Account Balances You can view account prior account balances as of a certain day in the month • Packaged Applications Packaged applications (like report generation tools) can make use of Flashback Query without any changes to application logic Any constraints that the application expects are guaranteed to be satisfied, because users see a consistent version of the Database as of the given time or SCN In addition, Flashback Query could be used after examination of audit information to see the before-image of the data In DSS environments, it could be used for extraction of data as of a consistent point in time from OLTP systems See Also: • • • Oracle Database Application Developer's Guide - Fundamentals for more information about using Oracle Flashback Query Oracle Database PL/SQL Packages and Types Reference for a description of the DBMS_FLASHBACK package Oracle Database Administrator's Guide for information about undo tablespaces and setting retention period ==== Giải giao dịch Lệnh COMMIT lệnh ROLLBACK Giải tương tranh Khóa • • • • Khóa mức cao cho tương tranh liệu: Khóa mức dòng cho inserts, updates, deletes Truy vấn không yêu cầu khóa Quản trị xếp hàng đợi tự động Khóa giữ kết thúc giao dịch (với thao tác COMMIT / ROLLBACK ) Khóa DML: Mối khóa giao dịch DML yêu cầu khóa: (VD lệnh UPDATE) • • Khóa dòng dành riêng(EXCLUSIVE) cho dòng/các dòng cập nhật Khóa mức bảng dòng dành riêng(ROW EXCLUSIVE ) cho bang chứa dòng Cơ chế hàng đợi Bám vết của: • • • Các phiên chờ khóa Các chế độ khóa yêu cầu Thứ tự phiên chờ khóa Nguyên nhân đụng độ khóa • • • Uncommitted changes Long-running transactions Unnecessarily high locking levels Các phien đụng độ khóa: (Định danh khóa chết/sau phân giải khóa chết) • • Select Blocking Sessions from the Performance page: o Đồ họa: Click lket ID phiên để xem ttin khóa phiên, bao gồm câu lệnh SQL o Đê giải đụng độ khóa:  Có phiên giữ khóa commit hay rollback  Kết thúc phiên giữ khóa resort cuối cung o Có kill session Disable/Enable SQL trace Có thể dùng câu lệnh SQL (select từ v$session với gtri sid blocking_session, sau alter ) o SQL> select sid, serial#, username from v$session where sid in (select blocking_session from v$session) Kqua đưa sid, serial#,username o • Hủy phiên: SQL> alter system kill session '144,8982' immediate; Khóa chết: hủy phiên??? Minh họa khái niệm giao dịch việc gửi, rút tiền từ ngân hàng: • • • Giảm số tiền tài khoản Tăng số tiền kiểm tra tài khoản Ghi giao dịch vào jounal giao dịch Oracle cần cho phép bối cảnh Nếu câu lệnh SQL thực để dtri tkhoan theo cân đối đúng, ahuong giao dịch adung cho csdl Tuy nhiên, nwus vấn đề không đủ tiền, sai tkhoan, hay cố pcung ngăn ngừa câu lệnh giao dịch không hoàn tất, toàn giao dịch phải rollback cho cân đối tài khoản Figure 4-1illustrates the banking transaction example Figure 4-1 A Banking Transaction Description of "Figure 4-1 A Banking Transaction" [...]... xa u Các giao dịch phân tán Các yêu cầu phân tán - Trong suốt giao dịch 4 Transaction transparency đảm bảo rằng các giao dịch csdl sẽ duy trì tính toàn vẹn và tính nhất quán csdl Giao dịch sẽ chỉ hoàn toàn nếu và chỉ nếu mọi site csdl liên quan đến giao dịch hoàn tất phần việc giao dịch của mình 4 Trong suốt phân tán Distribution transparency Được hỗ trợ bởi từ điển dữ liệu phân tán( distributed data... tán( distributed data dictionary (DDD) hay bằng catalog dữ liệu phân tán( distributed data catalog (DDC) DDC chứa mta của toàn bộ csdl khi nhìn bởi DBA Mta csdl được biết như lược đồ tổng thể phân tán là lược đồ csdl chung được dùng bởi TP cục bộ để dịch các yêu cầu nsd thành các truy vấn con 4 Transaction Transparency 4 Các yêu cầu phân tán và các giao dịch phân tán u Các yêu cầu xa cho phép ta truy nhập csdl... thông qua bảng khóa (trong các hệ thống thương mại là các header dữ liệu , id của giao dịch) Centralized 2PL o Chỉ có 1 bộ lập lịch 2PL trong hệ thống phân tán o Các yêu cầu Khóa được công bố cho bô lập lịch ttam (từ bộ quản trị giao dịch ) Distributed 2PL Bộ lập lịch được đặt ở mỗi site Mỗi bô lập lịch điều khiển các yêu cầu khoa cho dữ liệu ở site đó Một giao dịch có thể đọc bất kỳ nhân bản nào của... tranh, cách ly ¤ Các giao thức điều khiển Replica - Làm sao điều khiển tính nhất quán tương hỗ của dữ liệu được nhân bản (replicated data)? - Một bản copy, ROWA, tập trung (consensus)đa số, bầu cử động, cây quorum (số đại biểu cần thi t theo quy định) Vận hành giao dịch tập trung và phân tán: - ¤ Bộ quản trị giao dịch (TM) chịu trách nhiệm cho phối hợp vận hành của các thao tác csdl nhân danh các ứng... 10.10) u Giao dịch xa bao gồm 1 vài yêu cầu có thể truy nhập dữ liệu chỉ ở một site đơn (Figure 10.11) u Một giao dịch phân tán cho phép một giao dịch tham chiếu một vài site DP(cục bộ hay ở xa) (Figure 10.12) u Một yêu cầu phân tán cho phép ta tham chiếu một vài site DP ở xa (Figure 10.13) Nó cũng cho phép truy vấn đơn truy vấn đến các bảng phân chia vật lý(Figure 10.14) 4 Trong suốt giao dịch 4 Gthuc... - ¤ Bộ quản trị phục hồi cục bộ (RM) thực hiện các thủ tục để phục hồi từ các sự cố Điều khiển tương tranh: vấn đề đồng bộ các giao dịch tương tranh sao cho tính nhất quán cua csdl được bảo toàn trong khi cùng thời gian đạt được mức độ tương tranh cao nhất ~ Bất thường: mất cập nhật, đọc bẩn, phân tích không nhất quán Vận hành lịch biểu ( or History): - ¤ Khái niệm một lịch biểu cung cấp một cơ chế... transaction to a savepoint taken before the beginning of an autonomous transaction does not undo the autonomous transaction CHƯƠNG IV: QUẢN LÝ GIAO DỊCH VÀ ĐIỀU KHIỂN TƯƠNG TRANH (số tiết 4 ) 4 1 Quản lý giao dịch Khái niệm giao dịch/các giao dịch remote và phân tán/ vấn đề tương tranh H:\ddbs\ddbs1\Managing a Distributed Database.htm H:\oracle-baigiang\2010\ppt\baigiang truong codex \ch25[1] Advanced... và ID trong các ứng dụng VD, người quản trị có thể xem các tên các giao dịch trong Enterprise Manager khi giám sát các hoạt động hệ thống Tên các giao dịch được viết cho việc kiểm toán bản ghi redo LogMiner có thể dngf tên các giao dịch để tkiem các giao dịch đặc tả trong nhật ký redo Ta có thể dùng tên giao dịch để tìm ra 1 giao dịch đặc tả trong view tdien dữ liệu , như V$TRANSACTION Các giao dịch... dlieu, thậm chí nếu sco mạng hay hthong xhien Một giao dịch phân tán là giao dịch bao gồm 1 hay nhiều clenh, cnhat dlieu trên 2 hay nhiều nút knhau của csdl ptan Một cơ chế chuyển giao 2 pha dbao rằng mọi sv csdl tgia trong 1 gdich ptan hoặc tất cả đc cgiao hoặc undo các clenh trong gdich Cche cgiao 2 pha cũng bảo vệ các ttac DML ko tminh thien bởi các ràng buộc tven, lời gọi ttuc từ xa và các trigger... thực hiện khả thi: In practice, for concurrently executing transactions, the scheduler veri es whether the actual schedule is serializable For this, the scheduler maintains and extends the precedence graph while new operations are performed (or announced) by transactions { if the actual graph is acyclic, then continue schedule { otherwise reset (some) transactions Tính ntiep trong CSDL phân tán ¤ Local ... tất phần việc giao dịch Trong suốt phân tán Distribution transparency Được hỗ trợ từ điển liệu phân tán( distributed data dictionary (DDD) hay catalog liệu phân tán( distributed data catalog (DDC)... Khóa(4): Khóa trung tâm pha/khóa sở pha /khóa phân tán pha /luật đa số Khóa phân tán pha: site có quản trị khóa riêng(cho giao tiếp)/nếu nhân giao thức giống khóa sở pha/thực đọc ghi nhiều(ROWA... hỗ liệu nhân (replicated data)? - Một copy, ROWA, tập trung (consensus)đa số, bầu cử động, quorum (số đại biểu cần thi t theo quy định) Vận hành giao dịch tập trung phân tán: - ¤ Bộ quản trị

Ngày đăng: 17/01/2016, 00:08

Từ khóa liên quan

Mục lục

  • Điều khiển tương tranh

  • Xem them: http://softbase.uwaterloo.ca/~tozsu/ddbook/notes/Transaction/ppframe.htm

  • Các cây phiên cho giao dịch phân tán(Session Trees for Distributed Transactions)

    • Figure 31-2 Example of a Session Tree

    • Clients

    • Database Servers

    • Các bộ phối hợp cục bộ

    • Các bộ phối hợp tổng thể

    • Site điểm chuyển giao

      • Figure 31-3 Commit Point Site

      • Chuyển giao giao dịch phân tán như thế nào(How a Distributed Transaction Commits)

      • Độ mạnh điểm chuyển giao (Commit Point Strength)

      • Figure 31-4 Commit Point Strengths and Determination of the Commit Point Site

      • Cơ chế chuyển giao 2 pha (Two-Phase Commit Mechanism)

        • Pha chuẩn bị (Prepare Phase)

          • Các kiểu đáp ứng trong pha chuẩn bị (Types of Responses in the Prepare Phase)

            • Đáp ứng được chuẩn bị(Prepared Response)

            • Đáp ứng chỉ đọc (Read-Only Response)

            • Đáp ứng thoát(Abort Response)

            • Các bước trong pha chuẩn bị(Steps in the Prepare Phase)

            • Pha chuyển giao(Commit Phase)

              • Các bước trong pha chuyển giao(Steps in the Commit Phase)

              • Đảm bảo tính nhất quán csdl tổng thể(Guaranteeing Global Database Consistency)

              • Pha quên (Forget Phase)

              • CÁc giao dịch nghi ngờ(In-Doubt Transactions)

                • Phân giải tự động trong các giao dịch nghi ngờ(Automatic Resolution of In-Doubt Transactions)

                  • Sự cố trong pha chuẩn bị(Failure During the Prepare Phase)

                  • Figure 31-5 Failure During Prepare Phase

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

Tài liệu liên quan