%3CLINGO-SUB%20id%3D%22lingo-sub-2117312%22%20slang%3D%22en-US%22%3EMigrating%20database%20storage%20objects%20from%20Oracle%20to%20Postgres%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2117312%22%20slang%3D%22en-US%22%3E%3CP%3EWelcome%20to%20part%202%20of%20the%20four-part%20blog%20series%20on%20navigating%20Oracle%20to%20Postgres%20migrations.%20I%20am%20super%20stoked%20to%20let%20you%20know%20the%20first%20post%20in%20the%20series%E2%80%94%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fazure-database-for-postgresql%2Fnew-oracle-to-postgres-migration-guide-for-azure%2Fba-p%2F2055303%22%20target%3D%22_blank%22%3Eannouncing%20the%20new%20Oracle%20to%20Postgres%3C%2FA%3E%20migration%20guide%20for%20Azure%E2%80%94had%201000s%20of%20views%20and%20was%20featured%20in%20the%20%3CA%20href%3D%22https%3A%2F%2Fpostgresweekly.com%2Fissues%2F389%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3E389%3CSUP%3Eth%3C%2FSUP%3E%20edition%3C%2FA%3E%20of%20the%20Postgres%20Weekly%20newsletter.%20I%20feel%20happy%20that%20many%20of%20you%20personally%20messaged%20me%20to%20let%20me%20know%20that%20the%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fmicrosoft%2FOrcasNinjaTeam%2Fblob%2Fmaster%2FOracle%2520to%2520PostgreSQL%2520Migration%2520Guide%2FOracle%2520to%2520Azure%2520Database%2520for%2520PostgreSQL%2520Migration%2520Guide.pdf%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Emigration%20guide%3C%2FA%3E%20is%20helping%20your%20migration%20projects.%20Thank%20you%20for%20all%20the%20feedback.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EOracle%20to%20Postgres%20migrations%20are%20hard%2C%20multi-step%20projects%E2%80%94especially%20for%20complex%20applications.%26nbsp%3B%20From%20my%20experience%20working%20with%20those%20of%20you%20who%20have%20already%20done%20an%20Oracle%20to%20Postgres%20migration%E2%80%94specifically%20migrations%20to%20our%20%3CA%20href%3D%22https%3A%2F%2Fazure.microsoft.com%2Fservices%2Fpostgresql%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EAzure%20Database%20for%20PostgreSQL%20managed%20service%E2%80%94%3C%2FA%3Emany%20of%20you%20spend%20more%20than%2060%25%20of%20the%20entire%20migration%20project%20in%20the%20conversion%20(step%204)%20and%20migration%20(step%206)%20phases.%20In%20the%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fazure-database-for-postgresql%2Fnew-oracle-to-postgres-migration-guide-for-azure%2Fba-p%2F2055303%22%20target%3D%22_blank%22%3Efirst%20post%20in%20this%20Oracle%20to%20Postgres%20migration%3C%2FA%3E%20series%2C%20I%20dove%20deep%20into%20the%20different%20steps%20of%20an%20Oracle%20to%20Postgres%20migration.%20In%20the%20same%20spirit%2C%20let%E2%80%99s%20dive%20into%20some%20practical%20examples%20of%20how%20our%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fmicrosoft%2FOrcasNinjaTeam%2Fblob%2Fmaster%2FOracle%2520to%2520PostgreSQL%2520Migration%2520Guide%2FOracle%2520to%2520Azure%2520Database%2520for%2520PostgreSQL%2520Migration%2520Guide.pdf%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EOracle%20to%20Postgres%20migration%20guide%3C%2FA%3E%20can%20help%20you%20migrate%20your%20database%20storage%20objects.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Trio-of-plaid-Postgres-elephants-on-orange-background-for-migration-guide-post-1920x1080.jpg%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F253172iA91B98F390F0F675%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Trio-of-plaid-Postgres-elephants-on-orange-background-for-migration-guide-post-1920x1080.jpg%22%20alt%3D%22Trio-of-plaid-Postgres-elephants-on-orange-background-for-migration-guide-post-1920x1080.jpg%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--527827729%22%20id%3D%22toc-hId--527051243%22%3EWhat%20are%20database%20storage%20objects%3F%3C%2FH2%3E%0A%3CP%3EAny%20object%20in%20a%20relational%20database%20that%20defines%20how%20data%20is%20stored%2C%20represented%2C%20and%20accessed%20is%20a%20database%20storage%20object.%20Database%20storage%20objects%20include%3A%20Schemas%2C%20Tables%2C%20Types%2C%20Constraints%2C%20Indexes%2C%20Sequences%2C%20Views%2C%20Synonyms%2C%20Database%20Links%2C%20etc.%20While%20each%20of%20these%20objects%20may%20mean%20different%20things%20in%20Postgres%20(compared%20to%20Oracle)%2C%20it%20is%20important%20for%20you%20to%20know%20the%20best%20practices%20of%20migrating%20each%20of%20these%20objects%20from%20your%20Oracle%20database%20to%20Postgres.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3BIn%20this%20post%2C%20you%20will%20learn%20about%3A%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EBest%20practices%20to%20move%20some%20of%20these%20database%20objects%2C%20excerpted%20from%20the%20migration%20guide%3C%2FLI%3E%0A%3CLI%3ESome%20of%20my%20favorite%20examples%20of%20what%20to%20watch%20out%20for.%20I%20have%20burnt%20my%20fingers%20quite%20a%20few%20times%20when%20migrating%20a%20few%20of%20these%20database%20storage%20objects.%20I%20don%E2%80%99t%20want%20you%20to%20have%20to%20burn%20your%20fingers%20too.%26nbsp%3B%3CIMG%20class%3D%22lia-deferred-image%20lia-image-emoji%22%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Fhtml%2F%40D0941B27F467CBA2580A8C085A80A0CF%2Fimages%2Femoticons%2Fhappyface_40x40.gif%22%20alt%3D%22%3Ahappyface%3A%22%20title%3D%22%3Ahappyface%3A%22%20%2F%3E%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3EThe%20good%20news%20is%20that%20converting%2Fmigrating%20database%20storage%20objects%20from%20Oracle%20to%20Postgres%20is%20relatively%20easy%20compared%20to%20more%20complex%20DB%20objects%20such%20as%20packages%2C%20functions%2C%20procedures%2C%20etc.%20(typically%20known%20as%20DB%20code%20objects).%26nbsp%3BOne%20of%20the%20open%20source%20tools%20that%20we%20employ%20in%20Oracle%20to%20Postgres%20migrations%20is%20the%20wonderful%3CCODE%20style%3D%22color%3A%20black%3B%22%3EOra2Pg%3C%2FCODE%3Eutility.%20If%20you%E2%80%99re%20not%20yet%20familiar%2C%26nbsp%3B%3CA%20href%3D%22http%3A%2F%2Fora2pg.darold.net%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3EOra2Pg%3C%2FA%3E%26nbsp%3Bis%20a%20free%2C%20open%20source%20tool%20used%20to%20migrate%20an%20Oracle%20database%20to%20a%20PostgreSQL%20compatible%20schema.%26nbsp%3B%3CA%20href%3D%22http%3A%2F%2Fora2pg.darold.net%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3EOra2pg%3C%2FA%3E%26nbsp%3Bdoes%20a%20great%20job%20in%20converting%20DB%20storage%20objects%20automatically%20and%20has%20improved%20a%20lot%20over%20the%20years%20to%20cater%20to%20different%20combinations%20of%20these%20storage%20objects.%20The%20key%20to%20a%20successful%20migration%20lies%20in%20understanding%20how%20to%20convert%20these%20database%20storage%20objects%2C%20knowing%20why%3CCODE%20style%3D%22color%3A%20black%3B%22%3EOra2pg%3C%2FCODE%3Edoes%20conversions%20in%20a%20certain%20way%2C%20and%20ensuring%20that%20your%20converted%20workload%20works%20optimally%20in%20Postgres.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1959685104%22%20id%3D%22toc-hId-1960461590%22%3EWhat%20is%20the%20deal%20with%20schemas%20in%20Oracle%20vs.%20Postgres%3F%3C%2FH2%3E%0A%3CP%3ELet%E2%80%99s%20dive%20into%20an%20example%20right%20away.%20In%20Oracle%2C%20users%20and%20schemas%20are%20essentially%20the%20same%20thing.%20When%20you%20create%20a%20user%20(using%20the%20%E2%80%9Ccreate%20user%E2%80%9D%20command)%2C%20Oracle%20also%20creates%20a%20schema%20container%20to%20hold%20all%20objects%20that%20user%20creates.%20Whereas%20in%20Postgres%2C%20all%20objects%20created%20by%20a%20user%20need%20to%20be%20explicitly%20created%20in%20a%20schema%20within%20the%20database.%20All%20Postgres%20users%20are%20global%20to%20the%20entire%20server%20by%20itself.%20%3CA%20href%3D%22https%3A%2F%2Fblog.dbi-services.com%2Fa-schema-and-a-user-are-not-the-same-in-postgresql%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3EThis%20blog%20post%3C%2FA%3E%20on%20schemas%20in%20Oracle%20vs.%20Postgres%20depicts%20this%20difference%20well.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%E2%80%99re%20essentially%20going%20from%20%E2%80%93%3C%2FP%3E%0A%3CP%3E%7C------------------------------------------%7C%3C%2FP%3E%0A%3CP%3E%7C%20Oracle%20server%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%7C%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%7C------------------------------------------%7C%3C%2FP%3E%0A%3CP%3E%7C%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Database%201%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%7C%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Database%202%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7C%20DATABASE%3C%2FP%3E%0A%3CP%3E%7C---------------------%7C---------------------%7C%3C%2FP%3E%0A%3CP%3E%7C%26nbsp%3B%26nbsp%3B%20User%201%26nbsp%3B%20%7C%26nbsp%3B%20User%202%26nbsp%3B%20%7C%26nbsp%3B%20%26nbsp%3BUser%201%26nbsp%3B%20%7C%26nbsp%3B%20User%202%26nbsp%3B%20%7C%20USERS%2FSCHEMAS%3C%2FP%3E%0A%3CP%3E%7C----------%7C----------%7C----------%7C----------%7C%3C%2FP%3E%0A%3CP%3E%7C%20t1%2Ct2%2Ct3%26nbsp%3B%20%7C%20t1%2Ct2%2Ct3%26nbsp%3B%20%26nbsp%3B%7C%20t1%2Ct2%2Ct3%26nbsp%3B%20%7C%20t1%2Ct2%2Ct3%26nbsp%3B%20%26nbsp%3B%7C%20TABLES%3C%2FP%3E%0A%3CP%3E-------------------------------------------%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETO%3C%2FP%3E%0A%3CP%3E%7C--------------------------------------------------%7C---%7C%3C%2FP%3E%0A%3CP%3E%7C%20PostgreSQL%20instance%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7C%26nbsp%3B%26nbsp%3B%20%7C%3C%2FP%3E%0A%3CP%3E%7C--------------------------------------------------%7C%20U%20%7C%3C%2FP%3E%0A%3CP%3E%7C%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Database%201%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7C%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Database%202%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%7C%20S%20%7C%3C%2FP%3E%0A%3CP%3E%7C-------------------------%7C------------------------%20%7C%20E%20%7C%3C%2FP%3E%0A%3CP%3E%7C%20Schema%201%20%7C%20Schema%202%20%7C%20Schema%201%20%7C%20Schema%202%20%7C%20R%20%7C%3C%2FP%3E%0A%3CP%3E%7C------------%7C------------%7C------------%7C------------%7C%20S%20%7C%3C%2FP%3E%0A%3CP%3E%7C%20t1%2Ct2%2Ct3%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%7C%20t1%2Ct2%2Ct3%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7C%20t1%2Ct2%2Ct3%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%7C%20t1%2Ct2%2Ct3%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%7C%26nbsp%3B%26nbsp%3B%20%7C%3C%2FP%3E%0A%3CP%3E-------------------------------------------------%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20top%20things%20to%20consider%20when%20going%20through%20database%20level%20changes%20(such%20as%20the%20schema%20example%20above)%20are%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EWould%20your%20front-end%20application%20work%20with%20changes%20described%20above%3F%20If%20not%2C%20what%20would%20you%20need%20to%20change%3F%20Some%20apps%20are%20interfaced%20with%20an%20ORM%20layer%20that%20make%20these%20database%2Fschema%20level%20changes%20easy%20to%20take%20in.%20You%20may%20need%20to%20rearchitect%20some%20apps%20to%20work%20with%20this%20paradigm%20shift.%3C%2FLI%3E%0A%3CLI%3EWith%20these%20types%20of%20database%20level%20changes%2C%20are%20you%20going%20to%20get%20the%20required%20performance%20you%20need%20from%20the%20app%20and%20meet%20your%20SLAs%3F%20This%20is%20almost%20always%20answered%20via%20thorough%20testing%20at%20the%20end%20of%20the%20conversion%20exercise.%20Eventually%2C%20it%20also%20makes%20sense%20to%20test%20the%20entire%20stack%20once%20data%20migration%20is%20complete%20as%20well.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EBottom%20line%2C%20the%20schema-based%20semantics%20are%20quite%20different%20between%20Oracle%20and%20Postgres.%20So%2C%20you%20have%20to%20figure%20out%20whether%20your%20app%20is%20going%20to%20work%20as%20expected%20with%20a%20different%20schema%2C%20or%20whether%20you%20need%20to%20make%20some%20adjustments%20in%20your%20application.%20Don%E2%80%99t%20worry%2C%20though%E2%80%94catching%20these%20differences%20and%20implementing%20them%20are%20very%20easy%20once%20you%20get%20a%20hang%20of%20it.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EGiven%20schemas%20and%20users%20are%20the%20same%20thing%20in%20Oracle%2C%20there%20are%20multiple%20gotchas%20to%20take%20care%20of.%20All%20these%20gotchas%20with%20examples%20like%20above%20are%20given%20in%20the%20chapter%20on%20%3CSTRONG%3E%22Migrating%20from%20Oracle%20Security%20Model%22%20in%20page%2061%3C%2FSTRONG%3E%20of%20the%20%3CA%20href%3D%22https%3A%2F%2Faka.ms%2FOracletoPGguide%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EOracle%20to%20Postgres%20migration%20guide%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-152230641%22%20id%3D%22toc-hId-153007127%22%3EA%20fun%20story%20on%20numeric%20vs.%20BIGINT%3C%2FH2%3E%0A%3CP%3EWhen%20it%20comes%20to%20migrating%20tables%2C%20data%20type%20differences%20between%20Oracle%20and%20PostgreSQL%20take%20up%20a%20lot%20of%20mindshare.%20Before%20I%20tell%20you%20where%20to%20find%20specifics%20on%20table%20partitioning%2C%20migrating%20index%20organized%20tables%2C%20etc.%20from%20Oracle%2C%20let%20me%20walk%20you%20through%20a%20practical%20experience%20with%20data%20types%20to%20show%20you%20how%20important%20testing%20each%20conversion%20is.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EOracle%20has%20a%20very%20rich%20set%20of%20number%20related%20data%20types%20(think%20INT%2C%20DOUBLE%2C%20FLOAT%20etc.)%20with%20an%20ability%20to%20store%20scale%20and%20precision.%20However%2C%20when%20querying%20the%20Oracle%20dictionary%20tables%20to%20get%20details%20on%20data%20types%20for%20each%20table%20column%2C%20Oracle%20stores%20each%20of%20these%20numeric%20subtypes%20as%20a%20NUMBER%20with%20appropriate%20scale%20and%20precision.%20Sometimes%2C%20irrespective%20of%20what%20the%20subtype%20is%2C%20these%20columns%20get%20converted%20to%20numeric%20during%20the%20conversion%20process.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWell%2C%20here%20is%20the%20kicker.%20In%20Oracle%2C%20the%20largest%20number%20data%20type%20holds%2038%20digits.%20In%20Postgres%2C%20the%20largest%20numeric%20datatype%20can%20hold%20131%2C072%20digits.%20If%20you%20don't%20follow%20the%20tips%20and%20best%20practices%20in%20the%20%3CA%20href%3D%22https%3A%2F%2Faka.ms%2FOracletoPGguide%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EOracle%20to%20Postgres%20migration%20guide%3C%2FA%3E%E2%80%94and%20if%20the%20primary%20key%20index%20on%20this%20number%20column%20in%20Oracle%20is%20translated%20to%20a%20numeric%20in%20Postgres%E2%80%94%3CSTRONG%3Eyou%20will%20pay%20a%20performance%20penalty%20in%20Postgres%3C%2FSTRONG%3E.%20The%20good%20news%20is%2C%20the%20data%20type%20migration%20best%20practices%20in%20the%20%E2%80%9CData%20type%20conversions%E2%80%9D%20section%20of%20our%3CA%20href%3D%22https%3A%2F%2Faka.ms%2FOracletoPGguide%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%20Oracle%20to%20Postgres%20migration%20guide%3C%2FA%3E%20will%20help%20you%20avoid%20gotchas%20like%20this.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--1655223822%22%20id%3D%22toc-hId--1654447336%22%3EExperiment%20with%20Numeric%20types%3C%2FH2%3E%0A%3CP%3ELet%E2%80%99s%20do%20an%20interesting%20experiment%20to%20see%20the%20impact%20of%20creating%20an%20index%20on%20a%20numeric%20column%20vs.%20a%20BIGINT%20column%20in%20Postgres.%20In%20the%20example%20below%2C%20I%20am%20creating%202%20two-column%20tables%2C%20one%20with%20the%20ID%20set%20to%20numeric%20and%20the%20other%20with%20ID%20set%20to%20BIGINT.%20I%20am%20inserting%201M%20rows%20in%20each%20and%20comparing%20how%20long%20it%20takes%20to%20do%20a%20self-join%20count%20on%20both.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-sql%22%3E%3CCODE%3ECREATE%20TABLE%20public.arthiaga_numeric(id%20numeric%20NOT%20NULL%2C%20name%20character%20varying(200))%3B%0A%0A%23Insert%201M%20rows%0AINSERT%20INTO%20public.arthiaga_numeric(id%2C%20name)%0A%20SELECT%20generate_series(1%2C1000000)%2C%20md5(random()%3A%3Atext)%3B%0A%0AINSERT%200%201000000%0AQuery%20returned%20successfully%20in%203%20secs%20585%20msec.%0A%0A%23Add%20primary%20key%0AALTER%20TABLE%20public.arthiaga_numeric%20ADD%20PRIMARY%20KEY(id)%3B%0A%0AALTER%20TABLE%0AQuery%20returned%20successfully%20in%201%20secs%20262%20msec.%0A%0A%23Do%20a%20self-join%20count%0Aselect%20count(*)%20from%20public.arthiaga_numeric%20a%2C%20public.arthiaga_numeric%20b%20where%20a.id%3Db.id%3B%0A%0ASuccessfully%20run.%20Total%20query%20runtime%3A%201%20secs%20123%20msec.%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-832289011%22%20id%3D%22toc-hId-833065497%22%3EExperiment%20with%20BIGINT%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-sql%22%3E%3CCODE%3ECREATE%20TABLE%20public.arthiaga_bigint(id%20bigint%20NOT%20NULL%2C%20name%20character%20varying(200))%3B%0A%0A%23Insert%201M%20rows%0AINSERT%20INTO%20public.arthiaga_bigint(id%2C%20name)%0A%20SELECT%20generate_series(1%2C1000000)%2C%20md5(random()%3A%3Atext)%3B%0A%0AINSERT%200%201000000%0AQuery%20returned%20successfully%20in%203%20secs%20710%20msec.%0A%0A%23Add%20primary%20key%0AALTER%20TABLE%20public.arthiaga_bigint%20ADD%20PRIMARY%20KEY(id)%3B%0A%0AALTER%20TABLE%0AQuery%20returned%20successfully%20in%201%20secs%20107%20msec.%0A%0A%23Do%20a%20self-join%20count%0Aselect%20count(*)%20from%20public.arthiaga_bigint%20a%2C%20public.arthiaga_bigint%20b%20where%20a.id%3Db.id%3B%0A%0ASuccessfully%20run.%20Total%20query%20runtime%3A%201%20secs%203%20msec.%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFor%20a%20million-row%20table%20with%20two%20basic%20columns%2C%20you%20already%20see%20an%20%3CSTRONG%3E11%25%20improvement%20in%20query%20response%20times%3C%2FSTRONG%3E%20when%20I%20create%20an%20index%20on%20a%20BIGINT%20column%20as%20opposed%20to%20a%20numeric%20column%20in%20PostgreSQL.%20As%20you%20can%20see%20%E2%80%93%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CTABLE%20border%3D%221%22%20width%3D%2299.86187845303867%25%22%3E%0A%3CTBODY%3E%0A%3CTR%3E%0A%3CTD%20width%3D%2250%25%22%3E%3CP%3ECount%20query%20with%20BIGINT%20for%20a%201M%20row%20table%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%20width%3D%2249.86187845303867%25%22%3E%3CP%3ECompletes%20in%20%3CU%3E%3CSTRONG%3E1.003%3C%2FSTRONG%3E%3C%2FU%3E%20seconds%3C%2FP%3E%0A%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%20width%3D%2250%25%22%3E%3CP%3ECount%20query%20with%20NUMERIC%20for%20a%201M%20row%20table%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%20width%3D%2249.86187845303867%25%22%3E%3CP%3ECompletes%20in%201.123%20seconds%3C%2FP%3E%0A%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3C%2FTBODY%3E%0A%3C%2FTABLE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EImagine%20the%20performance%20penalties%20you%20will%20need%20to%20pay%20for%20larger%20and%20more%20complex%20table%20structures.%20Imagine%20the%20end-to-end%20performance%20impact%20when%20query%20response%20times%20are%20high%20across%20multiple%20tables%20in%20a%20workload.%20I%20would%20encourage%20you%20try%20this%20experiment%20on%20larger%20and%20more%20complex%20tables%20to%20see%20bigger%20performance%20gains%20yourself.%20For%20certain%20workloads%2C%20we%20have%20measured%20very%20high%20improvements%20in%20query%20response%20times%20(north%20of%2080%25)%20by%20just%20switching%20to%20use%20the%20right%20data%20type%20in%20Postgres.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20key%20thing%20to%20know%20is%2C%20from%20a%20table%20migration%20standpoint%2C%20you%20should%20keep%20an%20eye%20on%20data%20types%2C%20partitioning%20schemes%2C%20indexes%2C%20constraints%2C%20LOBs%2C%20temporary%20tables%2C%20sequences%20etc.%20when%20migrating%20from%20Oracle%20to%20Postgres.%20You%20can%20learn%20about%20all%20of%20these%20aspects%20in%20the%20%3CA%20href%3D%22https%3A%2F%2Faka.ms%2FOracletoPGguide%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EOracle%20to%20Postgres%20migration%20guide%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENext%20up%2C%20let%E2%80%99s%20look%20at%20a%20couple%20more%20of%20my%20most%20favorite%20learnings%20based%20on%20my%20experience%20with%20migrating%20DB%20storage%20objects%20in%20Oracle%20to%20Postgres%20migrations.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--975165452%22%20id%3D%22toc-hId--974388966%22%3ENULLs%20in%20Postgres%2C%20anyone%3F%3C%2FH2%3E%0A%3CP%3EPostgres%20handles%20NULLs%20in%20strings%20in%20a%20completely%20different%20way%20compared%20to%20Oracle%E2%80%94period!%20I%20highly%20recommend%20paying%20attention%20to%20and%20updating%20your%20SQL%20queries%20to%20cater%20to%20subtle%20differences%20in%20the%20treatment%20of%20NULLs.%20To%20avoid%20last-minute%20issues%20during%20cutover%20phases%2C%20you%E2%80%99ll%20definitely%20want%20to%20test%20(and%20test%2C%20and%20test)%20earlier%20in%20the%20process.%20If%20you%E2%80%99re%20migrating%20from%20a%20typical%20Oracle%20workload%2C%20there%20is%20a%20high%20chance%20you%20will%20hit%20this%20issue%20in%20the%20way%20Oracle%20treats%20NULLs%20in%20strings%20vs.%20Postgres.%20Let%E2%80%99s%20look%20at%20an%20example.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ELet%E2%80%99s%20use%20the%20same%20table%20created%20above%20for%20this%20experiment.%20I%20will%20just%20remove%20the%20primary%20key%20and%20add%20a%20composite%20unique%20constraint%20to%20one%20of%20the%20tables%20above%20to%20keep%20the%20explanation%20simple.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-sql%22%3E%3CCODE%3ECREATE%20TABLE%20public.arthiaga_bigint(id%20bigint%20NOT%20NULL%2C%20name%20character%20varying(200))%3B%0A%0A%23Add%20composite%20unique%20constraint%20across%20columns%0Aalter%20table%20public.arthiaga_bigint%20add%20constraint%20uniq_bigint%20unique%20(id%2C%20name)%3B%0A%0A%23Insert%20more%20rows%0AINSERT%20INTO%20public.arthiaga_bigint(id%2C%20name)%20VALUES%20(1%2C%20'Arun')%3B%0AINSERT%20INTO%20public.arthiaga_bigint(id)%20VALUES%20(2)%3B%0AINSERT%20INTO%20public.arthiaga_bigint(id)%20VALUES%20(2)%3B%0AINSERT%20INTO%20public.arthiaga_bigint(id)%20VALUES%20(3)%3B%0AINSERT%20INTO%20public.arthiaga_bigint(id)%20VALUES%20(3)%3B%0A%0A%23Table%20select%0Aselect%20*%20from%20public.arthiaga_bigint%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Figure-1-Non-uniqueness-in-Postgres-due-to-NULLs-528x318.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F253169i4917758523EC5403%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Figure-1-Non-uniqueness-in-Postgres-due-to-NULLs-528x318.png%22%20alt%3D%22Figure%201%3A%20Non-uniqueness%20in%20PostgreSQL%20due%20to%20NULLs.%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3EFigure%201%3A%20Non-uniqueness%20in%20PostgreSQL%20due%20to%20NULLs.%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EGuess%20what%20the%20select%20returns%2C%20despite%20the%20unique%20constraint%3F%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EThe%20duplicate%20inserts%20in%20Oracle%20will%20fail%2C%20given%20that%20Oracle%20supports%20null%20comparison.%3C%2FLI%3E%0A%3CLI%3EIn%20Postgres%2C%20two%20nulls%20aren%E2%80%99t%20the%20same%2C%20and%20hence%20despite%20the%20unique%20constraint%2C%20the%20duplicate%20insert%20goes%20through%20without%20issues.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EAs%20a%20result%2C%20when%20you%E2%80%99re%20migrating%20to%20Postgres%2C%20you%20will%20need%20to%20handle%20such%20exceptions%20in%20your%20application.%20And%20if%20you%20don%E2%80%99t%20handle%20these%20exceptions%20in%20your%20app%2C%20you%20are%20in%20for%20a%20lot%20of%20surprises.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20same%20point%20is%20applicable%20for%20NULLs%20within%20strings%20as%20well%3A%20Postgres%20does%20not%20support%20NULLs%20within%20strings%2C%20whereas%20Oracle%20does.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1512347381%22%20id%3D%22toc-hId-1513123867%22%3ESequence%20caching%20in%20Postgres%20vs.%20Oracle%3C%2FH2%3E%0A%3CP%3EOracle%20shares%20a%20sequence%20cache%20across%20multiple%20user%20sessions%20in%20the%20database.%20In%20PostgreSQL%2C%20the%20sequence%20cache%20is%20not%20shared%20across%20session%20and%20is%20instead%20at%20a%20per%20session%20level.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThis%20%3CA%20href%3D%22https%3A%2F%2Fseiler.us%2F2018-10-02-sequence-caching-oracle-vs-postgresql%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Eblog%20post%20on%20explaining%20sequence%20caching%20behavior%3C%2FA%3E%20differences%20in%20Oracle%20vs.%20Postgres%20does%20a%20great%20job%20on%20showing%20this%20behavior%20via%20an%20example.%20In%20the%20example%2C%20any%20new%20session%20in%20Postgres%20will%20get%20its%20own%20set%20of%20cached%20values%20for%20a%20particular%20sequence%20range.%20Whereas%20in%20Oracle%2C%20sequences%20are%20shared%20across%20sessions.%20If%20your%20application%20depends%20on%20shared%20cache%20values%20for%20sequences%2C%20it%20would%20be%20good%20to%20think%20about%20changing%20the%20design%20in%20the%20app%20itself%20given%20this%20difference.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWhile%20these%20are%20just%20a%20few%20examples%20based%20on%20my%20experience%2C%20the%20Oracle%20to%20Azure%20Database%20for%20PostgreSQL%20migration%20guide%20covers%20database%20storage%20object%20conversion%20topics%20in%20depth.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--295107082%22%20id%3D%22toc-hId--294330596%22%3ECheat%20sheet%3A%20where%20to%20find%20info%20about%20database%20storage%20objects%20in%20the%20migration%20guide%3C%2FH2%3E%0A%3CP%3EThis%20cheat%20sheet%20on%20where%20to%20find%20details%20about%20database%20storage%20objects%20in%20our%20%3CA%20href%3D%22https%3A%2F%2Faka.ms%2FOracletoPGguide%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EOracle%20to%20Postgres%20migration%20guide%3C%2FA%3E%20should%20be%20useful%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%3CSTRONG%3EData%20type%20conversions%3C%2FSTRONG%3E%2C%20with%20best%20practices%20%E2%80%93%20starting%20page%20241.%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3EPartitioning%20schemes%3C%2FSTRONG%3E%20%E2%80%93%20starting%20page%20198.%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3EIndexes%3C%2FSTRONG%3E%20%E2%80%93%20starting%20page%20294.%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3EConstraints%3C%2FSTRONG%3E%20%E2%80%93%20starting%20page%20184.%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3ELOBs%3C%2FSTRONG%3E%20%E2%80%93%20starting%20page%20223.%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3ETemporary%20tables%3C%2FSTRONG%3E%20%E2%80%93%20starting%20page%20171.%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3ESequences%3C%2FSTRONG%3E%20%E2%80%93%20starting%20page%20252.%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3ETablespaces%3C%2FSTRONG%3E%20%E2%80%93%20starting%20page%2076.%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3EUser-Defined%20types%3C%2FSTRONG%3E%20%E2%80%93%20starting%20page%20270.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EAs%20you%20can%20see%2C%20this%20guide%20has%20a%20LOT%20of%20content%20and%20is%20improved%20frequently.%20While%20these%20page%20numbers%20can%20change%20in%20a%20future%20version%20of%20this%20guide%2C%20you%20can%20still%20search%20for%20the%20chapters%20listed%20above.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--2102561545%22%20id%3D%22toc-hId--2101785059%22%3EIf%20you%E2%80%99re%20looking%20to%20migrate%20from%20Oracle%20to%20Postgres%2C%20some%20links%20%26amp%3B%20resources%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENow%20that%20you%20have%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3Eseen%20what%20the%20migration%20journey%20looks%20like%20in%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fazure-database-for-postgresql%2Fnew-oracle-to-postgres-migration-guide-for-azure%2Fba-p%2F2055303%22%20target%3D%22_blank%22%3Epart%201%20of%20this%20Oracle%20to%20Postgres%3C%2FA%3E%26nbsp%3Bblog%20series%20and%3C%2FLI%3E%0A%3CLI%3Egotten%20a%20rundown%20of%20migrating%20database%20storage%20objects%20to%20Postgres%20in%20this%20part%202%20blog%20post%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3Eyou%20might%20want%20to%20also%20check%20out%20the%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fmicrosoft%2FOrcasNinjaTeam%2Fblob%2Fmaster%2FOracle%2520to%2520PostgreSQL%2520Migration%2520Guide%2FOracle%2520to%2520Azure%2520Database%2520for%2520PostgreSQL%2520Migration%2520Guide.pdf%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EOracle%20to%20Azure%20Database%20for%20PostgreSQL%20migration%20guide%3C%2FA%3E.%20Let%20me%20know%20if%20it%E2%80%99s%20useful.%20And%20especially%20let%20me%20know%20if%20you%20see%20ways%20to%20make%20it%20even%20more%20useful.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20you%20want%20to%20chat%20about%20migrations%20to%20PostgreSQL%20in%20general%E2%80%94or%20have%20questions%20about%20our%20PostgreSQL%20managed%20service%20on%20Azure%E2%80%94you%20can%20always%20reach%20our%20product%20team%20via%20email%20at%20%3CA%20href%3D%22mailto%3AAskAzureDBforPostgreSQL%40service.microsoft.com%3Fsubject%3DOracle%2520to%2520Postgres%2520Migration%2520Blogs%2C%2520part%25202%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3EAsk%20AzureDB%20for%20PostgreSQL%3C%2FA%3E.%20I%20also%20love%20all%20the%20updates%20on%20our%20Twitter%20handle%20(%3CA%20href%3D%22https%3A%2F%2Ftwitter.com%2FAzureDBPostgres%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3E%40AzureDBPostgres%3C%2FA%3E)%20and%20recommend%20following%20us%20for%20more%20Postgres%20news%20and%20updates.%20We%20would%20love%20to%20hear%20from%20you.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EHappy%20learning.%26nbsp%3B%3CIMG%20class%3D%22lia-deferred-image%20lia-image-emoji%22%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Fhtml%2F%408341BD79091AF36AA2A09063B554B5CD%2Fimages%2Femoticons%2Fsmile_40x40.gif%22%20alt%3D%22%3Asmile%3A%22%20title%3D%22%3Asmile%3A%22%20%2F%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-2117312%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Trio-of-plaid-Postgres-elephants-on-orange-background-for-migration-guide-post-1920x1080.jpg%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F253170i951167DB75AA9DDE%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Trio-of-plaid-Postgres-elephants-on-orange-background-for-migration-guide-post-1920x1080.jpg%22%20alt%3D%22Do%20you%20know%20the%20best%20practices%20to%20migrate%20database%20storage%20objects%20such%20as%20tables%2C%20indexes%2C%20etc.%20from%20Oracle%20to%20Postgres%3F%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3EDo%20you%20know%20the%20best%20practices%20to%20migrate%20database%20storage%20objects%20such%20as%20tables%2C%20indexes%2C%20etc.%20from%20Oracle%20to%20Postgres%3F%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EBest%20practices%20for%20migrating%20database%20storage%20objects%E2%80%94such%20as%20tables%2C%20indexes%2C%20%26amp%3B%20schemas%E2%80%94from%20Oracle%20to%20Postgres.%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2117312%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%20Database%20for%20PostgreSQL%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EDatabases%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Edatatype%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMigration%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EOracle%20to%20Postgres%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Epostgres%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPostgreSQL%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft

