Administração e Optimização de Bases de Dados

31
AOBD07/08 AOBD07/08 Administração e Administração e Optimização de Bases de Optimização de Bases de Dados Dados Enquadramento Enquadramento Programa Programa Bibliografia Bibliografia Planeamento teóricas e Planeamento teóricas e laboratórios laboratórios Avaliação Avaliação Corpo docente Corpo docente

description

Administração e Optimização de Bases de Dados. Enquadramento Programa Bibliografia Planeamento teóricas e laboratórios Avaliação Corpo docente. Enquadramento. Cadeiras de gestão de dados e tratamento de informação DEI 2007/08 : BD (3º ano LEIC e LERCI) GTI (1º ano MEIC/SIE) - PowerPoint PPT Presentation

Transcript of Administração e Optimização de Bases de Dados

Page 1: Administração e Optimização de Bases de Dados

AOBD07/08AOBD07/08

Administração e Optimização Administração e Optimização de Bases de Dadosde Bases de Dados

Enquadramento Enquadramento ProgramaPrograma BibliografiaBibliografia Planeamento teóricas e laboratóriosPlaneamento teóricas e laboratórios AvaliaçãoAvaliação Corpo docenteCorpo docente

Page 2: Administração e Optimização de Bases de Dados

AOBD07/08AOBD07/08

EnquadramentoEnquadramento

Cadeiras de gestão de dados e tratamento Cadeiras de gestão de dados e tratamento de informação DEI 2007/08 :de informação DEI 2007/08 :

BDBD (3º ano LEIC e LERCI) (3º ano LEIC e LERCI) GTIGTI (1º ano MEIC/SIE) (1º ano MEIC/SIE) SADSAD (1º ano MEIC e MERC) (1º ano MEIC e MERC) AOBDAOBD (1º ano MEIC/TSI e MERC) (1º ano MEIC/TSI e MERC)

Page 3: Administração e Optimização de Bases de Dados

AOBD07/08AOBD07/08

BibliografiaBibliografia Database System ConceptsDatabase System Concepts, Silberchatz, Korth, , Silberchatz, Korth,

Sudarshan 5ª edição, McGraw Hill, 2005Sudarshan 5ª edição, McGraw Hill, 2005 Database Management SystemsDatabase Management Systems, Raghu , Raghu

Ramakrishnan, Johannes Gehrke 3ª edição, Mc Ramakrishnan, Johannes Gehrke 3ª edição, Mc Graw Hill, 2002Graw Hill, 2002

Database Tuning: Principles, Experiments, and Database Tuning: Principles, Experiments, and Troubleshooting TechniquesTroubleshooting Techniques, Dennis Shasha & , Dennis Shasha & Philippe Bonnet, Morgan Kaufmann, 2003.Philippe Bonnet, Morgan Kaufmann, 2003.

Page 4: Administração e Optimização de Bases de Dados

AOBD07/08AOBD07/08

Programa (1)Programa (1) Armazenamento e Sistema de Ficheiros: cap 11 Armazenamento e Sistema de Ficheiros: cap 11

(Silb), 9 (Raghu)(Silb), 9 (Raghu) Técnicas de indexação (B+tree e hash-based) – cap Técnicas de indexação (B+tree e hash-based) – cap

12 (Silb), 10 e 11 (Raghu)12 (Silb), 10 e 11 (Raghu) Processamento de interrogações – cap 13(Silb), 12 e Processamento de interrogações – cap 13(Silb), 12 e

13 (Raghu), 13 (Raghu), Optimização de interrogações – cap 14 (Silb), 15 Optimização de interrogações – cap 14 (Silb), 15

(Raghu)(Raghu) Gestão de Transações – cap 15 (Silb), 16 (Raghu)Gestão de Transações – cap 15 (Silb), 16 (Raghu) Controlo de Concorrência – cap 16(Silb), 17 (Raghu)Controlo de Concorrência – cap 16(Silb), 17 (Raghu) Gestão de Recuperação – cap 17(Silb), 18 (Raghu)Gestão de Recuperação – cap 17(Silb), 18 (Raghu)

Page 5: Administração e Optimização de Bases de Dados

AOBD07/08AOBD07/08

Programa (2)Programa (2) Principios de tuningPrincipios de tuning Lock tuningLock tuning Log tuningLog tuning Storage tuningStorage tuning OS tuningOS tuning Index tuningIndex tuning Query processing tuningQuery processing tuning API tuningAPI tuning

(Shasha & Bonnet e alguns capítulos do Raghu e/ou (Shasha & Bonnet e alguns capítulos do Raghu e/ou Silberchatz)Silberchatz)

