{"id":73224,"date":"2013-09-16T18:44:50","date_gmt":"2013-09-16T18:44:50","guid":{"rendered":"https:\/\/www.red-gate.com\/simple-talk\/uncategorized\/protecting-your-changes-when-working-in-a-shared-environment\/"},"modified":"2021-07-14T13:07:38","modified_gmt":"2021-07-14T13:07:38","slug":"protecting-your-changes-when-working-in-a-shared-environment","status":"publish","type":"post","link":"https:\/\/www.red-gate.com\/simple-talk\/databases\/oracle-databases\/protecting-your-changes-when-working-in-a-shared-environment\/","title":{"rendered":"Protecting your changes when working in a shared environment"},"content":{"rendered":"<p>Over the last few months, we&#8217;ve been visiting customers and helping them get up and running with Red Gate tools. Something we&#8217;ve seen over and over is that teams have to avoid stepping on each other\u2019s toes when sharing a database, because there\u2019s a constant risk of accidentally overwriting changes.<\/p>\n<p>A typical scenario goes something like this:<\/p>\n<ol>\n<li>Alice opens a package and starts editing it.<\/li>\n<li>Meanwhile, Bob unwittingly opens the same package, edits it, and saves it.<\/li>\n<li>Alice saves her changes to the package.<\/li>\n<\/ol>\n<p>Presto: Bob\u2019s work is gone. And what\u2019s more, Bob and Alice may not even notice. The error could make it all the way to production. We spoke to one developer who lost a week\u2019s work when their database was deployed without critical changes that had been accidentally overwritten.<\/p>\n<p>There are ways to undo this kind of mistake. Some types of objects can be rescued from the recycle bin, or recovered with backups or source control; if you have Oracle Flashback Technology enabled, you can return PL\/SQL objects to a previous state. None of these methods are comprehensive or reliable, they can be time-consuming, and they depend on the problem being noticed at all.<\/p>\n<p>It\u2019s better to prevent the mistake happening in the first place. To that end, some developers rely on email, IM, or text messages to warn their team when they\u2019re working on something. Others leave comments in the code or use Post-it notes. We\u2019ve even seen people shout across the office. In every case, the solution wasn&#8217;t reliable: Alice had to remember to warn Bob she was working on something, and Bob had to take notice. Some teams have a \u201cplay nice\u201d policy, and plan projects so people don\u2019t end up working on things simultaneously, but that isn&#8217;t ideal, either. It\u2019s basically a communication problem.<\/p>\n<p>With <a title=\"Source Control for Oracle\" href=\"http:\/\/www.red-gate.com\/products\/oracle-development\/source-control-for-oracle\/?utm_source=allthingsoracle&amp;utm_medium=publink&amp;utm_campaign=sourcecontrolfororacle&amp;utm_content=svn-ebook\">Source Control for Oracle 2<\/a>, you can lock database objects before you start work on them and leave a comment explaining what you\u2019re doing. Then you can carry on working normally without worrying about someone else overwriting your work. If someone goes to edit the locked object, the server returns an error with your comment, so they know what\u2019s going on.<\/p>\n<p>You can set up the Red Gate schema from the Lock objects tab in Source Control for Oracle. The tool runs a script to create a Red Gate schema on your database; <a href=\"http:\/\/documentation.red-gate.com\/display\/SOCO1\/Setting+up+object+locking\">it\u2019s all transparent, so you can review the script and see exactly what\u2019s going on<\/a>. Afterwards, the tab shows which objects are currently locked (by you or other people). You can see who locked the object, when they locked it, and how recently it was edited. The locking functionality works for every project connected to the database.<\/p>\n<p><a href=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/oracle\/2013\/09\/locking-objects-on-shared-oracle-database.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-4605\" alt=\"Screenshot: Locking objects on a shared oracle database\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/oracle\/2013\/09\/locking-objects-on-shared-oracle-database-1024x545.png\" width=\"585\" height=\"311\" srcset=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/oracle\/2013\/09\/locking-objects-on-shared-oracle-database-1024x545.png 1024w, https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/oracle\/2013\/09\/locking-objects-on-shared-oracle-database-300x159.png 300w, https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/oracle\/2013\/09\/locking-objects-on-shared-oracle-database.png 1366w\" sizes=\"auto, (max-width: 585px) 100vw, 585px\" \/><\/a><\/p>\n<p>When someone locks an object, information about who locked it is stored in the <i>locked_objects<\/i> table along with their comment. When anyone executes some DDL, a system-level trigger checks they have permission to edit the referenced object. If that person locked the object themselves, they can edit it as normal. Everyone else will see an error, even if they\u2019re signed in as the same Oracle user. The error contains the comment left by the person who locked it.<\/p>\n<p><a href=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/oracle\/2013\/09\/oracle-locked-object-error.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4606\" alt=\"Screenshot: Oracle locked object error\" src=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/oracle\/2013\/09\/oracle-locked-object-error.png\" width=\"768\" height=\"230\" srcset=\"https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/oracle\/2013\/09\/oracle-locked-object-error.png 768w, https:\/\/www.red-gate.com\/simple-talk\/wp-content\/uploads\/oracle\/2013\/09\/oracle-locked-object-error-300x89.png 300w\" sizes=\"auto, (max-width: 768px) 100vw, 768px\" \/><\/a><\/p>\n<p>It\u2019s not totally draconian. You can still unlock other people\u2019s objects if they\u2019re off sick or on vacation or taking an extended lunch break, or if you\u2019re just feeling mischievous. We see the locking feature as a communication tool to replace the emails and Post-its. The difference is that it\u2019s easy to communicate, and impossible to miss.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Over the last few months, we&#8217;ve been visiting customers and helping them get up and running with Red Gate tools. Something we&#8217;ve seen over and over is that teams have to avoid stepping on each other\u2019s toes when sharing a database, because there\u2019s a constant risk of accidentally overwriting changes. A typical scenario goes something like this: Alice opens a&hellip;<\/p>\n","protected":false},"author":316209,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[143533],"tags":[],"coauthors":[],"class_list":["post-73224","post","type-post","status-publish","format-standard","hentry","category-oracle-databases"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/73224","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/users\/316209"}],"replies":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/comments?post=73224"}],"version-history":[{"count":1,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/73224\/revisions"}],"predecessor-version":[{"id":91707,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/73224\/revisions\/91707"}],"wp:attachment":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/media?parent=73224"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/categories?post=73224"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/tags?post=73224"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/coauthors?post=73224"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}