Welcome to part 2 of the four-part blog series on navigating Oracle to Postgres migrations. I am super stoked to let you know the first post in the series—announcing the new Oracle to Postgres migration guide for Azure—had 1000s of views and was featured in the 389th edition of the Postgres Weekly newsletter. I feel happy that many of you personally messaged me to let me know that the migration guide is helping your migration projects. Thank you for all the feedback.

 

Oracle to Postgres migrations are hard, multi-step projects—especially for complex applications.  From my experience working with those of you who have already done an Oracle to Postgres migration—specifically migrations to our Azure Database for PostgreSQL managed service—many of you spend more than 60% of the entire migration project in the conversion (step 4) and migration (step 6) phases. In the first post in this Oracle to Postgres migration series, I dove deep into the different steps of an Oracle to Postgres migration. In the same spirit, let’s dive into some practical examples of how our Oracle to Postgres migration guide can help you migrate your database storage objects.

 

Trio-of-plaid-Postgres-elephants-on-orange-background-for-migration-guide-post-1920x1080.jpg

 

What are database storage objects?

Any object in a relational database that defines how data is stored, represented, and accessed is a database storage object. Database storage objects include: Schemas, Tables, Types, Constraints, Indexes, Sequences, Views, Synonyms, Database Links, etc. While each of these objects may mean different things in Postgres (compared to Oracle), it is important for you to know the best practices of migrating each of these objects from your Oracle database to Postgres.

 

 In this post, you will learn about:

  1. Best practices to move some of these database objects, excerpted from the migration guide
  2. Some of my favorite examples of what to watch out for. I have burnt my fingers quite a few times when migrating a few of these database storage objects. I don’t want you to have to burn your fingers too. :happyface:

