{"id":1757,"date":"2026-06-17T15:53:34","date_gmt":"2026-06-17T13:53:34","guid":{"rendered":"https:\/\/locallost.net\/?p=1757"},"modified":"2026-06-17T15:53:34","modified_gmt":"2026-06-17T13:53:34","slug":"performing-a-pg_basebackup-against-the-gitlabs-managed-postgresql-database","status":"publish","type":"post","link":"https:\/\/locallost.net\/?p=1757","title":{"rendered":"Performing a `pg_basebackup` against the GitLab&rsquo;s managed PostgreSQL database"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">One can perform a \u00ab\u00a0live-backup\u00a0\u00bb of a PostgreSQL cluster using <code>pg_basebackup<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">GitLab (installed from <code>.deb<\/code> packages) installs and manages a PostgreSQL cluster autonomously and by default a <code>pg_basebackup<\/code> will fail (and is not authorized).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To perform a live <code>pg_basebackup<\/code> against the GitLab&rsquo;s managed PostgreSQL server, one needs to enable replication and authorize the <code>gitlab-psql<\/code> user to perform the replication:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Setup GitLab&rsquo;s PostgreSQL for replication in <code>\/etc\/gitlab\/gitlab.rb<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>postgresql&#91;'wal_level'] = \"replica\"\npostgresql&#91;'max_wal_senders'] = 10\npostgresql&#91;'max_replication_slots'] = 10\npostgresql&#91;'custom_pg_hba_entries'] = {\n  PG_BASEBACKUP: &#91;\n    {\n      type: \"local\",\n      database: \"replication\",\n      user: \"gitlab-psql\",\n      cidr: \"\",\n      method: \"peer\"\n    }\n  ]\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This will enable replication in PostgreSQL (in <code>postgresql.conf<\/code>) and allow local connections for replication (in <code>pg_hba.conf<\/code>).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Reconfigure and restart the <code>postgresql<\/code> service:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gitlab-ctl reconfigure\ngitlab-ctl restart postgresql<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">From now on, you should be able to perform a <code>pg_basebackup<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>runuser -u gitlab-psql -- \/opt\/gitlab\/embedded\/bin\/pg_basebackup -h \/var\/opt\/gitlab\/postgresql --checkpoint=fast --format=p --pgdata \"\/tmp\/pg_basebackup.$(date +%Y-%m-%d).data\"<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>One can perform a \u00ab\u00a0live-backup\u00a0\u00bb of a PostgreSQL cluster using pg_basebackup. GitLab (installed from .deb packages) installs and manages a PostgreSQL cluster autonomously and by default a pg_basebackup will fail (and is not authorized). To perform a live pg_basebackup against &hellip; <a href=\"https:\/\/locallost.net\/?p=1757\">Continuer la lecture <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1],"tags":[],"class_list":["post-1757","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2Bei9-sl","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/locallost.net\/index.php?rest_route=\/wp\/v2\/posts\/1757","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/locallost.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/locallost.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/locallost.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/locallost.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1757"}],"version-history":[{"count":2,"href":"https:\/\/locallost.net\/index.php?rest_route=\/wp\/v2\/posts\/1757\/revisions"}],"predecessor-version":[{"id":1760,"href":"https:\/\/locallost.net\/index.php?rest_route=\/wp\/v2\/posts\/1757\/revisions\/1760"}],"wp:attachment":[{"href":"https:\/\/locallost.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1757"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/locallost.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1757"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/locallost.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1757"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}