{"id":2012,"date":"2021-05-20T11:47:49","date_gmt":"2021-05-20T15:47:49","guid":{"rendered":"https:\/\/shirishranjit.com\/blog1\/?page_id=2012"},"modified":"2021-05-20T11:47:50","modified_gmt":"2021-05-20T15:47:50","slug":"postgresql-upgrade-how-to","status":"publish","type":"page","link":"https:\/\/shirishranjit.com\/blog1\/technical-posts\/postgres-database-cheatsheet\/postgresql-upgrade-how-to","title":{"rendered":"Postgresql Upgrade &#8211; How To"},"content":{"rendered":"\n<p>Postgresql is a popular and powerful RDBMS. It is easy to use and has powerful RDBMS features. <\/p>\n\n\n\n<p>Postgresql has good documentation which are more general and does not have step by step playbook for upgrade. Following is the step by step to upgrade. You can upgrade from lower version to higher version without issue. <\/p>\n\n\n\n<p>Assumptions for this step by step:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>You have postgresql 9.5 and 10 and 12 are installed.<\/li><li>When you do  <strong><span style=\"color:#7e6ea6\" class=\"has-inline-color\">ps -ef |grep post<\/span><\/strong> -> you see 3 processes with 9, 10 and 12<\/li><li>Postgresql is installed as service<\/li><\/ul>\n\n\n\n<p>Step 1 &#8211; Stop the Postgres service<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>service postgresql stop\n\nps -ef |grep post -> &#91;should not see any process]<\/code><\/pre>\n\n\n\n<p>Step 2 &#8211; Drop new version to ensure there is nothing new <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pg_dropcluster --stop 10 main\npg_dropcluster --stop 12 main<\/code><\/pre>\n\n\n\n<p>Step 3 &#8211; Run upgrade scripts &#8211; this will upgrade to the latest version &#8211; in this case to version 12 and will skip version 10<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pg_upgradecluster -m upgrade 9.5 main\n\nThis will output upgrade logs. Read through the logs and there are commands for your references. Read through it make sure that there is nothing wrong.<\/code><\/pre>\n\n\n\n<p>Step 4 &#8211; Start up the new version and checkout your database.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pg_ctlcluster 12 main start  <\/code><\/pre>\n\n\n\n<p>Check your database &#8211; login and validate your data before you drop the old database and remove everything. <\/p>\n\n\n\n<p>Step 5 &#8211; Clean up &#8211; remove old data and old installations<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pg_dropcluster 9.5 main<\/code><\/pre>\n\n\n\n<p>This will drop the 9.5 database and related data and cleans up the file system. <\/p>\n\n\n\n<p>Step 6 &#8211; Remove installation &#8211; here the example is for Linux\/Ubuntu<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apt-get autoremove --purge postgresql-9.5\napt-get autoremove --purge postgresql-10<\/code><\/pre>\n\n\n\n<p>Now your system is clean and you are up and running with the latest version of postgresql. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Reference<\/strong>:<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/www.postgresql.org\/docs\/current\/upgrading.html\">https:\/\/www.postgresql.org\/docs\/current\/upgrading.html<\/a><\/li><\/ul>\n<div class=\"twttr_buttons\"><div class=\"twttr_twitter\">\n\t\t\t\t\t<a href=\"http:\/\/twitter.com\/share?text=Postgresql+Upgrade+-+How+To\" class=\"twitter-share-button\" data-via=\"\" data-hashtags=\"\"  data-size=\"default\" data-url=\"https:\/\/shirishranjit.com\/blog1\/technical-posts\/postgres-database-cheatsheet\/postgresql-upgrade-how-to\"  data-related=\"\" target=\"_blank\">Tweet<\/a>\n\t\t\t\t<\/div><div class=\"twttr_followme\">\n\t\t\t\t\t\t<a href=\"https:\/\/twitter.com\/shiranjit\" class=\"twitter-follow-button\" data-size=\"default\"  data-show-screen-name=\"false\"  target=\"_blank\">Follow me<\/a>\n\t\t\t\t\t<\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>Postgresql is a popular and powerful RDBMS. It is easy to use and has powerful RDBMS features. Postgresql has good documentation which are more general and does not have step by step playbook for upgrade. Following is the step by &hellip; <a href=\"https:\/\/shirishranjit.com\/blog1\/technical-posts\/postgres-database-cheatsheet\/postgresql-upgrade-how-to\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"parent":489,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-2012","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/shirishranjit.com\/blog1\/wp-json\/wp\/v2\/pages\/2012"}],"collection":[{"href":"https:\/\/shirishranjit.com\/blog1\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/shirishranjit.com\/blog1\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/shirishranjit.com\/blog1\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/shirishranjit.com\/blog1\/wp-json\/wp\/v2\/comments?post=2012"}],"version-history":[{"count":2,"href":"https:\/\/shirishranjit.com\/blog1\/wp-json\/wp\/v2\/pages\/2012\/revisions"}],"predecessor-version":[{"id":2014,"href":"https:\/\/shirishranjit.com\/blog1\/wp-json\/wp\/v2\/pages\/2012\/revisions\/2014"}],"up":[{"embeddable":true,"href":"https:\/\/shirishranjit.com\/blog1\/wp-json\/wp\/v2\/pages\/489"}],"wp:attachment":[{"href":"https:\/\/shirishranjit.com\/blog1\/wp-json\/wp\/v2\/media?parent=2012"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}