The good news is that converting/migrating database storage objects from Oracle to Postgres is relatively easy compared to more complex DB objects such as packages, functions, procedures, etc. (typically known as DB code objects). One of the open source tools that we employ in Oracle to Postgres migrations is the wonderful Ora2Pg utility. If you’re not yet familiar, Ora2Pg is a free, open source tool used to migrate an Oracle database to a PostgreSQL compatible schema. Ora2pg does a great job in converting DB storage objects automatically and has improved a lot over the years to cater to different combinations of these storage objects. The key to a successful migration lies in understanding how to convert these database storage objects, knowing why Ora2pg does conversions in a certain way, and ensuring that your converted workload works optimally in Postgres.

 

What is the deal with schemas in Oracle vs. Postgres?

Let’s dive into an example right away. In Oracle, users and schemas are essentially the same thing. When you create a user (using the “create user” command), Oracle also creates a schema container to hold all objects that user creates. Whereas in Postgres, all objects created by a user need to be explicitly created in a schema within the database. All Postgres users are global to the entire server by itself. This blog post on schemas in Oracle vs. Postgres depicts this difference well.

 

You’re essentially going from –

|------------------------------------------|

| Oracle server                                       | 

|------------------------------------------|

|     Database 1       |     Database 2        | DATABASE

|---------------------|---------------------|

