1 / 19

Allowing Multi-user Access

Allowing Multi-user Access. Grant GRANT <priv> ON <object> TO <user> |WITH GRANT OPTION / WITH ADMIN OPTION| <user> can be PUBLIC or a role <priv> can be all Revoke REVOKE <priv> ON <object> FROM <user> Very effective when used with views. Oracle Object Privs. ALTER DELETE EXECUTE

clancy
Download Presentation

Allowing Multi-user Access

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Allowing Multi-user Access • Grant • GRANT <priv> ON <object> TO <user> • |WITH GRANT OPTION / WITH ADMIN OPTION| • <user> can be PUBLIC or a role • <priv> can be all • Revoke • REVOKE <priv> ON <object> FROM <user> • Very effective when used with views

  2. Oracle Object Privs • ALTER • DELETE • EXECUTE • INDEX • INSERT • REFERENCES • SELECT • UPDATE

  3. Problems with Concurrent Access • Problems: • Lost updates • Uncommitted Data • Inconsistent retrievals • Solution • Resource Locking

  4. Locking Granularity • Database • Locks the entire database • Not efficient • Table • Locks one table • Sometimes needed for batch updates • Not very efficient • Page • Usually contains multiple rows • Locks a unit corresponding to a the working unit of the OS • Row • Locks one row of a table • Most commonly used locking level • Very efficient • Column • Locks only certain attributes of a row.

  5. Lock Types and Strategies Exclusive vs Shared Locks (lock type) • Exclusive • Will not allow another transaction to obtain a lock of any kind. • Shared • Allows multiple transactions to share a read only lock on the data. • Will not allow any transaction to write the locked rows. • Can potentially be upgraded to an Exclusive lock Optimistic vs Pessimistic Locking (locking strategy) • Optimistic • No locking occurs until the transaction is ready for submission by the client program • Can use several techniques to avoid business rule violations • Check row image before updating (timestamp, sequence number, or compare fields) • Update only changed fields • Use incremental updates to balances • Use conditional transactions with a timer • Client refreshes (not typically an option on web applications) • Pessimistic • Rows are locked at point of client retrieval of data • Client application will not proceed if locks cannot be obtained • Locks are not released until client application submits completed transaction

  6. ODBC and Access Record Locking When you edit data in a linked SQL database table using ODBC, Microsoft Access doesn't lock records; instead, the rules of that SQL database govern locking. In this instance, regardless of the record-locking setting you choose for your database, Microsoft Access always acts as though the No Locks setting has been selected.

  7. How to specify locking in Oracle • Table Lock Command • For update option of select command: Select * From Customer Where CustID = 123456 For update; Select * From Customer Where CustID = 123456 For updateNOWAIT;

  8. Where to specify locking in Access • Advanced tab of tools\options to Set default • RecordLocks property • Forms. Specifies how records in the underlying table or query are locked when data in a multiuser database is updated. • Reports. Specifies whether records in the underlying table or query are locked while a report is previewed or printed. • Queries. Specifies whether records in a query (typically an action query in a multiuser database) are locked while the query is run. • DAO. LockEdits property of recordset

  9. Transactions Transaction Definition: A logical unit of work that consists of one or more SQL statements that moves the database from one consistent state to another consistent state. Therefore, the transaction must succeed or fail as a unit. 01/01/02 Journal Entry #87543 110 Accounts Receivable – R. Smith(123) 1,045 401 Service Revenue – tax services 645 402 Service Revenue – consulting services 400 (provided services on account) Example: Would cause multiple related inserts and updates

  10. Oracle: No Transaction Defined Begin Update accounts set balance = balance + 1045 where accountnum = ‘110’; Commit; Update accounts set balance = balance + 645 where accountnum = ‘401’; Commit; Update accounts set balance = balance + 400 where accountnum = ‘402’; Commit; Update customers set BalDue = BalDue + 1045 where custid = 123; Commit; Insert into JournalEntries (JENumber, JEDate, Description) values (87543, ‘01-JAN-02’, ‘provided services on account’); Commit; Insert into DrCrDetail (JENumber, LineNumber, Account, Amount) values (87543, 1, ‘110’, 1045.00); Commit; Insert into DrCrDetail (JENumber, LineNumber, Account, Amount) values (87543, 2, ‘401’, 645.00); Commit; Insert into DrCrDetail (JENumber, LineNumber, Account, Amount) values (87543, 3, ‘402’, 400.00); Commit; End;

  11. Transaction Methods (Oracle) • Begin optional • Savepoint <savepointname> optional,creates a point that can be rolled back to • Commit [work] ends the current transaction and saves the changes. • Rollback [to <savepointname>] ends the current transaction and restores the databases in the Workspace object to the state they were in when the current transaction began.

  12. Transaction Methods (Access) • BeginTrans begins a new transaction. • CommitTrans ends the current transaction and saves the changes. • Rollback ends the current transaction and restores the databases in the Workspace object to the state they were in when the current transaction began.

  13. Transaction Methods (Oracle with lock waits) Begin Begin Transaction; Update accounts set balance = balance + 1045 where accountnum = ‘110’; Update accounts set balance = balance + 645 where accountnum = ‘401’; Update accounts set balance = balance + 400 where accountnum = ‘402’; Update customers set BalDue = BalDue + 1045 where custid = 123; Insert into JournalEntries (JENumber, JEDate, Description) values (87543, ‘01-JAN-02’, ‘provided services on account’); Insert into DrCrDetail(JENumber, LineNumber, Account, Amount) values (87543, 1, ‘110’, 1045.00); Insert into DrCrDetail (JENumber, LineNumber, Account, Amount) values (87543, 2, ‘401’, 645.00); Insert into DrCrDetail (JENumber, LineNumber, Account, Amount) values (87543, 3, ‘402’, 400.00); Commit; Exception rollback; End;

  14. Transaction Methods (Access) Sub PostAccounts() ‘Dim and assign variables including tempws, tempdb, temprs, posting Posting = False On Error GoTo ErrorCondition tempws.BeginTrans ' Start of transaction. Posting = True ‘complex set of operations here Posting = False tempws.CommitTrans Alldone ‘release variables ErrorCondition: MsgBox "Error!" If Posting Then tempws.Rollback End If Resume Alldone End Sub

  15. Transaction/Locking Problem • Problem: • Deadlock • Solutions • Prevention • e.g.: Two-phase locking with nowait • Dectection • Detect then kill and rollback one transaction

  16. Transaction Methods (Oracle with 2 stage locking) Begin Begin Transaction; Select * from accounts where accountnum in (‘110’, ‘401’, ‘402’) for update nowait; Select * from customers where custid = 123 for update nowait; Update accounts set balance = balance + 1045 where accountnum = ‘110’; Update accounts set balance = balance + 645 where accountnum = ‘401’; Update accounts set balance = balance + 400 where accountnum = ‘402’; Update customers set BalDue = BalDue + 1045 where custid = 123; Insert into JournalEntries (JENumber, JEDate, Description) values (87543, ‘01-JAN-02’, ‘provided services on account’); Insert into DrCrDetail(JENumber, LineNumber, Account, Amount) values (87543, 1, ‘110’, 1045.00); Insert into DrCrDetail (JENumber, LineNumber, Account, Amount) values (87543, 2, ‘401’, 645.00); Insert into DrCrDetail (JENumber, LineNumber, Account, Amount) values (87543, 3, ‘402’, 400.00); Commit; Exception rollback; End;

  17. New SELECT FOR UPDATE WAIT <seconds> Begin Begin Transaction; Select * from accounts where accountnum in (‘110’, ‘401’, ‘402’) for update wait 3; Select * from customers where custid = 123 for update wait 3; Update accounts set balance = balance + 1045 where accountnum = ‘110’; Update accounts set balance = balance + 645 where accountnum = ‘401’; Update accounts set balance = balance + 400 where accountnum = ‘402’; Update customers set BalDue = BalDue + 1045 where custid = 123; Insert into JournalEntries (JENumber, JEDate, Description) values (87543, ‘01-JAN-02’, ‘provided services on account’); Insert into DrCrDetail(JENumber, LineNumber, Account, Amount) values (87543, 1, ‘110’, 1045.00); Insert into DrCrDetail (JENumber, LineNumber, Account, Amount) values (87543, 2, ‘401’, 645.00); Insert into DrCrDetail (JENumber, LineNumber, Account, Amount) values (87543, 3, ‘402’, 400.00); Commit; Exception rollback; End;

  18. Access Record Selector Icons

More Related