Page 6: Administração e Optimização de Bases de Dados

AOBD07/08AOBD07/08

PlaneamentoPlaneamento Aulas teóricasAulas teóricas: 1H30: 1H30

Matéria (slides baseados no livro e artigos)Matéria (slides baseados no livro e artigos)

Aulas laboratóroAulas laboratóro: 1H30: 1H30 SQLServer 2005SQLServer 2005 Material de apoio adicional: livros on-line e Material de apoio adicional: livros on-line e

guias de laboratórioguias de laboratório

Page 7: Administração e Optimização de Bases de Dados

AOBD07/08AOBD07/08

AvaliaçãoAvaliação ExameExame (52%): (52%):

Nota mínima: 9,5vNota mínima: 9,5v Mini-projectosMini-projectos (48%): (48%):

Grupos de 3 pessoasGrupos de 3 pessoas Exercícios “de papel e lápis” e/ou com SQLServer Exercícios “de papel e lápis” e/ou com SQLServer

2005.2005. Nota mínima: 9,5vNota mínima: 9,5v

Page 8: Administração e Optimização de Bases de Dados

AOBD07/08AOBD07/08

Corpo docenteCorpo docente Helena Galhardas (responsável)Helena Galhardas (responsável) Pável CaladoPável Calado

Bruno Martins (laboratórios) Bruno Martins (laboratórios)

Page 9: Administração e Optimização de Bases de Dados

AOBD07/08AOBD07/08

Chapter 1: IntroductionChapter 1: Introduction Purpose of database systemsPurpose of database systems Data abstraction levelsData abstraction levels Data models Data models SQL :Data Definition Language and Data SQL :Data Definition Language and Data

Manipulation LanguageManipulation Language Transaction management Transaction management Database usersDatabase users DBMS structureDBMS structure Typical database architecturesTypical database architectures

Page 10: Administração e Optimização de Bases de Dados

AOBD07/08AOBD07/08

Database management systems Database management systems (DBMS)(DBMS)

Collection of Collection of interrelated datainterrelated data and a and a set of programsset of programs to access to access the data the data

DBMS contains DBMS contains relevantrelevant information about a particular enterprise information about a particular enterprise DBMS provides an environment that is both DBMS provides an environment that is both convenientconvenient and and

efficientefficient to use. to use. Database applications:Database applications:

• Banking: all transactionsBanking: all transactions• Airlines: reservations, schedulesAirlines: reservations, schedules• Universities: registration, gradesUniversities: registration, grades• Sales: customers, products, purchasesSales: customers, products, purchases• Manufacturing: production, inventory, orders, supply chainManufacturing: production, inventory, orders, supply chain• Human resources: employee records, salaries, tax deductionsHuman resources: employee records, salaries, tax deductions

Page 11: Administração e Optimização de Bases de Dados

AOBD07/08AOBD07/08

DBMS vs File Systems (1)DBMS vs File Systems (1) In the early days, database applications were In the early days, database applications were

built on top of file systemsbuilt on top of file systems Drawbacks of using file systems to store data:Drawbacks of using file systems to store data:

Data redundancy and inconsistency: Data redundancy and inconsistency: Multiple file Multiple file formats, duplication of information in different filesformats, duplication of information in different files

Difficulty in accessing dataDifficulty in accessing data: Need to write a new : Need to write a new program to carry out each new taskprogram to carry out each new task

Data isolationData isolation: Multiple files and formats: Multiple files and formats Integrity problems: Integrity problems: Integrity constraints (e.g. account Integrity constraints (e.g. account

balance > 0) become part of program code; Hard to balance > 0) become part of program code; Hard to add new constraints or change existing onesadd new constraints or change existing ones

Page 12: Administração e Optimização de Bases de Dados

AOBD07/08AOBD07/08

DBMS vs File Systems (2)DBMS vs File Systems (2) Drawbacks of using file systems (cont.) Drawbacks of using file systems (cont.)

Atomicity of updatesAtomicity of updates• Failures may leave database in an inconsistent state with Failures may leave database in an inconsistent state with

partial updates carried outpartial updates carried out E.g. transfer of funds from one account to another should either E.g. transfer of funds from one account to another should either

complete or not happen at allcomplete or not happen at all Concurrent access by multiple usersConcurrent access by multiple users

• Concurrent access needed for performanceConcurrent access needed for performance• Uncontrolled concurrent accesses can lead to Uncontrolled concurrent accesses can lead to

inconsistenciesinconsistencies E.g. two people reading a balance and updating it at the same timeE.g. two people reading a balance and updating it at the same time

Security problemsSecurity problems……. DBMS. DBMS offer solutions to all the above problems! offer solutions to all the above problems!