|   User 1  |  User 2  |   User 1  |  User 2  | USERS/SCHEMAS

|----------|----------|----------|----------|

| t1,t2,t3  | t1,t2,t3   | t1,t2,t3  | t1,t2,t3   | TABLES

-------------------------------------------

 

TO

|--------------------------------------------------|---|

| PostgreSQL instance                                        |   |

|--------------------------------------------------| U |

|     Database 1              |     Database 2             | S |

|-------------------------|------------------------ | E |

| Schema 1 | Schema 2 | Schema 1 | Schema 2 | R |

|------------|------------|------------|------------| S |

| t1,t2,t3     | t1,t2,t3      | t1,t2,t3     | t1,t2,t3      |   |

-------------------------------------------------

 

The top things to consider when going through database level changes (such as the schema example above) are:

  • Would your front-end application work with changes described above? If not, what would you need to change? Some apps are interfaced with an ORM layer that make these database/schema level changes easy to take in. You may need to rearchitect some apps to work with this paradigm shift.
  • With these types of database level changes, are you going to get the required performance you need from the app and meet your SLAs? This is almost always answered via thorough testing at the end of the conversion exercise. Eventually, it also makes sense to test the entire stack once data migration is complete as well.

Bottom line, the schema-based semantics are quite different between Oracle and Postgres. So, you have to figure out whether your app is going to work as expected with a different schema, or whether you need to make some adjustments in your application. Don’t worry, though—catching these differences and implementing them are very easy once you get a hang of it.

 

