{"id":11578,"date":"2018-08-20T15:07:22","date_gmt":"2018-08-20T13:07:22","guid":{"rendered":"https:\/\/www.dbi-services.com\/blog\/running-plsql-as-sysdba-through-definer-rights\/"},"modified":"2018-08-20T15:07:22","modified_gmt":"2018-08-20T13:07:22","slug":"running-plsql-as-sysdba-through-definer-rights","status":"publish","type":"post","link":"https:\/\/www.dbi-services.com\/blog\/running-plsql-as-sysdba-through-definer-rights\/","title":{"rendered":"Running PLSQL as SYSDBA through DEFINER-rights?"},"content":{"rendered":"<p>Recently I got an interesting request: The customer wanted to allow the application installation routine to create a guaranteed restore point without giving it all required privileges to do so. So the idea was to encapsulate creating and dropping a guaranteed restore point in a PLSQL package and granting the application owner the permission to execute the package. The problem with that approach is that SYSDBA-privileges are required to create a guaranteed restore point and the question came up if it is actually possible to have a PLSQL package created with DEFINER-rights, where the DEFINER has the SYSDBA-privilege? Actually that is not possible, because you have to be connected &#8220;AS SYSDBA&#8221; to have the SYSDBA-privilege. A package created from a user, who connected as SYSDBA does not inherit the SYSDBA-privilege as the following example shows:<\/p>\n<p><code><br \/>\nsqlplus \/ as sysdba<br \/>\n&nbsp;<br \/>\ncreate user dbadmin identified by dbadmin;<br \/>\ngrant sysdba to dbadmin;<br \/>\ncreate user appluser identified by appluser;<br \/>\ngrant create session to appluser;<br \/>\nconnect dbadmin\/dbadmin as sysdba<br \/>\n&nbsp;<br \/>\ncreate or replace package grp_handling as<br \/>\n   procedure create_grp;<br \/>\n   procedure drop_grp;<br \/>\nend;<br \/>\n\/<br \/>\n&nbsp;<br \/>\ncreate or replace package body grp_handling as<br \/>\nprocedure create_grp<br \/>\nas<br \/>\nbegin<br \/>\n   begin<br \/>\n      execute immediate 'drop restore point before_appl_installation';<br \/>\n   exception<br \/>\n      when others then null;<br \/>\n   end;<br \/>\n   execute immediate 'create restore point before_appl_installation guarantee flashback database';<br \/>\nend;<br \/>\nprocedure drop_grp<br \/>\nas<br \/>\nbegin<br \/>\n   execute immediate 'drop restore point before_appl_installation';<br \/>\nend;<br \/>\nend;<br \/>\n\/<br \/>\n&nbsp;<br \/>\nexec grp_handling.create_grp;<br \/>\n&nbsp;<br \/>\nPL\/SQL procedure successfully completed.<br \/>\n&nbsp;<br \/>\nselect name from v$restore_point;<br \/>\n&nbsp;<br \/>\nNAME<br \/>\n----------------------------------------------<br \/>\nBEFORE_APPL_INSTALLATION<br \/>\n&nbsp;<br \/>\nselect owner,object_type from dba_objects where object_name='GRP_HANDLING';<br \/>\n&nbsp;<br \/>\nOWNER                          OBJECT_TYPE<br \/>\n------------------------------ -----------------------<br \/>\nSYS                            PACKAGE<br \/>\nSYS                            PACKAGE BODY<br \/>\n&nbsp;<br \/>\nselect user from dual;<br \/>\n&nbsp;<br \/>\nUSER<br \/>\n------------------------------<br \/>\nSYS<br \/>\n&nbsp;<br \/>\ngrant execute on grp_handling to appluser;<br \/>\n&nbsp;<br \/>\nconnect appluser\/appluser<br \/>\nexec sys.grp_handling.create_grp;<br \/>\n&nbsp;<br \/>\n*<br \/>\nERROR at line 1:<br \/>\nORA-01031: insufficient privileges<br \/>\nORA-06512: at \"SYS.GRP_HANDLING\", line 10<br \/>\nORA-06512: at line 1<br \/>\n<\/code><\/p>\n<p>So first of all a user, who connects &#8220;AS SYSDBA&#8221; actually connects as SYS. Secondly the SYSDBA-privilege is not inherited as a DEFINER-right in PLSQL-objects.<\/p>\n<p>So how to resolve the issue to create a guaranteed restore point from the appluser-Session then?<br \/>\nI suggested to wrap a dbms_scheduler-external callout in a Package as follows:<\/p>\n<p>1.) Create the bash-Skript \/home\/oracle\/GRP\/cre_grp.bash as OS-User oracle<\/p>\n<p><code><br \/>\n#!\/bin\/bash<br \/>\n. oraenv &lt;&lt;EOF<br \/>\nprem122<br \/>\nEOF<br \/>\n&nbsp;<br \/>\nsqlplus \/ as sysdba &lt;&lt;EOF<br \/>\nbegin<br \/>\n   execute immediate &#039;drop restore point before_appl_installation&#039;;<br \/>\nexception<br \/>\n   when others then null;<br \/>\nend;<br \/>\n\/<br \/>\ncreate restore point before_appl_installation guarantee flashback database;<br \/>\nexit<br \/>\nEOF<br \/>\n<\/code><\/p>\n<p>&#8211;&gt; Add execute permissions for the user: chmod u+x \/home\/oracle\/GRP\/cre_grp.bash<\/p>\n<p>2.) Create credential and job<\/p>\n<p><code><br \/>\nconnect dbadmin as sysdba<br \/>\nBEGIN<br \/>\n  DBMS_CREDENTIAL.create_credential(<br \/>\n    credential_name =&gt; 'oracle_122',<br \/>\n    username        =&gt; 'oracle',<br \/>\n    password        =&gt; '&#060;passwd OS-user oracle&#062;'<br \/>\n  );<br \/>\nEND;<br \/>\n\/<br \/>\n&nbsp;<br \/>\nBEGIN<br \/>\n   dbms_scheduler.CREATE_job<br \/>\n   (<br \/>\n      job_name =&gt; 'CRE_GUARANTEED_RP',<br \/>\n      job_type =&gt; 'EXECUTABLE',<br \/>\n      job_action =&gt; '\/home\/oracle\/GRP\/cre_grp.bash',<br \/>\n      enabled =&gt; true,<br \/>\n      auto_drop =&gt; false,<br \/>\n      credential_name =&gt; 'oracle_122'<br \/>\n   );<br \/>\nEND;<br \/>\n\/<br \/>\n<\/code><\/p>\n<p>3.) Create a procedure to run the Job<\/p>\n<p><code><br \/>\nconnect dbadmin as sysdba<br \/>\ncreate procedure run_my_GRP_job<br \/>\nas<br \/>\nbegin<br \/>\n     dbms_scheduler.run_job('CRE_GUARANTEED_RP');<br \/>\nend;<br \/>\n\/<br \/>\n&nbsp;<br \/>\ngrant execute on run_my_GRP_job to appluser;<br \/>\n<\/code><\/p>\n<p>4.) Now the appluser can run the job:<\/p>\n<p><code><br \/>\nconnect appluser<br \/>\nexec sys.run_my_GRP_job;<br \/>\n<\/code><\/p>\n<p>Conclusion: You cannot provide SYSDBA-privileges through DEFINER-rights in PLSQL. In case you have to run PLSQL &#8220;AS SYSDBA&#8221; then you have to connect &#8220;AS SYSDBA&#8221;. Running SYSDBA-commands as a non-SYSDBA-user is possible with a workaround like through a procedure, which runs an external job.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently I got an interesting request: The customer wanted to allow the application installation routine to create a guaranteed restore point without giving it all required privileges to do so. So the idea was to encapsulate creating and dropping a guaranteed restore point in a PLSQL package and granting the application owner the permission to [&hellip;]<\/p>\n","protected":false},"author":35,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[229,198,59],"tags":[1437,96,1438],"type_dbi":[],"class_list":["post-11578","post","type-post","status-publish","format-standard","hentry","category-database-administration-monitoring","category-database-management","category-oracle","tag-definer-rights","tag-oracle","tag-sysdba"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.2 (Yoast SEO v27.2) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Running PLSQL as SYSDBA through DEFINER-rights? - dbi Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.dbi-services.com\/blog\/running-plsql-as-sysdba-through-definer-rights\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Running PLSQL as SYSDBA through DEFINER-rights?\" \/>\n<meta property=\"og:description\" content=\"Recently I got an interesting request: The customer wanted to allow the application installation routine to create a guaranteed restore point without giving it all required privileges to do so. So the idea was to encapsulate creating and dropping a guaranteed restore point in a PLSQL package and granting the application owner the permission to [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.dbi-services.com\/blog\/running-plsql-as-sysdba-through-definer-rights\/\" \/>\n<meta property=\"og:site_name\" content=\"dbi Blog\" \/>\n<meta property=\"article:published_time\" content=\"2018-08-20T13:07:22+00:00\" \/>\n<meta name=\"author\" content=\"Clemens Bleile\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@ifgtxD2SrQ8r!YuXj\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Clemens Bleile\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/running-plsql-as-sysdba-through-definer-rights\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/running-plsql-as-sysdba-through-definer-rights\/\"},\"author\":{\"name\":\"Clemens Bleile\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/0ac04011f60f2e93c115358d0789c2da\"},\"headline\":\"Running PLSQL as SYSDBA through DEFINER-rights?\",\"datePublished\":\"2018-08-20T13:07:22+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/running-plsql-as-sysdba-through-definer-rights\/\"},\"wordCount\":286,\"commentCount\":0,\"keywords\":[\"DEFINER-RIGHTS\",\"Oracle\",\"SYSDBA\"],\"articleSection\":[\"Database Administration &amp; Monitoring\",\"Database management\",\"Oracle\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/running-plsql-as-sysdba-through-definer-rights\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/running-plsql-as-sysdba-through-definer-rights\/\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/running-plsql-as-sysdba-through-definer-rights\/\",\"name\":\"Running PLSQL as SYSDBA through DEFINER-rights? - dbi Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\"},\"datePublished\":\"2018-08-20T13:07:22+00:00\",\"author\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/0ac04011f60f2e93c115358d0789c2da\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/running-plsql-as-sysdba-through-definer-rights\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/running-plsql-as-sysdba-through-definer-rights\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/running-plsql-as-sysdba-through-definer-rights\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Accueil\",\"item\":\"https:\/\/www.dbi-services.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Running PLSQL as SYSDBA through DEFINER-rights?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/\",\"name\":\"dbi Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/0ac04011f60f2e93c115358d0789c2da\",\"name\":\"Clemens Bleile\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/1f596609fc67cb28ed714e7bccc81ed4cd73b8582a8148a490c77daeb2fde21a?s=96&d=mm&r=g\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/1f596609fc67cb28ed714e7bccc81ed4cd73b8582a8148a490c77daeb2fde21a?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/1f596609fc67cb28ed714e7bccc81ed4cd73b8582a8148a490c77daeb2fde21a?s=96&d=mm&r=g\",\"caption\":\"Clemens Bleile\"},\"description\":\"Clemens Bleile has more than 30 years of IT experience, thirteen in Oracle Support and fifteen in Oracle Consulting. He is specialized in Oracle Database Performance Tuning (SQL Tuning, DB Tuning) and developing an Oracle DB IT architecture (highly available, low-maintenance, cost efficient storage of data). He is an expert in problem analysis and resolution. Prior to joining dbi services, Clemens Bleile was Manager of the EMEA Database Performance team at the Oracle Global Customer Support Services. Clemens Bleile is Oracle Certified Professional 11g, 12c and Oracle Certified Expert for Performance Management and Tuning and holds a Master Degree, Business Information Systems from the Fachhochschule Furtwangen, Germany.\",\"sameAs\":[\"https:\/\/www.dbi-services.com\",\"https:\/\/x.com\/ifgtxD2SrQ8r!YuXj\"],\"url\":\"https:\/\/www.dbi-services.com\/blog\/author\/clemens-bleile\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Running PLSQL as SYSDBA through DEFINER-rights? - dbi Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.dbi-services.com\/blog\/running-plsql-as-sysdba-through-definer-rights\/","og_locale":"en_US","og_type":"article","og_title":"Running PLSQL as SYSDBA through DEFINER-rights?","og_description":"Recently I got an interesting request: The customer wanted to allow the application installation routine to create a guaranteed restore point without giving it all required privileges to do so. So the idea was to encapsulate creating and dropping a guaranteed restore point in a PLSQL package and granting the application owner the permission to [&hellip;]","og_url":"https:\/\/www.dbi-services.com\/blog\/running-plsql-as-sysdba-through-definer-rights\/","og_site_name":"dbi Blog","article_published_time":"2018-08-20T13:07:22+00:00","author":"Clemens Bleile","twitter_card":"summary_large_image","twitter_creator":"@ifgtxD2SrQ8r!YuXj","twitter_misc":{"Written by":"Clemens Bleile","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.dbi-services.com\/blog\/running-plsql-as-sysdba-through-definer-rights\/#article","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/running-plsql-as-sysdba-through-definer-rights\/"},"author":{"name":"Clemens Bleile","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/0ac04011f60f2e93c115358d0789c2da"},"headline":"Running PLSQL as SYSDBA through DEFINER-rights?","datePublished":"2018-08-20T13:07:22+00:00","mainEntityOfPage":{"@id":"https:\/\/www.dbi-services.com\/blog\/running-plsql-as-sysdba-through-definer-rights\/"},"wordCount":286,"commentCount":0,"keywords":["DEFINER-RIGHTS","Oracle","SYSDBA"],"articleSection":["Database Administration &amp; Monitoring","Database management","Oracle"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.dbi-services.com\/blog\/running-plsql-as-sysdba-through-definer-rights\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.dbi-services.com\/blog\/running-plsql-as-sysdba-through-definer-rights\/","url":"https:\/\/www.dbi-services.com\/blog\/running-plsql-as-sysdba-through-definer-rights\/","name":"Running PLSQL as SYSDBA through DEFINER-rights? - dbi Blog","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/#website"},"datePublished":"2018-08-20T13:07:22+00:00","author":{"@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/0ac04011f60f2e93c115358d0789c2da"},"breadcrumb":{"@id":"https:\/\/www.dbi-services.com\/blog\/running-plsql-as-sysdba-through-definer-rights\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.dbi-services.com\/blog\/running-plsql-as-sysdba-through-definer-rights\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.dbi-services.com\/blog\/running-plsql-as-sysdba-through-definer-rights\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Accueil","item":"https:\/\/www.dbi-services.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Running PLSQL as SYSDBA through DEFINER-rights?"}]},{"@type":"WebSite","@id":"https:\/\/www.dbi-services.com\/blog\/#website","url":"https:\/\/www.dbi-services.com\/blog\/","name":"dbi Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.dbi-services.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/0ac04011f60f2e93c115358d0789c2da","name":"Clemens Bleile","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/1f596609fc67cb28ed714e7bccc81ed4cd73b8582a8148a490c77daeb2fde21a?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/1f596609fc67cb28ed714e7bccc81ed4cd73b8582a8148a490c77daeb2fde21a?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/1f596609fc67cb28ed714e7bccc81ed4cd73b8582a8148a490c77daeb2fde21a?s=96&d=mm&r=g","caption":"Clemens Bleile"},"description":"Clemens Bleile has more than 30 years of IT experience, thirteen in Oracle Support and fifteen in Oracle Consulting. He is specialized in Oracle Database Performance Tuning (SQL Tuning, DB Tuning) and developing an Oracle DB IT architecture (highly available, low-maintenance, cost efficient storage of data). He is an expert in problem analysis and resolution. Prior to joining dbi services, Clemens Bleile was Manager of the EMEA Database Performance team at the Oracle Global Customer Support Services. Clemens Bleile is Oracle Certified Professional 11g, 12c and Oracle Certified Expert for Performance Management and Tuning and holds a Master Degree, Business Information Systems from the Fachhochschule Furtwangen, Germany.","sameAs":["https:\/\/www.dbi-services.com","https:\/\/x.com\/ifgtxD2SrQ8r!YuXj"],"url":"https:\/\/www.dbi-services.com\/blog\/author\/clemens-bleile\/"}]}},"_links":{"self":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/11578","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/users\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/comments?post=11578"}],"version-history":[{"count":0,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/11578\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/media?parent=11578"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/categories?post=11578"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/tags?post=11578"},{"taxonomy":"type","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/type_dbi?post=11578"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}