Page 13: Administração e Optimização de Bases de Dados

AOBD07/08AOBD07/08

Why use a DBMS?Why use a DBMS? DataData independence independence and and efficient efficient accessaccess

ReducedReduced application development time. application development time.

Data Data integrityintegrity and and securitysecurity..

UniformUniform data administration. data administration.

ConcurrentConcurrent access, access, recoveryrecovery from crashes. from crashes.

Page 14: Administração e Optimização de Bases de Dados

AOBD07/08AOBD07/08

Levels of data abstraction (1)Levels of data abstraction (1)Physical levelPhysical level: describes how data are stored.: describes how data are stored.Logical levelLogical level: describes data stored in the : describes data stored in the

database, and the relationships among the database, and the relationships among the data.data.

View levelView level: application programs hide details : application programs hide details of data types. Views can also hide of data types. Views can also hide information (e.g., salary) for security information (e.g., salary) for security purposes. purposes.

Page 15: Administração e Optimização de Bases de Dados

AOBD07/08AOBD07/08

Levels of data abstraction (2)Levels of data abstraction (2)

Page 16: Administração e Optimização de Bases de Dados

AOBD07/08AOBD07/08

Data ModelsData Models A collection of A collection of conceptual toolsconceptual tools for describing: for describing:

data data data relationshipsdata relationships data semanticsdata semantics data constraintsdata constraints

Ex:Ex: Entity-Relationship model, UML class diagramEntity-Relationship model, UML class diagram Relational modelRelational model Other models: Other models:

• semi-structured data models (XML used to represent sstr. data)semi-structured data models (XML used to represent sstr. data)• older models: network model and hierarchical modelolder models: network model and hierarchical model

Page 17: Administração e Optimização de Bases de Dados

AOBD07/08AOBD07/08

Entity-Relationship ModelEntity-Relationship ModelExample of schema in the entity-relationship modelExample of schema in the entity-relationship model

Page 18: Administração e Optimização de Bases de Dados

AOBD07/08AOBD07/08

A Sample Relational DatabaseA Sample Relational Database

Page 19: Administração e Optimização de Bases de Dados

AOBD07/08AOBD07/08

Data Independence Data Independence Applications insulated from how data is Applications insulated from how data is

structured and stored.structured and stored.Logical data independence: Protection from Protection from

changes in the changes in the logical structure of data.structure of data.CustomerPublic(customer-id, customer-name)CustomerPublic(customer-id, customer-name)CustomerPrivate(customer-id, salary)CustomerPrivate(customer-id, salary)

Physical data independence: Protection from Protection from changes in the physical structure of data.changes in the physical structure of data.

One of the most important benefits of using a DBMS!

Page 20: Administração e Optimização de Bases de Dados

AOBD07/08AOBD07/08

Instances and Schemas Instances and Schemas Schema: : the logical structure of the database, the logical structure of the database, a a

description of a particular collection of data, using description of a particular collection of data, using a given data modela given data model Analogous to type information of a variable in a Analogous to type information of a variable in a

programprogram Physical schema: database design at the physical level: database design at the physical level Logical schema: database design at the logical level: database design at the logical level

Instance: : the actual content of the database at a the actual content of the database at a particular point in time particular point in time Analogous to the value of a variableAnalogous to the value of a variable

Page 21: Administração e Optimização de Bases de Dados

AOBD07/08AOBD07/08

ExampleExample

External schema (View): (View): CustomerPublic (customer-id, customer-name)CustomerPublic (customer-id, customer-name)

Logical schema: : Customer(customer-id, customer-name, customer-street, customer-age)Customer(customer-id, customer-name, customer-street, customer-age) Account(account-number, balance) Account(account-number, balance) Depositor(account-number, customer-id)Depositor(account-number, customer-id)

Physical schema:: Relations stored as unordered files. Relations stored as unordered files. Index on first column of Customer.Index on first column of Customer.

Page 22: Administração e Optimização de Bases de Dados

AOBD07/08AOBD07/08

SQL: Structured Query LanguageSQL: Structured Query Language A DBMS provides:A DBMS provides:

a a Data Definition LanguageData Definition Language (DDL) (DDL) a a Data Manipulation LanguageData Manipulation Language (DML) (DML)

as part of a single DB language: as part of a single DB language: SQLSQL

Most widely used Most widely used declarativedeclarative query language query language• ProceduralProcedural – user specifies what data is required and how to get – user specifies what data is required and how to get

those data those data • DeclarativeDeclarative – user specifies what data is required without specifying – user specifies what data is required without specifying

how to get those datahow to get those data