Given schemas and users are the same thing in Oracle, there are multiple gotchas to take care of. All these gotchas with examples like above are given in the chapter on "Migrating from Oracle Security Model" in page 61 of the Oracle to Postgres migration guide.

 

A fun story on numeric vs. BIGINT

When it comes to migrating tables, data type differences between Oracle and PostgreSQL take up a lot of mindshare. Before I tell you where to find specifics on table partitioning, migrating index organized tables, etc. from Oracle, let me walk you through a practical experience with data types to show you how important testing each conversion is.

 

Oracle has a very rich set of number related data types (think INT, DOUBLE, FLOAT etc.) with an ability to store scale and precision. However, when querying the Oracle dictionary tables to get details on data types for each table column, Oracle stores each of these numeric subtypes as a NUMBER with appropriate scale and precision. Sometimes, irrespective of what the subtype is, these columns get converted to numeric during the conversion process.

 

Well, here is the kicker. In Oracle, the largest number data type holds 38 digits. In Postgres, the largest numeric datatype can hold 131,072 digits. If you don't follow the tips and best practices in the Oracle to Postgres migration guide—and if the primary key index on this number column in Oracle is translated to a numeric in Postgres—you will pay a performance penalty in Postgres. The good news is, the data type migration best practices in the “Data type conversions” section of our Oracle to Postgres migration guide will help you avoid gotchas like this.

 

