Database Administration


Published on

  • Be the first to comment

  • Be the first to like this

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Database Administration

  1. 1. Database Administration Alan Schneider
  2. 2. Overview <ul><li>Implementing a Relational Database </li></ul><ul><ul><li>Instance </li></ul></ul><ul><ul><li>Tablespaces, Redo logs, Control Files </li></ul></ul><ul><ul><li>Object Owner (Schema) </li></ul></ul><ul><ul><li>Table and Views </li></ul></ul><ul><ul><li>Indexes </li></ul></ul><ul><ul><li>Public/Private Synonyms </li></ul></ul><ul><ul><li>Database Security </li></ul></ul><ul><li>Concurrency Control / Locking </li></ul><ul><li>Database Recovery </li></ul><ul><li>Triggers </li></ul><ul><li>Stored Procedures/Functions </li></ul><ul><li>Application Security </li></ul>
  3. 3. Implementing a Relational Database <ul><li>Instance - Logical In Memory </li></ul><ul><li>Tablespaces (data files), Redo Logs, Control Files – Physical on disk drives </li></ul><ul><ul><li>I/O Performance --The more physical disks and disk controllers there are, the better </li></ul></ul><ul><ul><li>Data Recovery -- Having your data spread over may disks, the easier it will be to recover data when failures occur </li></ul></ul><ul><ul><li>RDBMS Crashes -- Redo Log and control file redundancy over multiple disks ensures you can recover from a DB crash or disk failures. </li></ul></ul>
  4. 4. Implementing a Relational Database <ul><li>Object Owner (Schema) </li></ul><ul><ul><li>create user app_owner identified by app_owner; </li></ul></ul><ul><ul><ul><li>normally you would also assign the users default user and temporary tablespace used when creating objects and when interacting with the data.  The assignment of the tablespace can also be done when creating the objects individually </li></ul></ul></ul>
  5. 5. Implementing a Relational Database <ul><li>Tables and Views </li></ul>Create table employee (  emp_id number primary key,  fname varchar2(30) NOT NULL,  lname varchar2(30) NOT NULL,  emp_mi varchar2(1),  emp_city varchar2(25),  emp_state varchar2(2),  emp_zip varchar2(9),  dept_no number references department(dept_no));
  6. 6. Implementing a Relational Database <ul><li>Indexes </li></ul><ul><ul><li>Indexes allow rows to be quickly accessed when searching by sorting the data and reducing the number of database blocks that need to be read to find the data </li></ul></ul><ul><ul><ul><li>For example when searching on a table the does not contain an index the entire table will need to be accessed.  This will require several database block reads if it is a very large table containing many records </li></ul></ul></ul><ul><ul><ul><li>However, if an index is used which only holds the indexed column and a pointer back to all of the data for that row, fewer database block will need to be read and results in the rows returning much faster </li></ul></ul></ul>
  7. 7. Data Index Example <ul><li>The ROW ID is maintained internally by the database and is NOT part of the table or index when created </li></ul><ul><li>create index last_name_ndx on employee(lname); </li></ul>12348 Yeager 12347 Smith 12346 Smith 12345 Jones ROWID lname 1 76309 CA Modesto V Mark Smith 12346 3 23873 FL Miami C Kathy Smith 12347 2 34823 AL Birmingham G Charles Yeager 12348 2 60601 IL Chicago A Jennifer Jones 12345 dept_no ip state city MI fname lname ROWID *
  8. 8. Implementing a Relational Database <ul><li>Synonyms </li></ul><ul><ul><li>Private </li></ul></ul><ul><ul><ul><li>Must be prefixed with schema name to be seen </li></ul></ul></ul><ul><ul><li>Public </li></ul></ul><ul><ul><ul><li>Do not need to prefix with schema name </li></ul></ul></ul><ul><ul><ul><ul><li>Location Transparency </li></ul></ul></ul></ul><ul><ul><ul><li>Can only be created by a Database Administrator </li></ul></ul></ul><ul><li>create public synonym department </li></ul><ul><li>for department; </li></ul>
  9. 9. Implementing a Relational Database <ul><li>Database Security </li></ul><ul><ul><li>Limits certain actions on certain objects to certain users </li></ul></ul><ul><ul><ul><li>User Type </li></ul></ul></ul><ul><ul><ul><ul><li>Connect </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Resource </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Database Administrator </li></ul></ul></ul></ul><ul><ul><ul><li>Roles/Groups and Privileges/Permissions </li></ul></ul></ul><ul><ul><ul><li>Users => Roles/Groups => privileges/Permissions on objects </li></ul></ul></ul>
  10. 10. Implementing a Relational Database <ul><li>Database Security </li></ul><ul><li>grant select, insert, update, delete </li></ul><ul><li>on department to app_user; </li></ul><ul><li>grant <custom_role> to app_user </li></ul><ul><li>grant execute on pkg_emp_mgmt to app_user; </li></ul>
  11. 11. Concurrency Control / Locking <ul><li>Concurrency control measures are take to ensure that one user's work does not inappropriately influence another user's work. </li></ul><ul><li>No concurrency control technique or mechanism is ideal for all circumstances.  </li></ul><ul><ul><li>For example, a user can obtain very strict concurrency control by locking the entire database, but while he or she is processing, no other user will be able to do anything. </li></ul></ul>
  12. 12. Concurrency Control / Locking <ul><li>Disallows changing a value if another user is already using the data </li></ul><ul><li>Implicit locks are issues by the database system or by the application </li></ul><ul><li>Explicit locks are placed by command </li></ul><ul><li>Lock Granularity refers to whether the lock is at the page, table or database level </li></ul><ul><li>Exclusive Lock locks access of any type. No other transaction can read or change the data </li></ul><ul><li>Shared Lock locks access from change, but not from read </li></ul><ul><li>Deadlock </li></ul>
  13. 13. Concurrency Control / Locking <ul><li>Optimistic Locking </li></ul><ul><ul><li>Assumes that no conflicts will occur.  </li></ul></ul><ul><ul><li>Is accomplished after an attempt to change </li></ul></ul><ul><ul><li>Better for Internet applications </li></ul></ul><ul><li>Pessimistic Locking </li></ul><ul><ul><li>Assumes that that conflict will occur.  </li></ul></ul><ul><ul><li>Is accomplished before an attempt to change </li></ul></ul><ul><ul><li>Better for OLTP and maybe some Intranet Applications </li></ul></ul>Always Until Released Pessimistic Sometimes Update Only Optimistic Success Rate Length of Lock
  14. 14. Database Recovery <ul><li>Reprocessing </li></ul><ul><ul><li>Go back to a know good point and reprocess workload using the application </li></ul></ul><ul><ul><li>This may mean that the records are processed out of order </li></ul></ul><ul><li>Recovery via Rollback/Roll forward </li></ul><ul><ul><li>Data is stored in a Log to maintain a record of the changes </li></ul></ul><ul><ul><li>Roll forward:  Go back to know good point, and based on the logged changes since the save, reapply the changes based on the log files </li></ul></ul><ul><ul><li>Rollback:  Undo changes made by erroneous or partially processed transactions </li></ul></ul><ul><ul><li>&quot;Before Image&quot; holds the initial value of the column </li></ul></ul><ul><ul><li>&quot;After Image&quot; holds the changed value of the column </li></ul></ul><ul><ul><li>The &quot;Before Image&quot; logically goes away once a COMMIT is issued that writes the &quot;After Image&quot;  value to the physical database </li></ul></ul>
  15. 15. Triggers <ul><li>A special type of stored procedure </li></ul><ul><ul><li>Invoked when a special condition occurs, such as Before or After inserting, updating or deleting from a table </li></ul></ul><ul><li>create or replace trigger check_inventory_trg After update of inv_quantity on store_inventory for each row when new.inv_quantity < 25 </li></ul><ul><li>DECLARE </li></ul><ul><li>BEGIN </li></ul><ul><li>   Add code here ... </li></ul><ul><li>such as update the items_to_order table </li></ul><ul><li>END; </li></ul>
  16. 16. Stored Procedures and Functions <ul><li>Compilation of Query Language statements used to process complex operations. </li></ul><ul><li>Normally requires input of variables. </li></ul>
  17. 17. Stored Procedures and Functions <ul><li>create or replace procedure adjust_salary(p_emp_no IN integer </li></ul><ul><li>                ,p_raise IN integer) </li></ul><ul><li>AS </li></ul><ul><li>BEGIN </li></ul><ul><li>update employee   Set salary = salary + (salary * (p_raise/l00)) where emp_raise_date < (sysdate - 18)   and emp_no = p_emp_no; </li></ul><ul><li>END; </li></ul><ul><li>Execution of program would only require the user to type the following </li></ul><ul><ul><li>Exec adjust_salary (23, 3) ; </li></ul></ul><ul><ul><ul><li>23 = employee number 3 = the percentage of raise being applied </li></ul></ul></ul>
  18. 18. Application Security <ul><li>Controlled by the developer and based on Procedural business Rules.  </li></ul><ul><ul><li>For example an employee is allowed to enter orders but they cannot approve orders for release to shipping. </li></ul></ul>
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.