Page 23: Administração e Optimização de Bases de Dados

AOBD07/08AOBD07/08

SQL: Data Definition Language SQL: Data Definition Language (DDL)(DDL)

DDL: Specification notation for defining the database: Specification notation for defining the database• Ex: Ex:

create tablecreate table accountaccount( ( account-numberaccount-number charchar(10),(10), balancebalance integerinteger))

DDL compiler generates a set of tables stored in a DDL compiler generates a set of tables stored in a data dictionary

Data dictionary contains Data dictionary contains metadata (i.e., data about (i.e., data about data)data) Ex: Database schema, consistency constraints, Ex: Database schema, consistency constraints, access access

methodsmethods

Page 24: Administração e Optimização de Bases de Dados

AOBD07/08AOBD07/08

SQL: Data Manipulation SQL: Data Manipulation Language (DML)Language (DML)

Language for Language for accessing and manipulatingaccessing and manipulating data data

Ex: find the name of the customer with Ex: find the name of the customer with customer-id 192-83-7465customer-id 192-83-7465

selectselect customer.customer-namecustomer.customer-namefromfrom customercustomerwherewhere customer.customer-idcustomer.customer-id = ‘192-83- = ‘192-83-

7465’7465’

Page 25: Administração e Optimização de Bases de Dados

AOBD07/08AOBD07/08

Transaction ManagementTransaction Management A A transactiontransaction is a collection of operations that performs a single is a collection of operations that performs a single

logical function in a database applicationlogical function in a database application Ex: funds transfer includes withdraw from account A and deposit into Ex: funds transfer includes withdraw from account A and deposit into

account Baccount B

Transaction management component ensures that the database Transaction management component ensures that the database remains in a remains in a consistentconsistent (correct) state despite system failures (correct) state despite system failures (e.g., power failures and operating system crashes) and (e.g., power failures and operating system crashes) and transaction failures.transaction failures.

Transactions must be Transactions must be atomicatomic, , consistentconsistent, , isolatedisolated and and durable/persistentdurable/persistent

Page 26: Administração e Optimização de Bases de Dados

AOBD07/08AOBD07/08

Database Users (1)Database Users (1) Users are differentiated by the way they Users are differentiated by the way they

expect to interact with the systemexpect to interact with the systemApplication programmersApplication programmers: interact with system : interact with system

through DML calls through DML calls Sophisticated usersSophisticated users: form requests in a database : form requests in a database

query languagequery languageNaïve/End usersNaïve/End users: invoke one of the permanent : invoke one of the permanent

application programs that have been written application programs that have been written previouslypreviously• E.g. people accessing database over the web, bank E.g. people accessing database over the web, bank

tellers, clerical stafftellers, clerical staff

Page 27: Administração e Optimização de Bases de Dados

AOBD07/08AOBD07/08

Database Users (2)Database Users (2) Database administratorsDatabase administrators Coordinates all the activities of the database Coordinates all the activities of the database

system; has a good understanding of the enterprise’s information system; has a good understanding of the enterprise’s information resources and needs. Duties include:resources and needs. Duties include:• Schema definitionSchema definition• Storage structure and access method definitionStorage structure and access method definition• Schema and physical organization modificationSchema and physical organization modification• Granting user authority to access the databaseGranting user authority to access the database• Specifying integrity constraintsSpecifying integrity constraints• Acting as liaison with usersActing as liaison with users• Monitoring performance, tuning the system and respondingMonitoring performance, tuning the system and responding to changes in requirementsto changes in requirements

Page 28: Administração e Optimização de Bases de Dados

AOBD07/08AOBD07/08

Overall DBMS Structure Overall DBMS Structure

Page 29: Administração e Optimização de Bases de Dados

AOBD07/08AOBD07/08

Database TuningDatabase Tuning

Database Tuning is the activity of making Database Tuning is the activity of making a database application run more quickly. a database application run more quickly.

“More quickly” usually means higher “More quickly” usually means higher throughput, though it may mean lower throughput, though it may mean lower

response time for time-critical applications.response time for time-critical applications.

Page 30: Administração e Optimização de Bases de Dados

AOBD07/08AOBD07/08

ApplicationProgrammer

(e.g., business analyst,Data architect)

SophisticatedApplicationProgrammer

(e.g., SAP admin)

DBA,Tuner

Hardware[Processor(s), Disk(s), Memory]

Operating System

Concurrency Control Recovery

Storage SubsystemIndexes

Query Processor

Application

Page 31: Administração e Optimização de Bases de Dados

AOBD07/08AOBD07/08

Next lectureNext lecture Ch 11: Storage and File StructureCh 11: Storage and File Structure