Experiment with Numeric types

Let’s do an interesting experiment to see the impact of creating an index on a numeric column vs. a BIGINT column in Postgres. In the example below, I am creating 2 two-column tables, one with the ID set to numeric and the other with ID set to BIGINT. I am inserting 1M rows in each and comparing how long it takes to do a self-join count on both.

 

CREATE TABLE public.arthiaga_numeric(id numeric NOT NULL, name character varying(200));

#Insert 1M rows
INSERT INTO public.arthiaga_numeric(id, name)
	SELECT generate_series(1,1000000), md5(random()::text);

INSERT 0 1000000
Query returned successfully in 3 secs 585 msec.

#Add primary key
ALTER TABLE public.arthiaga_numeric ADD PRIMARY KEY(id);

ALTER TABLE
Query returned successfully in 1 secs 262 msec.

#Do a self-join count
select count(*) from public.arthiaga_numeric a, public.arthiaga_numeric b where a.id=b.id;

Successfully run. Total query runtime: 1 secs 123 msec.

 

Experiment with BIGINT

 

CREATE TABLE public.arthiaga_bigint(id bigint NOT NULL, name character varying(200));

#Insert 1M rows
INSERT INTO public.arthiaga_bigint(id, name)
	SELECT generate_series(1,1000000), md5(random()::text);

