{"id":20435,"date":"2022-11-17T09:28:00","date_gmt":"2022-11-17T08:28:00","guid":{"rendered":"https:\/\/www.dbi-services.com\/blog\/?p=20435"},"modified":"2024-09-10T17:25:53","modified_gmt":"2024-09-10T15:25:53","slug":"recreate-a-patroni-replica-using-pgbackrest","status":"publish","type":"post","link":"https:\/\/www.dbi-services.com\/blog\/recreate-a-patroni-replica-using-pgbackrest\/","title":{"rendered":"Recreate a Patroni replica using pgBackRest"},"content":{"rendered":"\n<p>In my last blog we had a look on <a href=\"https:\/\/www.dbi-services.com\/blog\/bootstrap-patroni-cluster-from-pgbackrest-backup\/\" target=\"_blank\" rel=\"noreferrer noopener\">how to bootstrap a complete Patroni Cluster from pgBackRest<\/a>. But there is also the possibility to recreate only one Patroni node using pgBackRest. In this blog we will have a look on all the things we need to change to recreate a node successfully from backup.<\/p>\n\n\n\n<p>First of all, let&#8217;s assume we have a three node Patroni Setup using etcd as key value store and pgBackRest is used to backup the database. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> postgres@hero2:\/home\/postgres\/ &#091;PG1] patronictl list\n+--------+----------------+---------+---------+----+-----------+\n| Member | Host           | Role    | State   | TL | Lag in MB |\n+ Cluster: PG1 (7166642010148587394) ---------+----+-----------+\n| hero1  | 192.168.22.251 | Leader  | running |  1 |           |\n| hero2  | 192.168.22.252 | Replica | running |  1 |         0 |\n| hero3  | 192.168.22.253 | Replica | running |  1 |         0 |\n+--------+----------------+---------+---------+----+-----------+\n\n postgres@hero2:\/home\/postgres\/ &#091;PG1] etcdctl member list\n1c83efe87807cd7b, started, hero2, http:\/\/192.168.22.252:2380, http:\/\/192.168.22.252:2379, false\nb059fedab560f470, started, hero3, http:\/\/192.168.22.253:2380, http:\/\/192.168.22.253:2379, false\necee86d6079e2735, started, hero1, http:\/\/192.168.22.251:2380, http:\/\/192.168.22.251:2379, false\n\n<\/code><\/pre>\n\n\n\n<p>To start we check if there is a backup available in our pgBackRest repository.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>postgres@backup_hero:\/home\/postgres\/ &#091;pg14] pgbackrest info\nstanza: hero2hero\n    status: ok\n    cipher: none\n\n    db (current)\n        wal archive min\/max (14): 000000010000000000000001\/00000001000000000000000C\n\n        full backup: 20221116-165815F\n            timestamp start\/stop: 2022-11-16 16:58:15 \/ 2022-11-16 16:59:04\n            wal start\/stop: 00000001000000000000000A \/ 00000001000000000000000C\n            database size: 105.0MB, database backup size: 105.0MB\n            repo1: backup set size: 30.8MB, backup size: 30.8MB\n<\/code><\/pre>\n\n\n\n<p>So as everything looks healthy we can start to change the configuration of the Patroni cluster. We have to make this change in two steps.<\/p>\n\n\n\n<p>In the first step edit the configuration using edit-conf.  Add the recovery_conf section between use_slots and retry_timeout. Safe your changes.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>postgres@hero2:\/home\/postgres\/ &#091;PG1] patronictl edit-config\n  use_slots: true\n<mark class=\"has-inline-color has-luminous-vivid-amber-color\">recovery_conf:\n  restore_command: pgbackrest --stanza=hero2hero archive-get %f %p\n  restore_target_timeline: latest<\/mark>\nretry_timeout: 10\nttl: 30<\/code><\/pre>\n\n\n\n<p>As the next step, change the patroni.yml. We add the create_replica_methods to the file. As we define pgbackrest and basebackup, it will try to recreate the replica from pgBackRest first and if this is not possible it will recreate from basebackup of the master. <\/p>\n\n\n\n<p>This change should be done at least on the node you want to recreate using pgBackRest but it&#8217;s better to do it on all three nodes to make sure that you are prepared in any case. Be careful with this change and make sure you add enough spaces at the beginning of the line. Add the section create_replica_methods below the parameters section.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>postgresql:\n  ..\n  ..\n  parameters:\n    unix_socket_directories: '\/tmp'\n  <mark class=\"has-inline-color has-luminous-vivid-amber-color\">create_replica_methods:\n    - pgbackrest\n    - basebackup\n  pgbackrest:\n    command: pgbackrest --stanza=hero2hero restore\n    keep_data: True\n    no_params: True\n  basebackup:\n    checkpoint: 'fast'<\/mark><\/code><\/pre>\n\n\n\n<p>Once all the changes are done, you need to reload patroni<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl reload patroni<\/code><\/pre>\n\n\n\n<p>Now we can destroy one replica and recreate it.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>postgres@hero2:\/home\/postgres\/ &#091;pg14] sudo systemctl stop patroni\npostgres@hero2:\/home\/postgres\/ &#091;pg14] rm -rf \/u02\/pgdata\/14\/PG1\/*\npostgres@hero2:\/home\/postgres\/ &#091;pg14] ls -al \/u02\/pgdata\/14\/PG1\/\ntotal 0\ndrwxr-x---. 2 postgres postgres  6 Nov 16 17:16 .\ndrwxr-x---. 3 postgres postgres 17 Sep  5 10:20 ..\npostgres@hero2:\/home\/postgres\/ &#091;pg14] sudo systemctl start patroni\n<\/code><\/pre>\n\n\n\n<p>This does not really show as if the replica is really recreated from pgBackRest, but if we check the logfile, we get a self explaining message, that pgBackRest was used (see last line)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>postgres@hero2:\/home\/postgres\/ &#091;pg14] sudo journalctl -u patroni -f\n-- Logs begin at Fri 2022-09-16 08:50:46 CEST. --\nNov 16 17:16:37 hero2 systemd&#091;1]: Starting dbi services patroni service...\nNov 16 17:16:37 hero2 systemd&#091;1]: Started dbi services patroni service.\nNov 16 17:16:38 hero2 patroni&#091;38394]: 2022-11-16 17:16:38,085 INFO: Selected new etcd server http:\/\/192.168.22.253:2379\nNov 16 17:16:38 hero2 patroni&#091;38394]: 2022-11-16 17:16:38,094 INFO: No PostgreSQL configuration items changed, nothing to reload.\nNov 16 17:16:38 hero2 patroni&#091;38394]: 2022-11-16 17:16:38,116 INFO: Lock owner: hero1; I am hero2\nNov 16 17:16:38 hero2 patroni&#091;38394]: 2022-11-16 17:16:38,120 INFO: trying to bootstrap from leader 'hero1'\n<mark class=\"has-inline-color has-luminous-vivid-amber-color\">Nov 16 17:16:42 hero2 patroni&#091;38394]: 2022-11-16 17:16:42,532 INFO: replica has been created using pgbackrest<\/mark>\n..\n..\n..<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>The implementation of that behavior is quite easy and fast to setup. As already mentioned, keep in mind to put enough spaces in the patroni.yml otherwise the replica won&#8217;t be created using pgBackRest. So in case you still see this entry in your logfile<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>INFO: replica has been created using basebackup\nINFO: bootstrapped from leader 'hero1'<\/code><\/pre>\n\n\n\n<p>Have a look at your patroni.yml once again!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In my last blog we had a look on how to bootstrap a complete Patroni Cluster from pgBackRest. But there is also the possibility to recreate only one Patroni node using pgBackRest. In this blog we will have a look on all the things we need to change to recreate a node successfully from backup. [&hellip;]<\/p>\n","protected":false},"author":28,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[229,83],"tags":[1984,84,1952],"type_dbi":[],"class_list":["post-20435","post","type-post","status-publish","format-standard","hentry","category-database-administration-monitoring","category-postgresql","tag-database-backup","tag-high-availability","tag-postgressql"],"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>Recreate a Patroni replica using pgBackRest - dbi Blog<\/title>\n<meta name=\"description\" content=\"In my last blog we had a look on how to bootstrap a complete Patroni Cluster from pgBackRest. But there is also the possibility to recreate only one Patroni node using pgBackRest. In this blog we will have a look on all the things we need to change to recreate a node successfully from backup.\" \/>\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\/recreate-a-patroni-replica-using-pgbackrest\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Recreate a Patroni replica using pgBackRest\" \/>\n<meta property=\"og:description\" content=\"In my last blog we had a look on how to bootstrap a complete Patroni Cluster from pgBackRest. But there is also the possibility to recreate only one Patroni node using pgBackRest. In this blog we will have a look on all the things we need to change to recreate a node successfully from backup.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.dbi-services.com\/blog\/recreate-a-patroni-replica-using-pgbackrest\/\" \/>\n<meta property=\"og:site_name\" content=\"dbi Blog\" \/>\n<meta property=\"article:published_time\" content=\"2022-11-17T08:28:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-09-10T15:25:53+00:00\" \/>\n<meta name=\"author\" content=\"Open source Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Open source Team\" \/>\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\/recreate-a-patroni-replica-using-pgbackrest\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/recreate-a-patroni-replica-using-pgbackrest\/\"},\"author\":{\"name\":\"Open source Team\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/59554f0d99383431eb6ed427e338952b\"},\"headline\":\"Recreate a Patroni replica using pgBackRest\",\"datePublished\":\"2022-11-17T08:28:00+00:00\",\"dateModified\":\"2024-09-10T15:25:53+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/recreate-a-patroni-replica-using-pgbackrest\/\"},\"wordCount\":370,\"commentCount\":0,\"keywords\":[\"Database backup\",\"High availability\",\"PostgresSQL\"],\"articleSection\":[\"Database Administration &amp; Monitoring\",\"PostgreSQL\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/recreate-a-patroni-replica-using-pgbackrest\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/recreate-a-patroni-replica-using-pgbackrest\/\",\"url\":\"https:\/\/www.dbi-services.com\/blog\/recreate-a-patroni-replica-using-pgbackrest\/\",\"name\":\"Recreate a Patroni replica using pgBackRest - dbi Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#website\"},\"datePublished\":\"2022-11-17T08:28:00+00:00\",\"dateModified\":\"2024-09-10T15:25:53+00:00\",\"author\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/59554f0d99383431eb6ed427e338952b\"},\"description\":\"In my last blog we had a look on how to bootstrap a complete Patroni Cluster from pgBackRest. But there is also the possibility to recreate only one Patroni node using pgBackRest. In this blog we will have a look on all the things we need to change to recreate a node successfully from backup.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.dbi-services.com\/blog\/recreate-a-patroni-replica-using-pgbackrest\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.dbi-services.com\/blog\/recreate-a-patroni-replica-using-pgbackrest\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.dbi-services.com\/blog\/recreate-a-patroni-replica-using-pgbackrest\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Accueil\",\"item\":\"https:\/\/www.dbi-services.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Recreate a Patroni replica using pgBackRest\"}]},{\"@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\/59554f0d99383431eb6ed427e338952b\",\"name\":\"Open source Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/eb4fb12e386e8c41fdef0733e8114594cf2653e4f55e9fa2161442b8eaf3f657?s=96&d=mm&r=g\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/eb4fb12e386e8c41fdef0733e8114594cf2653e4f55e9fa2161442b8eaf3f657?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/eb4fb12e386e8c41fdef0733e8114594cf2653e4f55e9fa2161442b8eaf3f657?s=96&d=mm&r=g\",\"caption\":\"Open source Team\"},\"url\":\"https:\/\/www.dbi-services.com\/blog\/author\/open-source-team\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Recreate a Patroni replica using pgBackRest - dbi Blog","description":"In my last blog we had a look on how to bootstrap a complete Patroni Cluster from pgBackRest. But there is also the possibility to recreate only one Patroni node using pgBackRest. In this blog we will have a look on all the things we need to change to recreate a node successfully from backup.","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\/recreate-a-patroni-replica-using-pgbackrest\/","og_locale":"en_US","og_type":"article","og_title":"Recreate a Patroni replica using pgBackRest","og_description":"In my last blog we had a look on how to bootstrap a complete Patroni Cluster from pgBackRest. But there is also the possibility to recreate only one Patroni node using pgBackRest. In this blog we will have a look on all the things we need to change to recreate a node successfully from backup.","og_url":"https:\/\/www.dbi-services.com\/blog\/recreate-a-patroni-replica-using-pgbackrest\/","og_site_name":"dbi Blog","article_published_time":"2022-11-17T08:28:00+00:00","article_modified_time":"2024-09-10T15:25:53+00:00","author":"Open source Team","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Open source Team","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.dbi-services.com\/blog\/recreate-a-patroni-replica-using-pgbackrest\/#article","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/recreate-a-patroni-replica-using-pgbackrest\/"},"author":{"name":"Open source Team","@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/59554f0d99383431eb6ed427e338952b"},"headline":"Recreate a Patroni replica using pgBackRest","datePublished":"2022-11-17T08:28:00+00:00","dateModified":"2024-09-10T15:25:53+00:00","mainEntityOfPage":{"@id":"https:\/\/www.dbi-services.com\/blog\/recreate-a-patroni-replica-using-pgbackrest\/"},"wordCount":370,"commentCount":0,"keywords":["Database backup","High availability","PostgresSQL"],"articleSection":["Database Administration &amp; Monitoring","PostgreSQL"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.dbi-services.com\/blog\/recreate-a-patroni-replica-using-pgbackrest\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.dbi-services.com\/blog\/recreate-a-patroni-replica-using-pgbackrest\/","url":"https:\/\/www.dbi-services.com\/blog\/recreate-a-patroni-replica-using-pgbackrest\/","name":"Recreate a Patroni replica using pgBackRest - dbi Blog","isPartOf":{"@id":"https:\/\/www.dbi-services.com\/blog\/#website"},"datePublished":"2022-11-17T08:28:00+00:00","dateModified":"2024-09-10T15:25:53+00:00","author":{"@id":"https:\/\/www.dbi-services.com\/blog\/#\/schema\/person\/59554f0d99383431eb6ed427e338952b"},"description":"In my last blog we had a look on how to bootstrap a complete Patroni Cluster from pgBackRest. But there is also the possibility to recreate only one Patroni node using pgBackRest. In this blog we will have a look on all the things we need to change to recreate a node successfully from backup.","breadcrumb":{"@id":"https:\/\/www.dbi-services.com\/blog\/recreate-a-patroni-replica-using-pgbackrest\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.dbi-services.com\/blog\/recreate-a-patroni-replica-using-pgbackrest\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.dbi-services.com\/blog\/recreate-a-patroni-replica-using-pgbackrest\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Accueil","item":"https:\/\/www.dbi-services.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Recreate a Patroni replica using pgBackRest"}]},{"@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\/59554f0d99383431eb6ed427e338952b","name":"Open source Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/eb4fb12e386e8c41fdef0733e8114594cf2653e4f55e9fa2161442b8eaf3f657?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/eb4fb12e386e8c41fdef0733e8114594cf2653e4f55e9fa2161442b8eaf3f657?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/eb4fb12e386e8c41fdef0733e8114594cf2653e4f55e9fa2161442b8eaf3f657?s=96&d=mm&r=g","caption":"Open source Team"},"url":"https:\/\/www.dbi-services.com\/blog\/author\/open-source-team\/"}]}},"_links":{"self":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/20435","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\/28"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/comments?post=20435"}],"version-history":[{"count":8,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/20435\/revisions"}],"predecessor-version":[{"id":20480,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/posts\/20435\/revisions\/20480"}],"wp:attachment":[{"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/media?parent=20435"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/categories?post=20435"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/tags?post=20435"},{"taxonomy":"type","embeddable":true,"href":"https:\/\/www.dbi-services.com\/blog\/wp-json\/wp\/v2\/type_dbi?post=20435"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}