Friday 3 November 2017

Flytte Gjennomsnittet Orakel 11g


Om SQL-funksjoner SQL-funksjoner er bygd inn i Oracle Database og er tilgjengelige for bruk i forskjellige relevante SQL-setninger. Ikke forveksle SQL-funksjoner med brukerdefinerte funksjoner skrevet i PLSQL. Hvis du ringer en SQL-funksjon med et argument av en datatype enn datatypen som forventes av SQL-funksjonen, forsøker Oracle å konvertere argumentet til den forventede datatypen før du utfører SQL-funksjonen. De kombinerte verdiene til NLSCOMP - og NLSSORT-innstillingene bestemmer reglene som karakterer sorteres og sammenlignes med. Hvis NLSCOMP er satt til LINGUISTIC for databasen, blir alle enheter i dette kapitlet tolket i henhold til reglene som er spesifisert av NLSSORT-parameteren. Hvis NLSCOMP ikke er satt til LINGUISTIC. da tolkes funksjonene uten hensyn til NLSSORT-innstillingen. NLSSORT kan eksplisitt settes. Hvis det ikke er angitt eksplisitt, kommer det fra NLSLANGUAGE. Vennligst se Oracle Database Globalization Support Guide for mer informasjon om disse innstillingene. I syntaksdiagrammer for SQL-funksjoner angis argumenter av deres datatyper. Når parameterfunksjonen vises i SQL-syntaks, erstatt den med en av funksjonene som er beskrevet i denne delen. Funksjoner grupperes av datatyper av deres argumenter og deres returverdier. Når du bruker SQL-funksjoner til LOB-kolonner, oppretter Oracle Database midlertidige LOB'er under SQL - og PLSQL-behandling. Du bør sørge for at midlertidig tabellplasskvote er tilstrekkelig til å lagre disse midlertidige LOB for din søknad. Om brukerdefinerte funksjoner for informasjon om brukerfunksjoner og datakonvertering for implisitt konvertering av datatyper Oracle Text Reference for informasjon om funksjoner som brukes med Oracle Text Oracle Data Mining Application Utviklerveiledning for informasjon om hyppige elementsettingsfunksjoner som brukes med Oracle Data Mining Syntaxen viser Følgende kategorier av funksjoner følger: Avsnittene som følger følger de innebygde SQL-funksjonene i hver av gruppene som er illustrert i de foregående diagrammene, bortsett fra brukerdefinerte funksjoner. Alle de innebygde SQL-funksjonene beskrives deretter i alfabetisk rekkefølge. Enkeltradningsfunksjoner Enkeltradsfunksjoner returnerer en enkelt resultatrader for hver rad i et forespurt tabell eller visning. Disse funksjonene kan vises i utvalgslister, WHERE-klausuler, START MED og CONNECT BY-klausuler og HAVING-klausuler. Numeriske funksjoner Numeriske funksjoner aksepterer numerisk inngang og returnerer numeriske verdier. De fleste numeriske funksjoner som returnerer NUMBER-verdier som er nøyaktige til 38 desimaltall. De transcendentale funksjonene COS. COSH. EXP. LN. LOGG. SYND. SINH. ROT. TAN. og TANH er nøyaktig til 36 desimaltall. Transcendental funksjonene ACOS. SOM I. BRUNFARGE. og ATAN2 er nøyaktig til 30 desimaltall. De numeriske funksjonene er: Tegn Funksjoner Retur Karakter Verdier Karakterfunksjoner som returnerer tegnverdier returverdier av følgende datatyper med mindre annet er dokumentert: Hvis inngangsargumentet er CHAR eller VARCHAR2. så returneres verdien VARCHAR2. Hvis inngangsargumentet er NCHAR eller NVARCHAR2. da returneres verdien NVARCHAR2. Lengden på verdien returnert av funksjonen er begrenset av den maksimale lengden på datatypen som returneres. For funksjoner som returnerer CHAR eller VARCHAR2. Hvis lengden på returverdien overstiger grensen, avkortes Oracle Database og returnerer resultatet uten en feilmelding. For funksjoner som returnerer CLOB-verdier, hvis lengden på returverdiene overstiger grensen, øker Oracle en feil og returnerer ingen data. Karakterfunksjonene som returnerer karakterverdier er: NLS Karakterfunksjoner NLS-karakterfunksjonene returnerer informasjon om tegnsettet. NLS-tegnfunksjonene er: Karakterfunksjoner Returnerende nummerverdier Karakterfunksjoner som returnerer tallverdier kan ta som argument ethvert tegn datatype. Tegnet funksjonene som returnerer nummerverdier er: Datetime Funksjoner Datetime funksjoner opererer på dato (DATE), tidsstempel (TIMESTAMP. TIMESTAMP WITH TIME ZONE. Og TIMESTAMP WITH LOCAL TIME ZONE), og intervall (INTERVAL DAG TIL ANDRE INTERVALÅR TIL MÅNED) verdier. Noen av datetime-funksjonene ble designet for datatypen Oracle DATE (ADDMONTHS. CURRENTDATE. LASTDAY. NEWTIME og NEXTDAY). Hvis du gir en tidsstempelverdi som deres argument, konverterer Oracle Database interntype til en DATE-verdi og returnerer en DATE-verdi. Unntakene er MONTHSBETWEEN-funksjonen, som returnerer et nummer, og ROUND og TRUNC-funksjonene, som ikke aksepterer tidsstempel eller intervallverdier i det hele tatt. De resterende datetime-funksjonene ble utformet for å akseptere noen av de tre typer data (dato, tidsstempel og intervall) og å returnere en verdi av en av disse typene. Alle datetime-funksjonene som returnerer gjeldende system datetime-informasjon, for eksempel SYSDATE. SYSTIMESTAMP. CURRENTTIMESTAMP. og så videre, blir evaluert en gang for hver SQL-setning, uansett hvor mange ganger de refereres til i setningen. Datetime-funksjonene er: Generelle sammenligningsfunksjoner De generelle sammenligningsfunksjonene bestemmer den største og minste verdien fra et sett med verdier. De generelle sammenligningsfunksjonene er: Konverteringsfunksjoner Konverteringsfunksjoner konverterer en verdi fra en datatype til en annen. Vanligvis følger skjemaet til funksjonsnavnene konvensjonens datatype til datatype. Den første datatypen er inngangsdatatypen. Den andre datatypen er utdata datatypen. SQL-konverteringsfunksjonene er: Store objektfunksjoner De store objektfunksjonene opererer på LOBs. De store objektfunksjonene er: Samlingsfunksjoner Samlingsfunksjonene opererer på innlejrede tabeller og varianter. SQL-samlingsfunksjonene er: Hierarkisk funksjon Den hierarkiske funksjonen bruker hierarkisk stiinformasjon til et resultatsett. Data Mining Funksjoner Data mining funksjonene fungerer på modeller som er bygget ved hjelp av DBMSDATAMINING pakken eller Oracle Data Mining Java API. SQL data mining funksjoner er: XML Funksjoner XML-funksjonene opererer på eller returnerer XML-dokumenter eller fragmenter. For mer informasjon om valg og spørring av XML-data ved hjelp av disse funksjonene, inkludert informasjon om formateringsutdata, se Oracle XML DB Developers Guide. SQL XML-funksjonene er: Kodings - og dekodingsfunksjoner Kodings - og dekodingsfunksjonene lar deg inspisere og avkode data i databasen. NULL-relaterte funksjoner De NULL-relaterte funksjonene gjør det mulig å håndtere null. NULL-relaterte funksjoner er: Miljø - og identifikasjonsfunksjoner Miljø - og identifiseringsfunksjonene gir informasjon om forekomsten og økten. Disse funksjonene er: Aggregate Funksjoner Aggregate funksjoner returnerer en enkelt resultatrad basert på grupper av rader, i stedet for på enkelte rader. Samlede funksjoner kan vises i utvalgte lister og i ORDER BY og HAVING-klausuler. De brukes vanligvis med GROUP BY-klausulen i en SELECT-setning, hvor Oracle Database deler rader av et forespurt tabell eller visning i grupper. I en spørring som inneholder en GROUP BY-setning, kan elementene i seleksjonslisten være aggregatfunksjoner, GROUP BY-uttrykk, konstanter eller uttrykk som involverer en av disse. Oracle bruker aggregatfunksjonene til hver gruppe av rader og returnerer en enkelt rad for hver gruppe. Hvis du unnlater GROUP BY-klausulen, bruker Oracle aggregatfunksjoner i valglisten til alle rader i spørrekategorien eller visningen. Du bruker aggregatfunksjoner i HAVING-klausulen for å eliminere grupper fra utgangen basert på resultatene av aggregatfunksjonene, i stedet for på verdiene for de enkelte radene i spørrekategorien eller visningen. Bruk av GROUP BY-klausulen: Eksempler og HAVING-klausulen for mer informasjon om GROUP BY-klausulen og HAVING-klausuler i spørringer og undersøkelser Mange (men ikke alle) aggregatfunksjoner som tar et enkelt argument, godtar disse klausulene: DISTINCT fører til at en samlet funksjon vurderes bare forskjellige verdier av argumentet uttrykket. ALLE forårsaker en samlet funksjon for å vurdere alle verdier, inkludert alle duplikater. For eksempel er DISTINCT-gjennomsnittet på 1, 1, 1 og 3 2. ALLE gjennomsnittet er 1,5. Hvis du ikke angir verken, er standard ALL. Noen aggregatfunksjoner tillater windowingclause. som er en del av syntaksen av analytiske funksjoner. Henvis til windowingclause for informasjon om denne klausulen. I oversikten over aggregatfunksjoner på slutten av denne delen blir funksjonene som tillater windowingclause etterfulgt av en stjerne () Alle aggregatfunksjoner unntatt COUNT (), GROUPING. og GROUPINGID ignorer nulls. Du kan bruke NVL-funksjonen i argumentet til en aggregatfunksjon for å erstatte en verdi for null. COUNT og REGRCOUNT returnerer aldri null, men returnerer enten et tall eller null. For alle gjenværende aggregatfunksjoner, hvis datasettet ikke inneholder noen rader, eller bare inneholder rader med nuller som argumenter for aggregatfunksjonen, returnerer funksjonen null. Aggregatet fungerer MIN. MAX. SUM. AVG. TELLE. Varians. og STDDEV. når etterfulgt av KEEP søkeordet, kan brukes i forbindelse med FIRST eller LAST-funksjonen for å operere på et sett med verdier fra et sett med rader som rangerer som FIRST eller LAST i forhold til en gitt sorteringsspesifikasjon. Se FIRST for mer informasjon. Du kan hekke aggregatfunksjoner. Eksempelvis beregner følgende eksempel gjennomsnittet av de maksimale lønnene til alle avdelingene i prøveskjemaet: Denne beregningen vurderer det indre aggregatet (MAX (lønn)) for hver gruppe definert av GROUP BY-klausulen (avdelingstid) og aggregater resultatene igjen. De samlede funksjonene er: Analytiske funksjoner Analytiske funksjoner beregner en samlet verdi basert på en gruppe rader. De adskiller seg fra aggregerte funksjoner ved at de returnerer flere rader for hver gruppe. Gruppen av rader kalles et vindu og er definert av analyticclause. For hver rad er et glidende vindu av rader definert. Vinduet bestemmer rekkevidden av rader som brukes til å utføre beregningene for den nåværende raden. Vinduestørrelser kan baseres på enten et fysisk antall rader eller et logisk intervall som tid. Analytiske funksjoner er det siste settet av operasjoner som utføres i en spørring, bortsett fra den endelige ORDER BY-klausulen. Alle blir sammen og alle der. GRUPPE AV. og HAVING klausuler er ferdig før de analytiske funksjonene blir behandlet. Derfor kan analytiske funksjoner bare vises i valglisten eller BESTILL BY-klausulen. Analytiske funksjoner blir ofte brukt til å beregne kumulative, flytte, sentrert og rapporterende aggregater. Oracle GoldenGate 11g - The Bridge to Everywhere Oracle GoldenGate 11g i Enterprise IOUG SELECT Journal 0411 Oracle GoldenGate har generert mye buzz i Oracle-fellesskapet siden dette var oppkjøpt av Oracle Corporation i 2015. GoldenGate-produktet markedsføres av Oracle som en nisjeapplikasjon, men en som kan brukes i nesten alle Oracle-miljøer. I tillegg har Oracle gjort det klart at de forventer at GoldenGate skal være hovedrepliseringsmetoden i fremtiden i stedet for Streams of Advanced Replication. Begrunnelsen bak dette er enkel: GoldenGate er en ekte heterogen replikasjonsløsning som ikke er bundet direkte til Oracle-programvaren. Ved å bruke GoldenGate, er det mulig å kopiere fra nesten hvilken som helst kommersiell database til enhver annen kommersiell database. Tilgjengelige plattformer inkluderer: DB2, MySQL, Oracle, SQLMX, SQL Server, Sybase, Teradata, TimesTen, flate filer og mange andre plattformer via Java. Programvaren kan replikere i nær sanntid eller med et lag, og kan ta en enkelt kilde og pumpe den til flere destinasjoner. GoldenGate er som motorveien for databaser, noe som gir rask overføring til og fra hvilken som helst plassering med mange ekstra destinasjoner som er lett tilgjengelige. GoldenGate fullfører disse oppgavene gjennom et enkelt sett med prosesser sentrert på Java Message Service (JMS) for kommunikasjon. Før vi dykker inn i hvordan GoldenGate kan brukes i ditt Oracle-miljø, kan vi gå gjennom komponentene i GoldenGate for å få bedre forståelse av programvaren. Et logisk arkitekturdiagram er vist nedenfor: (Kilde: Oracle GoldenGate Windows og UNIX Administrator Guide 11g Utgivelse 1 (11.1.1) E17341-01) Utdragsprosessen Det første trinnet i en replikasjonsprosess er å fange endringer i kildemiljøet. GoldenGate fullfører dette via Extract-prosesser som kan lese transaksjonslogger på kildesystemet og skrive endringsdata til en sti-fil (vi vil dekke dette neste). Multiple Extract-prosesser kan konfigureres som trekker forskjellige sett med data. Disse dataene kan bli trukket konstant (24x7 replikering), på en planlagt basis, eller til og med konfigurert som et hendelsebasert system hvor dataopptaket starter når visse dataendringer gjøres. Ved å lese fra transaksjonslogger, er GoldenGate i stand til å registrere endringer med svært minimal overhead til kildesystemet. Enda bedre, det er mulig å bruke et Oracle 11g Active DataGuard-miljø som en GoldenGate-kilde, noe som betyr at kildesystemet er knapt påvirket i det hele tatt. Utdragsprosessen kan også bruke lagret data som kilde i stedet for transaksjonslogger. Dette er mest nyttig for å lage en første kopi av en database til et målmiljø. Stien er hvor alle hentede endringer lagres. Den har en kombinasjon av DDL og DML. Trailfiler kan betegnes som enten en lokal sti som forblir på samme server som ekstraktet, eller en ekstern sti som sendes via TCPIP til et målsystem. GoldenGate opprettholder sporfilene Hovedansvaret for DBA er å opprinnelig opprette lagring og plassering for filene. Da data blir hentet, er det skrevet til stien filer. Etter hvert som filene fylles opp, dannes nye sporfiler, og dataene fortsetter å skrive. Etter hvert som data forbrukes, er GoldenGate i stand til å rense gamle sporinformasjon. Oracle-dokumentasjonen anbefaler at du bruker separate disker eller LUNer for stien filen for å gi optimal ytelse for GoldenGate behandling og sørge for at den ikke støter på andre ressurser på miljøet. Selv med kraftige systemer og rensing slått på, vil stien filen vokse raskt, spesielt i tilfelle nettverksbrudd, og dermed behovet for å gi en slik optimal ytelse. For å avgjøre hvor mye plass som kreves, anbefaler Oracle følgende formel: loggvolum på en time x maks antall timer nettverkstiden x 0.4 sporplass Dette er basert på Oracle estimerer at bare 40 av dataene i redologgene faktisk vil bli registrert av GoldenGate Extract - dette kan være mer eller mindre i ditt miljø og er avhengig av datamønstre. En av faktorene som gjør GoldenGate så fort er den begrensede mengden data som kreves for uttrekksprosessen. For eksempel kan GoldenGate trekke ut forpliktede transaksjoner mens redo-loggene holder alle transaksjoner enten engasjert eller ubestemt. Trailfiler er nesten alltid skrevet eksternt med det formål å replikere. Utpakningsprosessen kan imidlertid lagre stier lokalt slik at de kan hentes av en annen prosess kalt en datapumpe som sender stinavdataene til flere destinasjoner. Hvis en datapumpe ikke brukes, vil alle skriftlige data være på målsystemet og det kreves ingen lagring for sporfiler på kildemiljøet. Samleren går på målsystemet og mottar sti filinformasjon som skal skrives til disk. Da data blir hentet ut og sendt over nettverket, vil samleren plassere dataene i de riktige filene som skal hentes av replikeringsprosessen. Replikat-prosessen bruker data fra sporfiler på målsystemet. Denne prosessen er i stand til å analysere all stiinformasjon, kjøre DDL og DML mot målmiljøet, og registrerer skriftlige poster i et område kalt kontrollpanelbordet. For å opprettholde konsistens og garantidata hentes riktig etter feil, registrerer kontrollpunkttabellen fremdriften av replikatprosessene etter hvert som data forbrukes. Replikater er i stand til å laste store mengder data samtidig eller i en synkronisert konfigurasjon. For eksempel kan en replikat opprettes for å gjøre en innledende datalast fra et kildemiljø, og en annen kan opprettes for å fortsette å synkronisere endringer når den første belastningen er fullført. Hvis replikatprosessen mottar feil, registrerer den fremdriften og avbrytes. I GoldenGate kalles avbrytelsen av prosessen på grunn av feil. Hvis en prosess er abended, har den avbrutt på grunn av feil og må løst. GoldenGate bruker disse komponentene for å bygge et komplett replikasjonsmiljø. Utdragsprosesser trekker data og skriver til sporfiler som behandles av samlerprosesser og konsumeres av replikatprosesser. Den virkelige magien bak GoldenGate skjer ved å utnytte denne konfigurasjonen på ulike måter: Flere utdragsprosesser kan trekke forskjellige sett med data parallelt og sende det til flere mål. Enkeltekstraheringsprosesser kan trekke data og kringkaste via datapumper Flere systemer kan trekke ut til et enkelt mål der flere replikatprosesser kan konsolidere data Bruk flere databasetyper i en hvilken som helst kombinasjon for kilden eller målene. Filtrer ogor kartdata underveis til målet for tilpassede datakrav På denne måten kan GoldenGate brukes til å erstatte selv den mest effektive replikasjons - eller ETL-behandlingsstrukturen. Med disse evnene i tankene kan vi snakke om noen av måtene GoldenGate kan brukes i det gjennomsnittlige Oracle-miljøet. Gjøre det beste ut av GoldenGate GoldenGate-installasjonen er lett nok til at den kan distribueres på ethvert system. Den fungerer på Unix, Linux og Windows og overfører data over TCPIP. Programvaren i seg selv er selvstendig og kan bokstavelig talt opprettes innen få minutter. Så med all denne brukervennligheten, hvordan kan vi sette den på jobb Forenklet utdrag, transformere og laste (ETL) Oracle har mange alternativer for ETL og ELT (Extract, Load, Transform). Mest kjent er Oracle Data Integrator (ODI), som nå inkluderer integrering med GoldenGate for forbedret endringssynkronisering. ODI benytter en svært effektiv ELT-prosess for å samle inn flere datasett, laster til et oppføringssted, og deretter transformere dataene for sanntidspostering. Selv uten ODI, er GoldenGate lett brukbar for aggregering av data for lagerinnlasting. Utdragsprosesser kan trekke data samtidig og i sanntid fra Oracle, SQL Server, AS400-miljøer, XML, flate filer og mange flere kilder. Alle disse dataene vil bli skrevet som flere sporfiler til målmiljøet som deretter vil bli skrevet til lageret (igjen, på hvilken som helst plattform) ved replikatprosesser. Ved hjelp av denne metoden kan GoldenGate til og med filtrere og rense dataene under prosessen for å oppnå størstedelen av ETL-arbeidet i ett enkelt trinn. Eller hvis du foretrekker det, kan dataene enkelt aggregeres og deretter rengjøres med andre metoder på målsystemet for ELT. Med bruk av datapumper til å sende enkelt datakilder til flere steder, er det veldig enkelt å garantere at dataene i hele bedriften din er konsistente og pålitelige. Utdragsprosessen skriver data til en lokal sporfil som hentes av en datapumpe. Datapumpen sender i sin tur denne informasjonen til flere destinasjoner (nær eller langt) som samles og skrives til målmiljøet via replikatprosessen. I denne moderne tid med disklagring eliminerer data redundans som dette eliminerer behovet for kostbare databasekoblinger, men gir i sanntid tilgang til eksterne data ved å benytte data duplisering i stedet for nettleser. Faktisk er real-time buzzword stort med GoldenGate, og Oracle bruker det så mye som mulig. Kjernetemaet bak GoldenGate er sanntidsadgang til sanntidsdata, det vil si at dataene du trenger, vil være tilgjengelige umiddelbart og vil alltid være oppdatert. Bytte databaseforbindelser med synkroniserte kopier vil forbedre ytelsen på mange systemer enormt så lenge dataene er garantert å være friske. Oppdatere servere En av de største irritasjonene for mange DBAer er forfriskende utviklingssystemer med oppdatert data. GoldenGate er dannet av gjenbrukbare komponenter, og det er veldig enkelt å pakke ut og kopiere innledende datalaster. Ved å lage disse prosessene i GoldenGate en gang, kan en DBA initiere enkle etterspurt oppdateringer av utviklingsmiljøer. Ved å bruke datapumper kan DBA bruke en enkelt utvinning og bruke den til å fylle flere utviklingsmiljøer, individuelle miljøer for ulike utviklingsgrupper, DBA sandkasser eller developmentQA-miljøer parallelt. Disse miljøene kan spres over flere operativsystemer, databasesystemer eller til og med versjoner. Testing på 11g (eller 12g snart) vil være en bris på grunn av muligheten til å sømløst replikere. Muligheten til å flytte mellom versjoner introduserer en annen logisk bruk av GoldenGate: oppgradering til nye utgivelser. GoldenGate kan replikere sømløst fra server til server eller lokalt og kan brukes til å duplisere en database til en ny versjon ved hjelp av eksisterende behandlingskonfigurasjoner. For eksempel, hvis GoldenGate brukes til å kopiere data mellom en 10g database og en annen 10g database, er en oppgradering like enkelt som å stoppe replikering til målsystemet midlertidig, oppgradere til 11g, og deretter starte replikering igjen. GoldenGate opererer utenfor dataordlisten og kan sømløst fungere mellom disse versjonene. Det samme gjelder for å flytte til en annen server eller til og med til et annet operativsystem. Rullande utvikling i produksjon Flere ekstrakter og replikater kan enkelt konfigureres til å trekke utviklingsdata og slå sammen det med produksjonstabeller. Alternativt kan utviklingsdata trekkes fra flere steder, eller utviklings - og produksjonsdata kan trekkes fra deres respektive databaser og slås sammen til et nytt miljø. Uansett hvilken metode du velger, kan konfigurasjonene for ekstraktene og replikaene brukes på nytt for å utføre disse operasjonene med jevne mellomrom. Migrere tredjeparts verktøydatabaser Noen tredjepartsverktøyer tillater bare visse databaseplasser. Hvis du har en tredjeparts applikasjon som bare er designet for å kjøre på MySQL eller SQL Server, kan dataene fra dette systemet sendes til en Oracle-database for rapportering eller historisk registrering. På noen tredjepartsverktøy kan det til og med være mulig å integrere data fra andre systemer inn i tredjepartsdatabasen. Bruke Business Data i SharePoint Mange bedrifter har begynt å bruke SharePoint eller andre portalverktøy for deres bedriftsinfrastruktur. Ved hjelp av GoldenGate kan informasjon fra finans-, kunde-, HR - eller andre databaser enkelt integreres i selskapets portal, uansett hvilken server som eier SharePoint-databasen. Feilsøkingssystemer og overvåkingsverktøy Bruke GoldenGate, det er mulig å overføre data fra problemer med bildekryptering til overvåkingsmiljøer. For eksempel, hvis firmaet ditt bruker et billettverktøy for å motta problemer med billetter på kundespørsmål og et overvåkingsmiljø for IT-personell, kan GoldenGate fungere som et meldingssystem ved å kopiere billettinformasjon til overvåkingsmiljøet. Alternativt kan strømmen reverseres, og overvåking av informasjon kan brukes til å gi ekstra informasjon om billetter. Master Data Management (MDM) Den sentrale komponenten i mange distribuerte systemer, blir MDM mer og mer populært i store bedriftsmiljøer. MDM-løsninger er sentrale databaser som inneholder viktige bedriftsdata i et forsøk på å alltid sikre nøyaktig informasjon på tvers av distribuerte miljøer. For eksempel, hvis et selskap bruker fem forskjellige databaser og applikasjoner som alltid krever informasjon om ansatte, kan et MDM-miljø være et sentralt samlingspunkt for medarbeidsdata som deretter kan brukes i de eksterne miljøene. I disse typer oppsett kan GoldenGate brukes både til å levere MDM-data til andre databaser og for å laste inn MDM-data. Datapumper fra MDM-sentralarkivet kan spre informasjon til alle abonnementdatabaser, og relevant informasjon fra databaser i bedriften kan sende informasjon til MDM for sentral lagring. Oracle GoldenGate 11g er klar til å gjøre store endringer i måten data flyttes mellom miljøer. Selv om replikering har eksistert i lang tid, er GoldenGate det første svært tilgjengelige sanntidsreplikasjonsverktøyet med fullstendig heterogen støtte på tvers av mange plattformer. Med uttrekkbar ekstraktplattform er det enkelt å distribuere og gjenbrukes på mange forskjellige systemer for mange behov. Få fullstendig Oracle SQL Tuning-informasjon Markørboken quotAdvanced Oracle SQL Tuning Den Definitive Referencequot er fylt med verdifull informasjon om Oracle SQL Tuning. Denne boken inneholder skript og verktøy for å overføre Oracle 11g-ytelse, og du kan kjøpe den til 30 av direkte fra utgiveren. Behandle Oracle 11g-ferdighetene dine for å lære DB2 9.7 for Linux, UNIX og Windows Innledning En tidligere utviklerWorks-artikkel snakket om hvordan du kan utnytte MS SQL Server 2000-ferdighetene dine for å lære DB2. Er bakgrunnen din i Oracle i stedet for SQL Server Hvis ja, les videre. I denne artikkelen vil vi vise deg hvordan du bruker din nåværende kunnskap om Oracle 11g for raskt å finne foten din med DB2 9.7 IBM DB2-e-kit for databaseprofessorer Lær hvor lett det er å bli opplært og sertifisert for DB2 for Linux, UNIX, og Windows med IBM DB2 e-kit for Database Professionals. Registrer deg nå. og utvide din ferdighetsportefølje, eller utvide DBMS-leverandørens støtte for å inkludere DB2. DB2 9.7 har blitt levert med nye muligheter for å håndtere kostnader og forenkle applikasjonsutvikling. Det har vært forbedringer på flere områder som komprimering, pureXML, håndterbarhet og ytelse. Denne artikkelen fokuserer på å sammenligne grunnleggende begreper for DB2 og Oracle, sammen med å introdusere de nye funksjonene som er tilgjengelige i DB2 9.7. Merk: For resten av denne artikkelen vil vi bruke termen Oracle til å referere til Oracle 11g og DB2 for å henvise til DB2 9.7 for Linux, UNIX og Windows. Oversikt over systemstrukturer For å starte, må vi forstå arkitekturen som brukes av Oracle og hvordan den sammenligner med DB2. Figur 1 viser systemstrukturen til Oracle. Sammenlign det med figur 2. som viser systemstrukturen til DB2. Henvis til disse tallene for forståelse mens du leser artikkelen. Figur 1. Oracle systemstruktur på Linux, UNIX og Windows Figur 2. DB2 på Linux, UNIX og Windows systemstruktur Konseptet med en forekomst er lik både i Oracle og DB2. I begge tilfeller er en forekomst en kombinasjon av bakgrunnsprosesser og delt minne. Den største forskjellen mellom de to er at i Oracle kan det bare være en database per forekomst, mens DB2-databaser kan dele en forekomst. Fordi det er en en-til-en korrespondanse mellom database og forekomst, i Oracle lager du en forekomst implisitt ved å opprette en database med CREATE DATABASE-kommandoen. Alternativt, for å opprette en Oracle-forekomst på maskinen, kan du bruke Database Configuration Assistant, eller du kan bruke ORADIM-verktøyet, tilgjengelig med Oracle 9i med det nye alternativet. Du må også angi visse opplysninger, inkludert et systemidentifikator (SID) eller et servicenavn, eksempelpassord, maksimalt antall brukere, oppstartsmodus og så videre. På samme måte, for å slette forekomsten, kan ORADIM-verktøyet brukes med DELETE-alternativet. Du må passere i SID eller service navn. Det er ingen standardinstans opprettet med en fersk installasjon av Oracle med mindre du oppretter en ny database under installasjonsprosessen. I DB2, etter installasjon av produktet på Windows-plattformen, blir forekomsten DB2 opprettet som standard. I Linux og UNIX heter standard instansnavn db2inst1. For å opprette en annen forekomst i samme maskin, utfører du bare kommandoen db2icrt ltinstance namegt. Figur 3 viser en forekomst kalt DB201 opprettet med kommandoen db2icrt fra GUI for DB2 Control Center. Figur 3. DB2 Control Center GUI som viser DB2-forekomster For å referere til en gitt DB2-forekomst fra et kommandolinjegrensesnitt, bruk miljøvariabelen DB2INSTANCE. Denne variabelen lar deg angi den nåværende aktive forekomsten som alle kommandoer vil gjelde. For eksempel, hvis DB2INSTANCE er satt til PROD, og ​​du utsteder kommandoen, oppretter database MYDB1. Du vil opprette en database knyttet til eksempel PROD. Hvis du vil lage denne databasen, for eksempel DB2 i stedet, må du først endre verdien av DB2INSTANCE-variabelen til DB2. Dette ligner ORACLESID (System Identifier) ​​som også brukes når brukere vil bytte mellom forekomster. En annen enkel måte å identifisere forekomsten du vil jobbe med, er å bruke DB2 Control Center GUI som vist på Figur 3. Hvis du vil se en oppføring for den nye forekomsten i dette verktøyet, må du kanskje legge til forekomsten til GUI ved høyre klikker på Instances og velger Add. For å slippe en forekomst i DB2, kan du kjøre kommandoen db2idrop ltinstance namegt. Sammendrag I Oracle kan databasekonfigurasjonsassistenten brukes til å opprette, modifisere, starte, stoppe og slette forekomsten, mens i DB2 kan kontrollsenter-GUI brukes til tilsvarende formål. Også en Oracle-forekomst kan bare ha et ett-til-ett-forhold med en database, mens dette ikke er tilfellet i DB2. Flere databaser kan eksistere og brukes samtidig i en DB2-forekomst. I Oracle kan en database enten opprettes manuelt ved hjelp av kommandoen CREATE DATABASE eller ved hjelp av Database Configuration Assistant. Å lage databasen manuelt krever at en rekke trinn følges, inkludert innstilling av OS-variabler, utarbeidelse av parameterfilen og opprettelse av en passordfil før CREATE DATABASE-kommandoen kan utføres. Metadatainformasjon lagres og administreres av Data Dictionary, som består av basistabeller og tilhørende visninger. Basistabellene opprettes automatisk under opprettelsen av databasen, og visningene blir konstruert ved å kjøre katalog. sql og catproc. sql-skript. Oracle-databasen er derfor sett på som en samling av tre filtyper: Datafil. Inneholder faktiske data, fysisk implementering av databasen. (Ligner på containere i DB2) Redo fil. Dette tilsvarer Transaksjonslogger i DB2. Kontrollfil. Inneholder informasjon for å opprettholde og verifisere databaseintegritet. I DB2 kan en forekomst inneholde flere databaser, som vist i figur 2. Hver database er en virkelig lukket og uavhengig enhet. Hver database har sin egen katalogtabellplass, midlertidig tabellplass og brukertabellplass som er opprettet som standard ved vellykket databaseopprettelse. DB2 inneholder en binær fil kjent som systemdatabasekatalogen som inneholder oppføringer av alle databasene du kan koble fra DB2-maskinen din. Denne katalogen holdes på instansnivå. Når en forekomst er opprettet, opprettes ingen databaser som standard. Du må eksplisitt lage en database ved hjelp av opprett database-kommandoen. Du kan også opprette en database ved hjelp av kontrollsenteret som vist i figurene 4 og 5. Figure 4. Creating a DB2 database using the Control Center GUI Figure 5. Creating a DB2 database using the Control Center GUI (continued) In Figure 5. you can also see what happens when you click Show Command . All DB2 Control Center GUI screens let you see the SQL statement or command that is actually executed in the background. These commands can be saved in scripts for execution at a later time, or can be copied and executed from the Command Line Processor (CLP) tool or Command Center GUI tool. These tools are equivalent to Oracles SQLPlus and iSQL Plus respectively. A DB2 database can be dropped by using the DROP DATABASE command or from the DB2 Control Center GUI. In Oracle there is no such command a database is deleted by deleting all the associated datafiles. Databases within an instance normally dont interact with each other. However, if your application needs to interact with more than one database, this requirement can be supported by enabling federation support. See the resources section for an article about federation. Containers, table spaces, bufferpools and pages In Oracle, data is physically stored in files called Data Files. This is similar to DB2s containers where data is physically stored. Every Oracle database contains a table space named SYSTEM, which Oracle creates automatically when the database is created. Other table spaces for user, temporary and index data need to be created after the database has been created, and a user needs to be assigned to these table spaces before they can be used. In DB2, a table space is the logical object used as a layer between logical tables and physical containers. When you create a table space, you can associate it with a specific buffer pool (database cache) as well as to specific containers. This gives you flexibility in managing performance. For example, if you have a hot table, you can define it in its own table space associated with its own buffer pool. This helps ensure the data for this table is continuously cached in memory. In DB2 three default table spaces are created automatically upon database creation when using default values for the CREATE DATABASE command. Table 1 describes the default DB2 table spaces: Table 1. DB2 table spaces created by default when a database is created with default values User table space. By default, USERSPACE1 is normally created after database creation As indicated earlier, Oracles data buffer concept is equivalent to DB2s bufferpool however, DB2 allows for multiple bufferpools to exist. There is no predefined number of bufferpools that you can create, and they can have any name. The concept of an Oracle block is most similar to DB2s page. A DB2 page can have a size of 4k, 8k, 16k or 32k. A table row must fit in only one page it cannot span to other pages as in Oracle. Object names An Oracle object name takes the following form: In DB2, objects also have a two-part structure: As in Oracle, the DB2 schema name is used to group objects logically. An important difference, however, is that in DB2, a schema name does not have to match to a user id. Any user with a privilege called IMPLICITSCHEMA can create an object using a non-existing schema. For example, suppose that Peter has IMPLICITSCHEMA privilege and executes this command: CREATE TABLE WORLD. TABLEA (lastname char(10)) In this case, the table WORLD. TABLEA is created, where WORLD is the newly created schema. If Peter had not explicitly indicated the schema, then the table PETER. TABLEA would have been created, because the connection ID is used by default. In DB2 you always connect to a database before issuing database specific commands therefore, under this architecture, object names need not include the database name. Tables, views, and indexes Tables, views, and indexes are basically the same in both Oracle and DB2. DB2 provides a utility called Design Advisor which you can use to recommend indexes for a particular query or workload. You can invoke the Design Advisor from the DB2 Control Center or from the DB2 CLP using the db2advis command. In DB2, indexes are directly tied to the table definition. For example, when using DMS table spaces you can specify in which table space the indexes can reside as follows: CREATE TABLE mytable (col1 integer, col2 char(10)) in tbls1 index in tbls2 The above example shows that the data for the table will be stored in table space tbls1, while the index pages will be stored in table space tbls2. This is in contrast to Oracle syntax where the CREATE INDEX statement provides an option to specify in which table space the index will reside. Also, once an index has been created in DB2, you cannot alter any clause of the index definition. You would need to drop the index and create it again in order to implement changes. As in Oracle, DB2 tables, views and indexes in different databases can have the same names. Tables and views within the same database must have distinct names, but creating an index with the same name as either an existing table or view is allowed. Stored procedures, triggers and user-defined functions (UDFs) DB2 stored procedures can be written in any language supported by the DB2 precompilers, including Java, C, C, REXX, Fortran, and COBOL. However, the recommended language to use is the SQL Procedural Language (SQL PL), which is fairly similar to Oracles PLSQL. SQL PL stored procedures are easy to create and have good performance. DB2 stored procedure development also supports SQLJ and Java using JDBC drivers type 2 and 4. Type 3 is discontinued. Development of triggers and functions can use inline SQLPL, a subset of SQL PL. The Data Studio tool can be used to easily create, build, debug and deploy DB2 stored procedures and user-defined functions. Configuration files Traditionally Oracle stores all session and system-related parameters in a text file, normally referred to as initSID. ora. However due to the non-persistent nature of this text file, starting from Oracle 9i, Oracle introduced Server Parameter File (SPFILE), which is a binary parameter file stored on the server. This persists across instance shutdown and startup. The initSID. ora file is still used, however, when an SPFILE is not available. Prior to the introduction of SPFILE, any ALTER SYSTEM and ALTER SESSION commands that affected parameters would only persist during that instance or that session. The DBA would have had to manually modify the initSID. ora text file whenever a rebound of a database instance was intended. Network access configurations are typically stored in listener. ora for listener and tnsnames. ora for client access. With DB2, configuration parameters are stored at the instance level, known as the database manager configuration file, and at the database level, known as the database configuration file. Most of these parameters can be changed dynamically, that is, there is no need to stop and restart the instance or force all connections from a database before the change to the parameter value takes effect. The files where DB2 stores its configuration information cannot be edited directly. If you would like to manually change a specific database manager parameter from the CLP, use the command UPDATE DBM CFG USING ltparameter namegt ltnew valuegt . If you would like to manually change a specific database parameter from the CLP, use the command UPDATE DB CFG FOR ltdatabase namegt USING ltparameter namegt ltnew valuegt. These commands would be the equivalent to Oracles ALTER SYSTEM and ALTER SESSION. Alternatively, using the Control Center, you can review and change values for these parameters if you right click on a given instance and choose Configure Parameters . you will see the window shown in Figure 6 . Figure 6. DB2 Database Manager configuration parameters (instance level) At the database level, right clicking on a given database, and choosing Configure Parameters displays the window shown in Figure 7 . Figure 7. Database configuration parameters (database level) DB2 provides many parameters you can use to configure your system. However, if you would like an easy way to configure the system automatically, use the autoconfigure command (or the Configuration Advisor GUI) which sets the database manager and database configuration parameters to optimal values based on some information you provide. Figure 8 shows the Configuration Advisor. Figure 8. - DB2 Configuration Advisor In addition to configuration files, DB2 also uses DB2 Registry variables normally for platform-specific configurations. Note, the DB2 Registry variables have no relationship whatsoever to the Windows registry . Use the command db2set to review and change these variables. Connectivity (network access) information is stored in the system database directory, local database directory and node directory. These are binary files and can only be modified with the CATALOG and UNCATALOG commands. Memory architecture, background processes and threads Next well look at the memory architecture, background processes and threads, and will compare and contrast the way they are used in Oracle and DB2. Figure 9: Oracle memory architecture and background processes The System Global Area (SGA) in Oracle is a group of shared memory areas that stores information for the instance. Examples include statement cache, redo log buffers, and data buffer cache. The Program Global Area (PGA) and the User Global Area (UGA) shared memory areas contain data and control information for server processes and user sessions. Oracle supports multiple instances within the same machine but background processes are not shared. For example, three instances in one machine will require three set of background processes. Therefore it is generally recommended to have one database, one instance and multiple schemas within the same machine. Figure 10: DB2 Memory architecture and background processes and threads Both DB2 and Oracle use shared memory areas, but DB2s memory architecture is implemented in a slightly different way than Oracles. Since a DB2 instance can contain more than one database, two levels of configuration exist. As we mentioned in the previous section, instance level configuration can be done in the DBM CFG file while the database level configuration is done in the DB CFG file. Configuration parameters at both levels can be adjusted to tune memory usage. The section below provides a bit more detail on DB2s memory structures and different background processes. Unlike Oracle where memory is allocated to both the instance and the database upon startup, DB2 allocates memory at different levels. This is primarily due to the fact that a DB2 instance can contain multiple databases. There are three main memory structures in DB2: Instance shared memory . This refers to the database manager global shared memory, which is allocated when the instance is started using the db2start command, and remains allocated until a db2stop command is issued to stop the instance. Database shared memory . This refers to the database global memory, which is allocated when the database is activated or connected to for the first time. Memory allocated includes buffer pools, locklist, database heap, utility heap, package cache and catalog cache. Application shared memory . This refers to the memory allocated when an application connects to a database and is used by agents that do the work requested by the connected clients. Each application connected to the database has memory allocated to it therefore accurate configuration of the parameters affecting the application shared memory becomes crucial. The DB2 database server must perform many different tasks, such as processing database application requests or ensuring that log records are written out to disk. Each task is typically performed by a separate engine dispatchable unit (EDU). In DB2 for Windows, Linux and UNIX. server activities are conducted in the form of threads. DB2 threads and processes operate in the following levels. Note that this is a non-exhaustive list but we do highlight the important threads and processes: Instance Level: These are processes and threads that are initialized when an instance is started: DB2 Daemon Spawner (db2gds): Global daemon processor started for each instance (only in UNIX) DB2 System Controller (db2sysc): Main DB2 process DB2 Watchdog (db2wdog): Parent process for all other processes DB2 Format Log (db2fmtlg): Similar to the ARCn process in Oracle, pre-allocates log files in the log path Autonomic computing daemon (db2acd): Hosts the health monitor, automatic maintenance utilities, and the administrative task scheduler. This process was formerly known as db2hmon. Database Level: These are processes that are initialized when a connection is made to a database. DB2 Log Reader (db2loggr): Similar to the subset of Oracles PMON process. This process reads log files during rollback, restart recovery and roll forward. DB2 Log Writer (db2loggw): Flushes log from log buffer to the transaction log files on disk. Equivalent to LGWR process in Oracle. DB2 Page Cleaner (db2pclnr): Equivalent to DBWR process in Oracle, this process cleans the buffer pool before pages from the disk are moved into the BP. DB2 Prefetcher (db2pfchr): Retrieves pages from disk and places into the buffer pool before it is needed. DB2 Deadlock Detector (db2dlock): Deadlock detector process. DB2 Self-Tuning Memory Manager (db2stmm): for the autonomic self-tuning memory management feature. Application Level: Each application connecting to the database would have its own share of application-level background processes associated with it. These are as follows: DB2 Communication Manager (db2ipccm): Inter-process communication process for each locally connected client. DB2 TCP Manager (db2tcpcm): TCP communication manager process for remote clients connecting using TCPIP. DB2 Coordinating Agent (db2agent): Thread that handles all requests on behalf of an application. DB2 Pooled Gateway Agent (db2agntgp and db2agntgp): An agent pooled on a remote database and local database respectively. For a comprehensive explanation of DB2s processes please refer to the article Everything you wanted to know about DB2 processes . Locking mechanisms Locking in Oracle can be either manual or automatic. The Oracle Lock Manager can implicitly lock table data at the row level, or default locks can be overridden at transaction or session level using the following SQL statements: 1. SET TRANSACTION ISOLATION LEVEL 2. LOCK TABLE 3. SELECT FOR UPDATE Oracle supports a mechanism called Multi-Version Read Consistency which is implemented by undo data in the undo segments. DB2 implements ANSI standard Isolation levels such as Uncommitted Read, Cursor stability, Read stability and Repeatable Read. A user will only see committed data unless the Uncommitted Read isolation level is used. Row locks are acquired implicitly according to the isolation level. Database objects that are lockable are table spaces, tables and rows, however, only tables and table spaces can be explicitly locked. The LOCK TABLE command can be used to lock a table instead of using the default row locking. Unlike Oracle, in DB2, locks are stored in the memory and not in data pages. The LOCKLIST database configuration parameter can be used to configure the memory available for locks, while the MAXLOCKS configuration parameter defines the maximum amount of memory for a particular applications locks. In DB2 9.7 lock event reporting has been enhanced. The new lock event monitor collects information about lock timeouts, deadlocks, and lock waits that are more than a specified duration. This data can be accessed from either a XML document, from database tables or using a java based tool (db2evmonfmt) to read from an xml or text document. A new database configuration parameter curcommit has been introduced which basically allows only committed data to be returned, as was the case previously, but now readers do not wait for writers to release row locks. Instead, readers return data that is based on the currently committed version that is, data prior to the start of the write operation. Both Oracle and DB2 are secure databases with basic and advanced security features. In Oracle, there are 4 different user authentication methods, as follows: Database . The database performs both identification and authentication of users. External . The operating system or network service performs authentication Global authentication and authorization . The user is authenticated globally by SSL Proxy authentication and authorization . The middle-tier server performs authentication. The authentication method is specified when creating the user using the CREATE USER command. There are several Data Dictionary views that contain information about these users. In DB2, users do not exist within the database, but are rather managed by the operating system. No database login information is kept in any database table. Any operating system user can potentially access DB2 however, unless they have been granted a given DB2 authority or privilege, there is not much they can do. Granting and revoking authorities and privileges can easily be handled through the Control Center GUI. You first may have to add a user or group to the Control Center from the available operating system users or groups. Also in DB2 the term roles is not used instead, DB2 uses the term authorities, which are similar to Oracles database roles, whereby privileges are granted to certain groups or users. The authorities supported with DB2 are: SYSADM, SYSCTRL, SYSMAINT, SYSMON, SECADM, DBADM and LOAD. The SYSADM, SYSCTRL and SYSMAINT authorities cannot be granted using the GRANT SQL statement. These special authorities can only be set by modifying the specific database manager configuration parameters. DB2 also uses the term privilege which is similar to Oracles system and schema object privileges. There are database privileges (connect, createtab, and so on) and database object privileges (schema, table, view, and so on). Figure 11 shows DB2 security information obtained from the Control Center GUI. Most of the tabs shown on the Change User window correspond to the privileges supported by DB2. Figure 11. DB2 security Authentication in DB2 does not only involve encrypting user names and passwords but also allows for encryption of data as it travels across the network between the clients and the server. The location of the authentication process is determined by the value of the database manager configuration parameter AUTHENTICATION. The following are the valid options for enabling authentication for DB2: SERVERENCRYPT - This value specifies that the authentication occurs on the server. The user id and password specified during connection are encrypted and sent to the server where they are compared with the user and password on the server side. If the match is successful, the user is allowed to access the database. KRBSERVERENCRYPT - This specifies that the server accepts KERBEROS authentication or encrypted SERVER authentication schemes. DATAENCRYPT - This setting specifies that the server allows for SERVER authentication, and also that the data traveling over the network between the client and server is encrypted. DATAENCRYPTCMP - This specifies that the server accepts encrypted SERVER authentication schemes and the encryption of user data. This authentication type allows for compatibility with down-level products not supporting the DATAENCRYPT authentication type. GSSSERVERENCRYPT - This specifies that the server accepts GSS API-based plug-in authentication or encrypted server authentication schemes. To update the AUTHENTICATION instance parameter, for example to a value of DATAENCRYPT, use the commands shown below: Listing 1. Updating AUTHENTICATION instance parameter DB2 further extends security by offering a Label Based Access Control (LBAC) mechanism. The LBAC feature provides for greater granularity for controlling read and write access to individual rows and table columns. A security administrator role (SECADM) has been provided in DB2 which is needed to manipulate LBAC objects. Users attempting to access an object must have its security label granted to them. When theres a match, access is permitted without a match, access is denied. There are other aspects of database security beyond privileges and authorities. Briefly, here are some of the differences and similarities between Oracle and DB2: User authentication and authorization Oracle uses an encrypted password stored in the dictionary once a user is created. DB2 supports passwords for user authentication and uses the underlying operating user for authentication. Both Oracle and DB2 support LDAP (Oracle Internet Directory and IBM Directory Server). Both Oracle and DB2 support single sign on (SSO). Oracle supports data encryption where sensitive data such as credit card numbers and some highly sensitive business data can be encrypted. You have the following options for encrypting DB2 data in storage: You can use the encryption and decryption built-in functions ENCRYPT, DECRYPTBIN, DECRYPTCHAR, and GETHINT to encrypt your data within database tables. You can use IBM Database Encryption Expert to encrypt the underlying operating system data and backup files. If you are running a DB2 Enterprise Server Edition system on the AI operating system, and you are interested in file-level encryption only, you can use encrypted file system (EFS) to encrypt your operating system data and backup files. Oracle provides network encryption with its Oracle Advanced Security. Oracle uses DES, 3DES and RC4 industry standard encryptions. To encrypt data in-transit between clients and DB2 databases, you can use the DATAENCRYPT authentication type, or, the DB2 database system support of Secure Sockets Layer (SSL). Oracle allows you to audit trail users and objects. Log miner can also be used for investigating and analyzing suspicious queries. DB2 provides a similar auditing facility. The db2audit utility can be used for this purpose. XML support This section compares Oracles support for XML to DB2s. Shipped with Oracle 9i Release 2, Oracle XML DB feature provided a way to manage XML storage, retrieval and schema by defining XMLTYPE tables and columns which are stored as CLOB or shredded (decomposed) to small pieces into relational tables. Oracle 10g came with some improvements to manage XML documents for example, changes in schema can be dynamically reflected by mapping existing data without the need to re-import. In Oracle 11G, a third kind of XML support called binary XML was introduced. So Oracle now has the following ways of storing XML data: Unstructured storage using CLOBs (also know as schema-less storage) Structured storage which maps XML to object relational Binary XML storage DB2s pureXML technology, stores XML documents natively, that is, internally in tree format. It also allows for the use of SQL with XML extensions, Xquery and Xpath to access relational and XML data. Storing XML documents natively is a better approach, and IBMs research indicates that there is a better performance for search and retrieval of XML documents, and reduction in the lines of codes for certain programs. Support for the DB2 XML data type is available in the DB2 Control Center, command line processor, IBM Data Studio, and IBM Database Add-Ins for Microsoft Visual Studio. In order to use the pureXML feature in your database, create the database as UNICODE (for example using codeset UTF-8). Failure to create a UNICODE database prior to creating a table will result in an error as shown below: DB2 stores relational data as in previous versions. However, XML data is stored in hierarchical format (as a tree using the Xquery Data Model, XDM). There is tight integration between both XML and relational services. To store XML documents, a user needs to create a table, and specify a column to use a new data type, XML, as shown in the example below. Listing 2. Create a DB2 table with XML datatype As XML documents are stored in parsed hierarchical format natively in the XQuery Data Model (XDM), there is no need for translation or mapping the format used to store XML documents is the format used to process it. This allows for greater performance. Utilities such as backup, restore and import apply to tables with XML columns the same as in any other tables. XML data can be inserted into the XML column either by using the INSERT statement or by using the DB2 IMPORT utility. Prior to importing XML documents received from third parties, it is a good idea to validate these documents against a pre-defined XML schema. To register against an XML schema, DBAs are required to issue the REGISTER XML SCHEMA command, ended with COMPLETE XML SCHEMA to complete the registration process. DB2 also supports indexes to be created on a subset of an XML document, or on the entire document. An XPATH needs to be specified when creating an index which would point to that particular elementattribute to be indexed. With DB2 you now have four ways to access relational and XML data: Plain SQL (no XQuery involved) SQLXML, that is, XQuery embedded in SQL XQuery as a stand-alone language (no SQL involved) Xquery with embedded SQL In DB2 9.7 additional XML features were included such as support for the XML type in User Defined Funcions. Important enhancements in DB2 9.7 are that the LOAD utility can now be used to load XML data. Also, On partitioned tables, indexes over XML data that you create with DB2 V9.7 or earlier are nonpartitioned. Starting in DB2 Version 9.7 Fix Pack 1, you can create an index over XML data on a partitioned table as either partitioned or nonpartitioned. There are more developerWorks articles on IBM pureXML capabilities such as Query DB2 XML data with XQuery. Query DB2 XML Data with SQL amongst others for more in-depth discussions. Partitioning Oracle Partitioning offers several partitioning strategies that control how the database places data into partitions. The basic strategies are range, list, and hash partitioning. DB2s table partitioning (a. k.a Range partitioning), is similar to Oracles partitioning. It basically allows a single logical table to be broken up into multiple physical storage objects across one or more table spaces. Each of the objects would correspond to a partition and would allow each table space to contain a range of data which can be accessed very easily. In DB2 there are several ways to partition your data, and you can apply these methods simultaneously on the same data. To avoid confusion, here is a short explanation about the different ways to provide this partitioning: DATABASE PARTITIONING - distributing data by key hash across logical nodes of the database (DPF). RANGETABLE PARTITIONING (Available with DB2 9) - splitting data by key range over multiple physical objects within a logical database partition. MULTI DIMENSIONAL CLUSTERING (MDC) - organizing data in table (or range of a table) by multiple key values. In Version 9.7, you can have indexes that refer to rows of data across all partitions in a data partitioned table (known as nonpartitioned indexes), or you can have the index itself partitioned such that each data partition has an associated index partition. You can have both nonpartitioned and partitioned indexes for partitioned tables. The following example creates a table customer where rows with lshipdate gt 01012006 and lshipdate lt 03312006 are stored in table space ts1, rows with lshipdate gt 04012006 and lshipdate lt 06302006 are in table space ts2, etc. More exhaustive explanation can be obtained from developerWorks article, Table partitioning in DB2 9 . Listing 3. Range partitoning a table A comparison of Oracle and DB2 partitioning terminology can be found in Table 1 of the article Migrate from Oracle or Sybase to DB2 in weeks. Compression There are three compression features provided by Oracle index, table and row level compression. Improper planning of these features may have adverse effect in performance. Oracle introduced index compression since version 8i. Indexes that can be compressed are bitmap, btree and index organized tables. To use index compression is straightforward for example, to create an index with the compression feature, use: Listing 4. Create index with compression For indexes that were not created initially with compression, you can turn them to compression by altering them. Listing 5 shows an example of how you can alter an index to include compression. Listing 5. Alter index with compression Currently, Oracle doesnt provide any automated advisor to pinpoint which indexes should be compressed. Most of the benefits gained by index compression requires proper planning by seasoned DBAs who with intimate knowledge of Oracle CBO. Table compression on the other hand, was introduced in Oracle 9i release 2. It can be used to compress entire tables, table partitions, and materialized views. The compression can be applied to all partitions or some partitions. Though table compression works for a non-partitioned table, its usage for non-partitioned tables in OLTP workloads may not be desirable as insert and update performance may suffer. In Oracle table compression, duplicate values are removed in a database block, and information is stored to recreate the uncompressed data within the block. The following example shows how to create partition table with compression. Listing 6. Create table with compression To turn a table into a compressed table, use alter table lttable namegt move compress . A compressed table, however, does not allow adding or dropping of columns. In DB2 9.7, row compression, also referred to as deep compression, compresses data rows by replacing patterns of values that repeat across rows with shorter symbol strings. Of the various data compression techniques available in DB2 9.7, row compression offers the biggest possibilities for storage savings. Row compression requires the creation of a dictionary which stores a mapping between repetitive patterns or entries and numeric keys. The compression algorithm is intelligent enough not to compress rows that will not realize in any significant disk-space saving. DB2s row compression, unlike Oracles key compression, does not require keys to be specified. Compression is enabled at individual table level via the CREATE TABLE or ALTER TABLE commands. For example: Listing 7. CreateAlter table with COMPRESSION YES To achieve the same effect using the DB2 Control Center, during the column definition (second step in the table creation wizard), ensure that you choose the checkbox, Store table data in a compressed format located at the bottom of the panel (as the following diagram shows). Figure 12. DB2 Control Center - Creating table with compression The table dictionary is built only when a REORG is performed, after which the data in the table can be compressed. The dictionary gets updated for every subsequent REORG operation. The compressed data is kept both on disk and memory and DB2 also compresses user data stored in log files, thereby reducing log file size. Note that each partition of a partitioned table can have a different compression dictionaries and each partition of a table in DPF can have a different compression dictionaries. Besides, data row compression, other compression mechanisms offered by DB2 9.7 include: NULL and Default Value Compression (V8 GA): Compression for null, zero length data in variable length columns and system default value. Multidimensional Clustering (V8 GA): Implements a form of index compression by using block indexes, one index entry for thousands of records. Database Backup Compression (V8 FP4): Compression to result in smaller backup images. XML Parsing Autonomic Features There are a few tuning improvements provided in Oracle 11g. Oracle automated the following tuning areas: Redo Logfile Sizing Advisor - This feature recommends the optimal size of redo log files in order to avoid excessive disk IOs due to frequent checkpointing. Automatic Checkpoint Tuning - The Oracle Database can now self-tune checkpointing to achieve good recovery times with low impact on normal throughput. You no longer have to set any checkpoint-related parameters. Automatic Shared Memory Tuning - Automatic Shared Memory Tuning automates the configuration of System Global Area (SGA) memory-related parameters (buffer cache, shared pool) through self-tuning algorithms. It simplifies database configuration, ensures most efficient utilization of available memory and improves performance. Transaction Rollback and Recovery Monitoring - This feature enables you estimate how long it will take to roll back a transaction. You can also monitor the progress of transactions being recovered and estimate the average speed of transaction recovery. SQL Tuning - The SQL Tuning Advisor automatically tunes high cost SQL statements. Automatic Storage manager - The automatic storage manager (ASM) simplifies the managment or Oracle related files. Oracle also provides some advisors such as segment and undo advisors. The segment advisor is based on the level of space fragmentation within an object, and as result, gives advice on whether an object is a good candidate for the new online shrink operation. As well, this advisor give reports on the historical growth trend of segments, and proved to be especially informative for capacity planning. Undo Advisor, on the other hand, helps administrators to make the right judgement in sizing the undo table space in both flash back and non-flashback features. It advises administrators in setting UNDORETENTION appropriately to avoid the age-old snapshot too old problem. DB2 9.7 has several autonomic features to assist in managing its environment that are self-configuring, self-healing, self-optimizing, and self-protecting. By sensing and responding to situations that occur, autonomic computing shifts the burden of managing a computing environment from database administrators to technology. Automatic memory tuning DB2 9.7 features a self-tuning memory feature called the Self Tuning Memory Manager that simplifies the task of memory configuration by automatically setting values for several memory configuration parameters. When enabled, the automatic tuner acting as dispatcher will figure out the memory resources available and distribute them to several memory consumers for the database dynamically. Self-tuning memory only applies to single partition databases. Automatic configuration With the AUTOCONFIGURE command you can calculate and displays initial values for the buffer pool size, database configuration and database manager configuration parameters, with the option of applying these recommended values. Automatic storage management Automatic storage automatically grows the size of your database across disk and file systems and since it automatically grows the size of the database, it removes the need to managing storage containers by DBAs. When you create databases in DB2 9.7 the automatic storage management feature is enabled by default. Automatic Maintenance DB2 9.7 has automatic maintenance capabilities that are used for automatically performing maintenance functions such as: Automatic database backups which provide the capability of a full database backup performed as needed. Automatic statistics collection. DB2 determines which statistics are required and need to be updated and then automatically executes the RUNSTATS utility in the background. Automatic table and index reorganisation. DB2 determines if a table or index reorganization by periodically checking tables and indexes that have had their statistics updated, and schedules such operations whenever they are necessary. We shall look at tools from different areas such as database creation and maintenance, network, administration GUI, performance tuning, data movement and backup-recovery tools. Figure 13 shows the DB2 9.7 GUI tools. Figure 13. DB2 9.7 GUI Tools Lets take a look at how similar tasks are performed in Oracle and DB2 9.7. Database Creation and Maintenance Oracle provides the Database Configuration Assistant (dbca) as the GUI tool to create databases. For database maintenance, Oracle provides the Oracle Enterprise Manager. DB2 databases can be created and maintained from the DB2 Control Center. Oracle provides the Network Configuration Assistant (netca) for network configuration. Alternatively, you can use the Oracle Network Manager to configure service naming, listener, profile and Oracle name servers. DB2 uses the CATALOG command to catalog nodes and databases. Cataloging can also be done using either the DB2 command line or DB2 Configuration Assistant GUI. The Oracle Enterprise Manager provides a wide range of administrative capabilities for the day-to-day tasks of administrators. DB2 Control Center provides similar functions as Oracle Enterprise Manager. Apart from the DB2 Control Center, you can also use the DB2 command line processor to issue DDL and DML statements. This utility is similar to the Oracle SQLPLUS utility. Figure 14 shows the DB2 command line processor. Figure 14. DB2 Command Line Processor Commands can also be issued from the Command Center, shown in Figure 15 . Figure 15. Command Center GUI (GUI version of DB2 Command Line Processor) Oracle Enterprise Manager comes with Change Management pack, Tuning Pack, and Diagnostic Pack. DB2 provides the Activity Monitor, Event Analyzer, Health Center, Indoubt Transaction Manager and Memory Visualizer as GUI tools for performance tuning tasks. Oracle provides SQL Loader (sqlldr) for loading data in delimited text format. Import (imp) and export (exp) can be used to perform logical import and export. DB2 provides similar import, export and load utilities. For cross platform data movement, DB2 provides the db2move utility. Backup and Recovery Oracle provides Recovery Manager as an option for hot backup. Backing up databases in DB2 can be accomplished using the backup command or the DB2 Control Center. Oracle 11g Enteprise Manager comes with new performance overview charts. The enhanced Oracle Enterprise Manager HTML interface provides a central point of access to all database performance-related statistics and facilitates complete monitoring and diagnostics. Apart from interfaces that are shipped with DB2 9.7 there is a no-charge application development tool, based on the Eclipse framework called tbe IBM Data Studio (Data Stuidio). Data Stuidio is a one-stop center for creating, editing, debugging, deploying, and testing DB2 stored procedures and user-defined functions. You can also use the Data Stuidio to develop SQLJ applications, and create, edit, and run SQL statements and XML queries. You can download IBM Data Studio from the Developerworks web site. For more details about IBM Data Studio review this tutorial tutorial in developerWorks. For examples and features, refer to the IBM Data Studio Features and Benefits web page. article in developerWorks. In this article weve introduced you to DB2 9.7 for Linux, UNIX and Windows by using your current knowledge of Oracle 11g as leverage. We briefly described the DB2 architecture, background processes, memory model, security, tools, and so on. There are many similarities between Oracle and DB2 9, and we have pointed out some of the differences so you can use your current knowledge to become successful with DB2 9.7. Table 3 summarizes the differences and similarities between Oracle and DB2 that weve discussed. Table 3. Summary of Oracle vs. DB2 concepts The article Migrate from Oracle or Sybase to DB2 in weeks (Data Management Magazine, Oct 2010) contains some helpful comparisons of DB2 and Oracle terminology and technology. The article DB2 9.7: Run Oracle applications on DB2 9.7 for Linux, UNIX, and Windows (developerWorks, May 2010) describes the out-of-the-box support for Oracles SQL and PLSQL dialects in DB2 9.7. IBM Data Movement Tool (developerWorks, Nov 2010): Move data from source databases to DB2 the easy way. An inside look at IBM DB2 Advanced Enterprise Servier Edition (developerWorks, March 2011): Learn about a software bundle that packages DB2 with optimization, development, and management tools. The Redbooks174 publication Oracle to DB2 Conversion Guide: Compatibility Made Easy is an Oracle to DB2 migration guide. It describes the new DB2 Oracle Database compatibility features, new technology, best practices for moving to DB2, and how to handle some common scenarios. The article Everything you wanted to know about DB2 processes (developerWorks, Apr 2003) describes the processes that DB2 uses on Linux, UNIX, and Windows, and details their functions. The IBM Redbooks publication Oracle to DB2 Conversion Guide for Linux, UNIX, and Windows is a step-by-step guide for migrating from Oracle to DB2. Visit the developerWorks resource page for DB2 for Linux, UNIX, and Windows to read articles and tutorials and connect to other resources to expand your DB2 skills. Learn about DB2 Express-C. the no-charge version of DB2 Express Edition for the community. Get products and technologies Download a free trial version of DB2 for Linux, UNIX, and Windows . Now you can use DB2 for free. Download DB2 Express-C. a no-charge version of DB2 Express Edition for the community that offers the same core data features as DB2 Express Edtion and provides a solid base to build and deploy applications. Download IBM product evaluation versions and get your hands on application development tools and middleware products from DB2, Lotus174, Rational174, Tivoli174, and WebSphere174. developerWorks: Sign in Required fields are indicated with an asterisk ( ). The first time you sign into developerWorks, a profile is created for you. Information in your profile (your name, countryregion, and company name) is displayed to the public and will accompany any content you post, unless you opt to hide your company name . You may update your IBM account at any time. All information submitted is secure. Choose your display name The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks. Please choose a display name between 3-31 characters . Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons. Required fields are indicated with an asterisk ( ). All information submitted is secure. Dig deeper into Information management on developerWorks Exclusive tools to build your next great app. Learn more. Ask a technical question Tutorials amp training to grow your development skills ArticleTitleLeverage your Oracle 11g skills to learn DB2 9.7 for Linux, UNIX, and Windows

No comments:

Post a Comment