INSERT 0 1000000
Query returned successfully in 3 secs 710 msec.

#Add primary key
ALTER TABLE public.arthiaga_bigint ADD PRIMARY KEY(id);

ALTER TABLE
Query returned successfully in 1 secs 107 msec.

#Do a self-join count
select count(*) from public.arthiaga_bigint a, public.arthiaga_bigint b where a.id=b.id;

Successfully run. Total query runtime: 1 secs 3 msec.

 

For a million-row table with two basic columns, you already see an 11% improvement in query response times when I create an index on a BIGINT column as opposed to a numeric column in PostgreSQL. As you can see –

 

Count query with BIGINT for a 1M row table

Completes in 1.003 seconds

Count query with NUMERIC for a 1M row table

Completes in 1.123 seconds

 

Imagine the performance penalties you will need to pay for larger and more complex table structures. Imagine the end-to-end performance impact when query response times are high across multiple tables in a workload. I would encourage you try this experiment on larger and more complex tables to see bigger performance gains yourself. For certain workloads, we have measured very high improvements in query response times (north of 80%) by just switching to use the right data type in Postgres.

 

The key thing to know is, from a table migration standpoint, you should keep an eye on data types, partitioning schemes, indexes, constraints, LOBs, temporary tables, sequences etc. when migrating from Oracle to Postgres. You can learn about all of these aspects in the Oracle to Postgres migration guide.

 

