{"id":3869,"date":"2021-07-15T16:23:05","date_gmt":"2021-07-15T16:23:05","guid":{"rendered":"https:\/\/nenadnoveljic.com\/blog\/?p=3869"},"modified":"2021-07-15T16:23:08","modified_gmt":"2021-07-15T16:23:08","slug":"minimum-sga_target","status":"publish","type":"post","link":"https:\/\/nenadnoveljic.com\/blog\/minimum-sga_target\/","title":{"rendered":"Minimum sga_target"},"content":{"rendered":"<p>We occasionally got the following error message when attempting to start the databases after a hardware change or during a database upgrade:<\/p>\n<pre><code>ORA-00821: Specified value of sga_target 4096M is too small, needs to be at least 4352M<\/code><\/pre>\n<p>We immediately resolved the issue by increasing sga_target, but couldn&#8217;t explain the root cause.<\/p>\n<p>Obviously, the hardware configuration has an impact on the minimum sga_target calculation, and the limit usually changes with a new database release.<\/p>\n<p>Unfortunately, this calculation isn&#8217;t documented. And yet it would be extremely useful to anticipate the new limit and avoid unpleasant suprises.<\/p>\n<p>I asked for information on <a href=\"https:\/\/www.freelists.org\/post\/oracle-l\/minimal-sga-target\">Oracle-l<\/a>.<\/p>\n<p><a href=\"https:\/\/jonathanlewis.wordpress.com\/\">Jonathan Lewis<\/a> said that the calculation <a href=\"https:\/\/www.freelists.org\/post\/oracle-l\/minimal-sga-target,2\">depends on the database parameter cpu_count<\/a>. <a href=\"http:\/\/orasql.org\/\">Sayan Malakshinov<\/a> <a href=\"https:\/\/www.freelists.org\/post\/oracle-l\/minimal-sga-target,1\">mentioned the processes parameter<\/a>.<\/p>\n<p>I setup an experiment to measure how the minimum sga_sarget depends on both values.<\/p>\n<h1>Experiment<\/h1>\n<p>After backing up the spfile, I was repeating the following process with different parameter values:<\/p>\n<ol>\n<li>set sga_target to 100M<\/li>\n<li>adjust the parameter of interest<\/li>\n<li>stop the database<\/li>\n<li>try to start the database (it will fail.)<\/li>\n<li>get the new limit from the error message<\/li>\n<li>restore the correct spfile<\/li>\n<\/ol>\n<p>I semi-automated the testing with the code snippet below:<\/p>\n<p>Backup spfile (only once):<\/p>\n<pre><code>cp spfileDB.ora spfileDB.ora.bak<\/code><\/pre>\n<p>Change cpu_count (or any other parameter) with every execution:<\/p>\n<pre><code>alter system set cpu_count=192 scope=spfile ;\nalter system set sga_target=100M scope=spfile ;\nshutdown abort\nstartup\n\n! cp spfileDB.ora.bak spfileDB.ora\nshutdown abort\nstartup<\/code><\/pre>\n<h1>Model<\/h1>\n<p>After reducing cpu_count from 120 to 60, the minimum sga_target approximately halved.<\/p>\n<p>In contrast, the parameter processes had a neglectable impact on the requirement.<\/p>\n<p>Since the dependency on cpu_count is linear, and cpu_count is the main contributor, we can approximate all other dependencies with a constant C:<\/p>\n<p>min_sga_target = k * cpu_count + C<\/p>\n<p>After completing experiments with two different cpu_count values we can find k (slope) and C (y intercept) by solving the system of two linear equations, for example:<\/p>\n<p>cpu_count = 120, min_sga_target =  2576M<br \/>\ncpu_count = 60, min_sga_target = 1348M<\/p>\n<p>k = 20.47M , C = 120M<\/p>\n<p>We can verify this calculation by picking a third value, calculating it and comparing with reality:<\/p>\n<p>cpu_count = 30, min_sga_target = 734M<\/p>\n<pre><code>ORA-00821: Specified value of sga_target 100M is too small, needs to be at least 764M<\/code><\/pre>\n<p>As we can see, the calculation is reliable. We can use it to predict the new minimum sga_target after adding more CPUs.<\/p>\n<h1>Bounds<\/h1>\n<p>The extrapolation works for the following cpu_count values:<\/p>\n<p>1 &lt;&lt; cpu_count &lt; #cpu<\/p>\n<p>In other words, cpu_count has to be siginficantly greater than 1 and lower or equal than the number of CPU threads on the server. Simply put, we&#8217;re looking at large servers.<\/p>\n<h2>Lower bound<\/h2>\n<p>Fow a low cpu_count the dependency becomes non-linear, as there are some minimal requirements for sga_target, for example for cpu_count=4<\/p>\n<pre><code>ORA-00821: Specified value of sga_target 100M is too small, needs to be at least 296M<\/code><\/pre>\n<p>But that&#8217;s irrelevant, because the theoretical value for minimum sga_target for a low cpu_count is so small that it&#8217;s unfit for the real world.<\/p>\n<h2>Upper bound<\/h2>\n<p>Minimum sga_target doesn&#8217;t grow anymore after increasing cpu_count above the total number of CPUs.<\/p>\n<p>For example, for cpu_count=192<\/p>\n<pre><code>ORA-00821: Specified value of sga_target 100M is too small, needs to be at least 2576M<\/code><\/pre>\n<h1>Risks<\/h1>\n<h2>Hardware and OS changes<\/h2>\n<p>Adding more CPUs to the server increases the minimum sga_target requirement, which can prevent the restart of the databases that suddenly come below the new limit.<\/p>\n<p>Notice that the database sees hyperthreads as CPUs, so adding virtual CPUs or turning on hyperthreading can also lead to the problem.<\/p>\n<p>Or if your test server has less CPUs, some problems might only appear in production.<\/p>\n<h2>Oracle upgrades<\/h2>\n<p>Here are slope and y intercept values for 19.10.0.0.210119 in MB: k = 20.46 , C = 120<\/p>\n<p>Let&#8217;s compare them with 12.2.0.1.180116: k = 8.47, C = 124<\/p>\n<p>The minimum sga_target is 2.4 time higher in 19c than in 12c.<\/p>\n<h1>Monitoring<\/h1>\n<p>After becoming aware of the risk, we started monitoring sga_target with the following Perl code:<\/p>\n<pre><code>  sub get_min_sga_target {\n    my ($self) = shift @_ ;\n    \n    my $cpu_count = $self-&gt;get_spfile_parameter('cpu_count') ;\n    \n    return $cpu_count * 21 * 1024 ** 2 + 1024 ** 3 ;\n  }<\/code><\/pre>\n<pre><code>use Number::Format qw( format_bytes ) ;\nsub exec_check{\n  my $db_obj = shift @_ ;\n\n  my $sga_target = $db_obj-&gt;get_spfile_parameter('sga_target') ;  \n  \n  my $min_sga_target = $db_obj-&gt;get_min_sga_target() ; \n\n  my $return_code = ( $sga_target &lt; $min_sga_target ) ? 1 : 0 ;\n  \n  $sga_target = format_bytes( $sga_target, unit =&gt; 'G' ) ;\n  $min_sga_target = format_bytes( $min_sga_target, unit =&gt; 'G' ) ;\n  \n  my $message \n    = \"sga_target: $sga_target, minimum: $min_sga_target\" ;\n\n  return { return_code =&gt; $return_code , message =&gt; $message } ;  \n}<\/code><\/pre>\n<h1>Conclusion<\/h1>\n<p>In conclusion, minimum sga_target largely depends on cpu_count. Consequently, database start might fail after adding CPUs. This includes virtual CPUs and hyperthreads as well.<\/p>\n<p>The limit changes with every database release, so an upgrade can fail for databases with a smaller SGA. Also, a database upgrade that you tested on a server with much less CPUs might fail in production.<\/p>\n<p>I provided the methodology to anticipate problems and monitor critical conditions.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Database won&#8217;t start after a hardware\/OS change or a database upgrade?<\/p>\n<p>You can monitor critical conditions and prevent unpleasant surprises. <a href=\"https:\/\/nenadnoveljic.com\/blog\/minimum-sga_target\/\" class=\"more-link\">Continue Reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[5],"tags":[],"class_list":["post-3869","post","type-post","status-publish","format-standard","hentry","category-oracle"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Minimum sga_target - All-round Database Topics<\/title>\n<meta name=\"description\" content=\"Database won&#039;t start after a hardware\/OS change or a database upgrade?You can monitor critical conditions and prevent unpleasant surprises.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/nenadnoveljic.com\/blog\/minimum-sga_target\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Minimum sga_target - All-round Database Topics\" \/>\n<meta property=\"og:description\" content=\"Database won&#039;t start after a hardware\/OS change or a database upgrade?You can monitor critical conditions and prevent unpleasant surprises.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/nenadnoveljic.com\/blog\/minimum-sga_target\/\" \/>\n<meta property=\"og:site_name\" content=\"All-round Database Topics\" \/>\n<meta property=\"article:published_time\" content=\"2021-07-15T16:23:05+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-07-15T16:23:08+00:00\" \/>\n<meta name=\"author\" content=\"Nenad Noveljic\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@NenadNoveljic\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Nenad Noveljic\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/minimum-sga_target\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/minimum-sga_target\\\/\"},\"author\":{\"name\":\"Nenad Noveljic\",\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/#\\\/schema\\\/person\\\/51458d9dd86dbbdd19f5add451d44efa\"},\"headline\":\"Minimum sga_target\",\"datePublished\":\"2021-07-15T16:23:05+00:00\",\"dateModified\":\"2021-07-15T16:23:08+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/minimum-sga_target\\\/\"},\"wordCount\":662,\"commentCount\":4,\"articleSection\":[\"Oracle\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/minimum-sga_target\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/minimum-sga_target\\\/\",\"url\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/minimum-sga_target\\\/\",\"name\":\"Minimum sga_target - All-round Database Topics\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/#website\"},\"datePublished\":\"2021-07-15T16:23:05+00:00\",\"dateModified\":\"2021-07-15T16:23:08+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/#\\\/schema\\\/person\\\/51458d9dd86dbbdd19f5add451d44efa\"},\"description\":\"Database won't start after a hardware\\\/OS change or a database upgrade?You can monitor critical conditions and prevent unpleasant surprises.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/minimum-sga_target\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/minimum-sga_target\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/minimum-sga_target\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Minimum sga_target\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/\",\"name\":\"All-round Database Topics\",\"description\":\"Nenad Noveljic\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/#\\\/schema\\\/person\\\/51458d9dd86dbbdd19f5add451d44efa\",\"name\":\"Nenad Noveljic\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a97b796613ea48ec8a7b79c8ffe1c685dcffc920c68121f6238d5caab5070670?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a97b796613ea48ec8a7b79c8ffe1c685dcffc920c68121f6238d5caab5070670?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a97b796613ea48ec8a7b79c8ffe1c685dcffc920c68121f6238d5caab5070670?s=96&d=mm&r=g\",\"caption\":\"Nenad Noveljic\"},\"sameAs\":[\"nenad-noveljic-9b746a6\",\"https:\\\/\\\/x.com\\\/NenadNoveljic\"],\"url\":\"https:\\\/\\\/nenadnoveljic.com\\\/blog\\\/author\\\/nenad\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Minimum sga_target - All-round Database Topics","description":"Database won't start after a hardware\/OS change or a database upgrade?You can monitor critical conditions and prevent unpleasant surprises.","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:\/\/nenadnoveljic.com\/blog\/minimum-sga_target\/","og_locale":"en_US","og_type":"article","og_title":"Minimum sga_target - All-round Database Topics","og_description":"Database won't start after a hardware\/OS change or a database upgrade?You can monitor critical conditions and prevent unpleasant surprises.","og_url":"https:\/\/nenadnoveljic.com\/blog\/minimum-sga_target\/","og_site_name":"All-round Database Topics","article_published_time":"2021-07-15T16:23:05+00:00","article_modified_time":"2021-07-15T16:23:08+00:00","author":"Nenad Noveljic","twitter_card":"summary_large_image","twitter_creator":"@NenadNoveljic","twitter_misc":{"Written by":"Nenad Noveljic","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/nenadnoveljic.com\/blog\/minimum-sga_target\/#article","isPartOf":{"@id":"https:\/\/nenadnoveljic.com\/blog\/minimum-sga_target\/"},"author":{"name":"Nenad Noveljic","@id":"https:\/\/nenadnoveljic.com\/blog\/#\/schema\/person\/51458d9dd86dbbdd19f5add451d44efa"},"headline":"Minimum sga_target","datePublished":"2021-07-15T16:23:05+00:00","dateModified":"2021-07-15T16:23:08+00:00","mainEntityOfPage":{"@id":"https:\/\/nenadnoveljic.com\/blog\/minimum-sga_target\/"},"wordCount":662,"commentCount":4,"articleSection":["Oracle"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/nenadnoveljic.com\/blog\/minimum-sga_target\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/nenadnoveljic.com\/blog\/minimum-sga_target\/","url":"https:\/\/nenadnoveljic.com\/blog\/minimum-sga_target\/","name":"Minimum sga_target - All-round Database Topics","isPartOf":{"@id":"https:\/\/nenadnoveljic.com\/blog\/#website"},"datePublished":"2021-07-15T16:23:05+00:00","dateModified":"2021-07-15T16:23:08+00:00","author":{"@id":"https:\/\/nenadnoveljic.com\/blog\/#\/schema\/person\/51458d9dd86dbbdd19f5add451d44efa"},"description":"Database won't start after a hardware\/OS change or a database upgrade?You can monitor critical conditions and prevent unpleasant surprises.","breadcrumb":{"@id":"https:\/\/nenadnoveljic.com\/blog\/minimum-sga_target\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/nenadnoveljic.com\/blog\/minimum-sga_target\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/nenadnoveljic.com\/blog\/minimum-sga_target\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/nenadnoveljic.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Minimum sga_target"}]},{"@type":"WebSite","@id":"https:\/\/nenadnoveljic.com\/blog\/#website","url":"https:\/\/nenadnoveljic.com\/blog\/","name":"All-round Database Topics","description":"Nenad Noveljic","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/nenadnoveljic.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/nenadnoveljic.com\/blog\/#\/schema\/person\/51458d9dd86dbbdd19f5add451d44efa","name":"Nenad Noveljic","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/a97b796613ea48ec8a7b79c8ffe1c685dcffc920c68121f6238d5caab5070670?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/a97b796613ea48ec8a7b79c8ffe1c685dcffc920c68121f6238d5caab5070670?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/a97b796613ea48ec8a7b79c8ffe1c685dcffc920c68121f6238d5caab5070670?s=96&d=mm&r=g","caption":"Nenad Noveljic"},"sameAs":["nenad-noveljic-9b746a6","https:\/\/x.com\/NenadNoveljic"],"url":"https:\/\/nenadnoveljic.com\/blog\/author\/nenad\/"}]}},"_links":{"self":[{"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/posts\/3869","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/comments?post=3869"}],"version-history":[{"count":1,"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/posts\/3869\/revisions"}],"predecessor-version":[{"id":3874,"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/posts\/3869\/revisions\/3874"}],"wp:attachment":[{"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/media?parent=3869"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/categories?post=3869"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nenadnoveljic.com\/blog\/wp-json\/wp\/v2\/tags?post=3869"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}