{"id":254,"date":"2024-07-02T08:06:37","date_gmt":"2024-07-02T15:06:37","guid":{"rendered":"https:\/\/www.cmsws.com\/blog\/?p=254"},"modified":"2024-07-07T09:57:37","modified_gmt":"2024-07-07T16:57:37","slug":"postgresql-upgrade-9-6-to-11-or-13","status":"publish","type":"post","link":"https:\/\/www.cmsws.com\/blog\/postgresql-upgrade-9-6-to-11-or-13\/","title":{"rendered":"Upgrade PostgreSQL 11 to 13"},"content":{"rendered":"\n<p>The newer version of Debian 11 comes with PostgreSQL 13.  I have the original PostgreSQL 11 running with all my data.  Now I&#8217;m going to walk through the process of upgrading from PostgreSQL 11 to 13.<\/p><div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 ez-toc-wrap-right counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<span class=\"ez-toc-title-toggle\"><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.cmsws.com\/blog\/postgresql-upgrade-9-6-to-11-or-13\/#Lets_see_whats_going_on\" >Lets see what&#8217;s going on.<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.cmsws.com\/blog\/postgresql-upgrade-9-6-to-11-or-13\/#This_will_show_a_bunch_of_output_about_the_process_of_upgrading_the_DB\" >This will show a bunch of output about the process of upgrading the DB.<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.cmsws.com\/blog\/postgresql-upgrade-9-6-to-11-or-13\/#Lets_see_what_is_running_now\" >Lets see what is running now.<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.cmsws.com\/blog\/postgresql-upgrade-9-6-to-11-or-13\/#Remove_all_old_versions_of_PostgreSQL\" >Remove all old versions of PostgreSQL.<\/a><\/li><\/ul><\/nav><\/div>\n\n\n\n\n<p>Be aware this process will work when upgrading from PostgreSQL 9.6 to 11 or 13.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Lets_see_whats_going_on\"><\/span>Lets see what&#8217;s going on.<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Run pg_lsclusters to see which databases are live and running.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>~$ sudo su - postgres\n~# pg_lsclusters\nVer Cluster Port Status Owner    Data directory               Log file\n11  main    5432 online postgres \/var\/lib\/postgresql\/11\/main  \/var\/log\/postgresql\/postgresql-11-main.log\n13  main    5433 online postgres \/var\/lib\/postgresql\/13\/main  \/var\/log\/postgresql\/postgresql-13-main.log<\/code><\/pre>\n\n\n\n<p>Also, lets double check each instance to make sure where our data truly resides.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>~$ sudo su - postgres\n~# psql --cluster 11\/main\npsql (13.15 (Debian 13.15-0+deb11u1), server 11.22 (Debian 11.22-0+deb10u2))\nType \"help\" for help.\n\npostgres=# \\l\n                                  List of databases\n   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   \n-----------+----------+----------+-------------+-------------+-----------------------\n postgres  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | \n template0 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c\/postgres          +\n           |          |          |             |             | postgres=CTc\/postgres\n template1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c\/postgres          +\n           |          |          |             |             | postgres=CTc\/postgres\n(3 rows)\n\npostgres=# \\q\n~# psql --cluster 13\/main\npsql (13.15 (Debian 13.15-0+deb11u1))\nType \"help\" for help.\n\npostgres=# \\l\n                                  List of databases\n   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   \n-----------+----------+----------+-------------+-------------+-----------------------\n postgres  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | \n template0 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c\/postgres          +\n           |          |          |             |             | postgres=CTc\/postgres\n template1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c\/postgres          +\n           |          |          |             |             | postgres=CTc\/postgres\n(3 rows)\n\npostgres=# \\q<\/code><\/pre>\n\n\n\n<p>Drop the default databases found in the newer PostgreSQL versions.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>~$ sudo su - postgres\n~# pg_dropcluster --stop 13 main<\/code><\/pre>\n\n\n\n<p>Upgrade 11 to 13<\/p>\n\n\n\n<pre id=\"block-830e58fc-4a1d-43e1-8424-b2514bc0b09b\" class=\"wp-block-code\"><code># pg_upgradecluster 11 main<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"This_will_show_a_bunch_of_output_about_the_process_of_upgrading_the_DB\"><\/span>This will show a bunch of output about the process of upgrading the DB.<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>Warning: the cluster will not be running as a systemd service. Consider using systemctl:\n  sudo systemctl start postgresql@13-main\n\nSuccess. Please check that the upgraded cluster works. If it does,\nyou can remove the old cluster with\n    pg_dropcluster 11 main\n\nVer Cluster Port Status Owner    Data directory               Log file\n11  main    5433 down   postgres \/var\/lib\/postgresql\/11\/main  \/var\/log\/postgresql\/postgresql-11-main.log\nVer Cluster Port Status Owner    Data directory              Log file\n13  main    5432 online postgres \/var\/lib\/postgresql\/13\/main \/var\/log\/postgresql\/postgresql-13-main.log<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Lets_see_what_is_running_now\"><\/span>Lets see what is running now.<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<pre id=\"block-830e58fc-4a1d-43e1-8424-b2514bc0b09b\" class=\"wp-block-code\"><code>$ pg_lsclusters \nVer Cluster Port Status Owner    Data directory               Log file\n11  main    5433 down   postgres \/var\/lib\/postgresql\/11\/main  \/var\/log\/postgresql\/postgresql-11-main.log\n13  main    5432 online postgres \/var\/lib\/postgresql\/13\/main  \/var\/log\/postgresql\/postgresql-13-main.log<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Remove_all_old_versions_of_PostgreSQL\"><\/span>Remove all old versions of PostgreSQL.<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>$ sudo su - postgres\n$ pg_dropcluster 11 main\n$ pg_lsclusters \nVer Cluster Port Status Owner    Data directory              Log file\n13  main    5432 online postgres \/var\/lib\/postgresql\/13\/main \/var\/log\/postgresql\/postgresql-13-main.log\n$ sudo apt remove postgresql-11 postgresql-client-11<\/code><\/pre>\n\n\n\n<p>Currently PostgreSQL is running as the postgres user, we need to stop the PostgreSQL daemon and start it with the normal system calls.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>~$ sudo su - postgres\n~$ pg_ctlcluster 13 main stop\n~$ \nlogout\n~$ sudo systemctl daemon-reload\n~$ sudo systemctl stop postgresql@11-main\n~$ sudo systemctl stop postgresql@13-main\n~$ sudo systemctl start postgresql@13-main\n~$ sudo pg_lsclusters \nVer Cluster Port Status Owner    Data directory              Log file\n13  main    5432 online postgres \/var\/lib\/postgresql\/13\/main \/var\/log\/postgresql\/postgresql-13-main.log\n<\/code><\/pre>\n\n\n\n<p>Your upgrade is now complete!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The newer version of Debian 11 comes with PostgreSQL 13. I have the original PostgreSQL 11 running with all my data. Now I&#8217;m going to walk through the process of upgrading from PostgreSQL 11 to 13. Be aware this process will work when upgrading from PostgreSQL 9.6 to 11 or 13. Lets see what&#8217;s going on. Run pg_lsclusters to see [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-254","post","type-post","status-publish","format-standard","hentry","category-misc"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.cmsws.com\/blog\/wp-json\/wp\/v2\/posts\/254","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cmsws.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cmsws.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cmsws.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cmsws.com\/blog\/wp-json\/wp\/v2\/comments?post=254"}],"version-history":[{"count":6,"href":"https:\/\/www.cmsws.com\/blog\/wp-json\/wp\/v2\/posts\/254\/revisions"}],"predecessor-version":[{"id":264,"href":"https:\/\/www.cmsws.com\/blog\/wp-json\/wp\/v2\/posts\/254\/revisions\/264"}],"wp:attachment":[{"href":"https:\/\/www.cmsws.com\/blog\/wp-json\/wp\/v2\/media?parent=254"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cmsws.com\/blog\/wp-json\/wp\/v2\/categories?post=254"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cmsws.com\/blog\/wp-json\/wp\/v2\/tags?post=254"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}