Next up, let’s look at a couple more of my most favorite learnings based on my experience with migrating DB storage objects in Oracle to Postgres migrations.

 

NULLs in Postgres, anyone?

Postgres handles NULLs in strings in a completely different way compared to Oracle—period! I highly recommend paying attention to and updating your SQL queries to cater to subtle differences in the treatment of NULLs. To avoid last-minute issues during cutover phases, you’ll definitely want to test (and test, and test) earlier in the process. If you’re migrating from a typical Oracle workload, there is a high chance you will hit this issue in the way Oracle treats NULLs in strings vs. Postgres. Let’s look at an example.

 

Let’s use the same table created above for this experiment. I will just remove the primary key and add a composite unique constraint to one of the tables above to keep the explanation simple.

 

CREATE TABLE public.arthiaga_bigint(id bigint NOT NULL, name character varying(200));

#Add composite unique constraint across columns
alter table public.arthiaga_bigint add constraint uniq_bigint unique (id, name);

#Insert more rows
INSERT INTO public.arthiaga_bigint(id, name) VALUES (1, 'Arun');
INSERT INTO public.arthiaga_bigint(id) VALUES (2);
INSERT INTO public.arthiaga_bigint(id) VALUES (2);
INSERT INTO public.arthiaga_bigint(id) VALUES (3);
INSERT INTO public.arthiaga_bigint(id) VALUES (3);

#Table select
select * from public.arthiaga_bigint;

 

Figure 1: Non-uniqueness in PostgreSQL due to NULLs.Figure 1: Non-uniqueness in PostgreSQL due to NULLs.

 

Guess what the select returns, despite the unique constraint?

  • The duplicate inserts in Oracle will fail, given that Oracle supports null comparison.
  • In Postgres, two nulls aren’t the same, and hence despite the unique constraint, the duplicate insert goes through without issues.

As a result, when you’re migrating to Postgres, you will need to handle such exceptions in your application. And if you don’t handle these exceptions in your app, you are in for a lot of surprises.

 

The same point is applicable for NULLs within strings as well: Postgres does not support NULLs within strings, whereas Oracle does.

 

Sequence caching in Postgres vs. Oracle

Oracle shares a sequence cache across multiple user sessions in the database. In PostgreSQL, the sequence cache is not shared across session and is instead at a per session level.

 

This blog post on explaining sequence caching behavior differences in Oracle vs. Postgres does a great job on showing this behavior via an example. In the example, any new session in Postgres will get its own set of cached values for a particular sequence range. Whereas in Oracle, sequences are shared across sessions. If your application depends on shared cache values for sequences, it would be good to think about changing the design in the app itself given this difference.

 

While these are just a few examples based on my experience, the Oracle to Azure Database for PostgreSQL migration guide covers database storage object conversion topics in depth.

 

Cheat sheet: where to find info about database storage objects in the migration guide

This cheat sheet on where to find details about database storage objects in our Oracle to Postgres migration guide should be useful:

 

  • Data type conversions, with best practices – starting page 241.
  • Partitioning schemes – starting page 198.
  • Indexes – starting page 294.
  • Constraints – starting page 184.
  • LOBs – starting page 223.
  • Temporary tables – starting page 171.
  • Sequences – starting page 252.
  • Tablespaces – starting page 76.
  • User-Defined types – starting page 270.

As you can see, this guide has a LOT of content and is improved frequently. While these page numbers can change in a future version of this guide, you can still search for the chapters listed above.

 

If you’re looking to migrate from Oracle to Postgres, some links & resources

 

Now that you have:

  • seen what the migration journey looks like in part 1 of this Oracle to Postgres blog series and
  • gotten a rundown of migrating database storage objects to Postgres in this part 2 blog post

you might want to also check out the Oracle to Azure Database for PostgreSQL migration guide. Let me know if it’s useful. And especially let me know if you see ways to make it even more useful.

 

If you want to chat about migrations to PostgreSQL in general—or have questions about our PostgreSQL managed service on Azure—you can always reach our product team via email at Ask AzureDB for PostgreSQL. I also love all the updates on our Twitter handle (@AzureDBPostgres) and recommend following us for more Postgres news and updates. We would love to hear from you.

 

Happy learning. :smile: