1---
2stage: Enablement
3group: Geo
4info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#assignments
5type: howto
6---
7
8# Disaster Recovery (Geo) **(PREMIUM SELF)**
9
10Geo replicates your database, your Git repositories, and few other assets,
11but there are some [limitations](../index.md#limitations).
12
13WARNING:
14Disaster recovery for multi-secondary configurations is in **Alpha**.
15For the latest updates, check the [Disaster Recovery epic for complete maturity](https://gitlab.com/groups/gitlab-org/-/epics/3574).
16Multi-secondary configurations require the complete re-synchronization and re-configuration of all non-promoted secondaries and
17causes downtime.
18
19## Promoting a **secondary** Geo site in single-secondary configurations
20
21We don't currently provide an automated way to promote a Geo replica and do a
22failover, but you can do it manually if you have `root` access to the machine.
23
24This process promotes a **secondary** Geo site to a **primary** site. To regain
25geographic redundancy as quickly as possible, you should add a new **secondary** site
26immediately after following these instructions.
27
28### Step 1. Allow replication to finish if possible
29
30If the **secondary** site is still replicating data from the **primary** site, follow
31[the planned failover docs](planned_failover.md) as closely as possible in
32order to avoid unnecessary data loss.
33
34### Step 2. Permanently disable the **primary** site
35
36WARNING:
37If the **primary** site goes offline, there may be data saved on the **primary** site
38that have not been replicated to the **secondary** site. This data should be treated
39as lost if you proceed.
40
41If an outage on the **primary** site happens, you should do everything possible to
42avoid a split-brain situation where writes can occur in two different GitLab
43instances, complicating recovery efforts. So to prepare for the failover, we
44must disable the **primary** site.
45
46- If you have SSH access:
47
48  1. SSH into the **primary** site to stop and disable GitLab:
49
50     ```shell
51     sudo gitlab-ctl stop
52     ```
53
54  1. Prevent GitLab from starting up again if the server unexpectedly reboots:
55
56     ```shell
57     sudo systemctl disable gitlab-runsvdir
58     ```
59
60- If you do not have SSH access to the **primary** site, take the machine offline and
61  prevent it from rebooting by any means at your disposal.
62  You might need to:
63
64  - Reconfigure the load balancers.
65  - Change DNS records (for example, point the primary DNS record to the
66    **secondary** site to stop usage of the **primary** site).
67  - Stop the virtual servers.
68  - Block traffic through a firewall.
69  - Revoke object storage permissions from the **primary** site.
70  - Physically disconnect a machine.
71
72  If you plan to [update the primary domain DNS record](#step-4-optional-updating-the-primary-domain-dns-record),
73  you may wish to lower the TTL now to speed up propagation.
74
75### Step 3. Promoting a **secondary** site
76
77WARNING:
78In GitLab 13.2 and 13.3, promoting a secondary site to a primary while the
79secondary is paused fails. Do not pause replication before promoting a
80secondary. If the secondary site is paused, be sure to resume before promoting.
81This issue has been fixed in GitLab 13.4 and later.
82
83Note the following when promoting a secondary:
84
85- If replication was paused on the secondary site (for example as a part of
86  upgrading, while you were running a version of GitLab earlier than 13.4), you
87  _must_ [enable the site by using the database](../replication/troubleshooting.md#message-activerecordrecordinvalid-validation-failed-enabled-geo-primary-node-cannot-be-disabled)
88  before proceeding. If the secondary site
89  [has been paused](../../geo/index.md#pausing-and-resuming-replication), the promotion
90  performs a point-in-time recovery to the last known state.
91  Data that was created on the primary while the secondary was paused is lost.
92- A new **secondary** should not be added at this time. If you want to add a new
93  **secondary**, do this after you have completed the entire process of promoting
94  the **secondary** to the **primary**.
95- If you encounter an `ActiveRecord::RecordInvalid: Validation failed: Name has already been taken`
96  error message during this process, for more information, see this
97  [troubleshooting advice](../replication/troubleshooting.md#fixing-errors-during-a-failover-or-when-promoting-a-secondary-to-a-primary-node).
98- If you run into errors when using `--force` or `--skip-preflight-checks` before 13.5 during this process,
99  for more information, see this
100  [troubleshooting advice](../replication/troubleshooting.md#errors-when-using---skip-preflight-checks-or---force).
101
102#### Promoting a **secondary** site running on a single node running GitLab 14.5 and later
103
1041. SSH in to your **secondary** node and execute:
105
106   - To promote the secondary node to primary:
107
108     ```shell
109     sudo gitlab-ctl geo promote
110     ```
111
112   - To promote the secondary node to primary **without any further confirmation**:
113
114     ```shell
115     sudo gitlab-ctl geo promote --force
116     ```
117
1181. Verify you can connect to the newly-promoted **primary** site using the URL used
119   previously for the **secondary** site.
1201. If successful, the **secondary** site is now promoted to the **primary** site.
121
122#### Promoting a **secondary** site running on a single node running GitLab 14.4 and earlier
123
124WARNING:
125The `gitlab-ctl promote-to-primary-node` and `gitlab-ctl promoted-db` commands are
126deprecated in GitLab 14.5 and later, and are scheduled to [be removed in GitLab 15.0](https://gitlab.com/gitlab-org/gitlab/-/issues/345207).
127Use `gitlab-ctl geo promote` instead.
128
1291. SSH in to your **secondary** node and login as root:
130
131   ```shell
132   sudo -i
133   ```
134
1351. If you're using GitLab 13.5 and later, skip this step. If not, edit
136   `/etc/gitlab/gitlab.rb` and remove any of the following lines that
137   might be present:
138
139   ```ruby
140   geo_secondary_role['enable'] = true
141   roles ['geo_secondary_role']
142   ```
143
1441. Promote the **secondary** site to the **primary** site:
145
146   - To promote the secondary node to primary along with [preflight checks](planned_failover.md#preflight-checks):
147
148     ```shell
149     gitlab-ctl promote-to-primary-node
150     ```
151
152   - If you have already run the preflight checks separately or don't want to run them,
153     you can skip them with:
154
155     ```shell
156     gitlab-ctl promote-to-primary-node --skip-preflight-checks
157     ```
158
159     NOTE:
160     In GitLab 13.7 and earlier, if you have a data type with zero items to sync
161     and don't skip the preflight checks, promoting the secondary reports
162     `ERROR - Replication is not up-to-date` even if replication is actually
163     up-to-date. If replication and verification output
164     shows that it is complete, you can skip the preflight checks to make the
165     command complete promotion. This bug was fixed in GitLab 13.8 and later.
166
167   - To promote the secondary node to primary **without any further confirmation**,
168     even when preflight checks fail:
169
170     ```shell
171     gitlab-ctl promote-to-primary-node --force
172     ```
173
1741. Verify you can connect to the newly-promoted **primary** site using the URL used
175   previously for the **secondary** site.
1761. If successful, the **secondary** site is now promoted to the **primary** site.
177
178#### Promoting a **secondary** site with multiple nodes running GitLab 14.5 and later
179
1801. SSH to every Sidekiq, PostgresSQL, and Gitaly node in the **secondary** site and run one of the following commands:
181
182   - To promote the secondary node to primary:
183
184     ```shell
185     sudo gitlab-ctl geo promote
186     ```
187
188   - To promote the secondary node to primary **without any further confirmation**:
189
190     ```shell
191     sudo gitlab-ctl geo promote --force
192     ```
193
1941. SSH into each Rails node on your **secondary** site and run one of the following commands:
195
196   - To promote the secondary node to primary:
197
198     ```shell
199     sudo gitlab-ctl geo promote
200     ```
201
202   - To promote the secondary node to primary **without any further confirmation**:
203
204     ```shell
205     sudo gitlab-ctl geo promote --force
206     ```
207
2081. Verify you can connect to the newly-promoted **primary** site using the URL used
209   previously for the **secondary** site.
2101. If successful, the **secondary** site is now promoted to the **primary** site.
211
212#### Promoting a **secondary** site with multiple nodes running GitLab 14.4 and earlier
213
214WARNING:
215The `gitlab-ctl promote-to-primary-node` and `gitlab-ctl promoted-db` commands are
216deprecated in GitLab 14.5 and later, and are scheduled to [be removed in GitLab 15.0](https://gitlab.com/gitlab-org/gitlab/-/issues/345207).
217Use `gitlab-ctl geo promote` instead.
218
219The `gitlab-ctl promote-to-primary-node` command cannot be used yet in
220conjunction with multiple nodes, as it can only perform changes on
221a **secondary** with only a single node. Instead, you must
222do this manually.
223
2241. SSH in to the database node in the **secondary** site and trigger PostgreSQL to
225   promote to read-write:
226
227   ```shell
228   sudo gitlab-ctl promote-db
229   ```
230
231   In GitLab 12.8 and earlier, see [Message: `sudo: gitlab-pg-ctl: command not found`](../replication/troubleshooting.md#message-sudo-gitlab-pg-ctl-command-not-found).
232
2331. Edit `/etc/gitlab/gitlab.rb` on every node in the **secondary** site to
234   reflect its new status as **primary** by removing any of the following
235   lines that might be present:
236
237   ```ruby
238   geo_secondary_role['enable'] = true
239   roles ['geo_secondary_role']
240   ```
241
242   After making these changes, [reconfigure GitLab](../../restart_gitlab.md#omnibus-gitlab-reconfigure)
243   on each machine so the changes take effect.
244
2451. Promote the **secondary** to **primary**. SSH into a single application
246   server and execute:
247
248   ```shell
249   sudo gitlab-rake geo:set_secondary_as_primary
250   ```
251
2521. Verify you can connect to the newly-promoted **primary** using the URL used
253   previously for the **secondary**.
2541. If successful, the **secondary** site is now promoted to the **primary** site.
255
256#### Promoting a **secondary** site with a Patroni standby cluster running GitLab 14.5 and later
257
2581. SSH to every Sidekiq, PostgresSQL, and Gitaly node in the **secondary** site and run one of the following commands:
259
260   - To promote the secondary node to primary:
261
262     ```shell
263     sudo gitlab-ctl geo promote
264     ```
265
266   - To promote the secondary node to primary **without any further confirmation**:
267
268     ```shell
269     sudo gitlab-ctl geo promote --force
270     ```
271
2721. SSH into each Rails node on your **secondary** site and run one of the following commands:
273
274   - To promote the secondary node to primary:
275
276     ```shell
277     sudo gitlab-ctl geo promote
278     ```
279
280   - To promote the secondary node to primary **without any further confirmation**:
281
282     ```shell
283     sudo gitlab-ctl geo promote --force
284     ```
285
2861. Verify you can connect to the newly-promoted **primary** site using the URL used
287   previously for the **secondary** site.
2881. If successful, the **secondary** site is now promoted to the **primary** site.
289
290#### Promoting a **secondary** site with a Patroni standby cluster running GitLab 14.4 and earlier
291
292WARNING:
293The `gitlab-ctl promote-to-primary-node` and `gitlab-ctl promoted-db` commands are
294deprecated in GitLab 14.5 and later, and are scheduled to [be removed in GitLab 15.0](https://gitlab.com/gitlab-org/gitlab/-/issues/345207).
295Use `gitlab-ctl geo promote` instead.
296
297The `gitlab-ctl promote-to-primary-node` command cannot be used yet in
298conjunction with a Patroni standby cluster, as it can only perform changes on
299a **secondary** with only a single node. Instead, you must do this manually.
300
3011. SSH in to the Standby Leader database node in the **secondary** site and trigger PostgreSQL to
302   promote to read-write:
303
304   ```shell
305   sudo gitlab-ctl promote-db
306   ```
307
3081. Edit `/etc/gitlab/gitlab.rb` on every application and Sidekiq nodes in the secondary to reflect its new status as primary by removing any of the following lines that might be present:
309
310   ```ruby
311   geo_secondary_role['enable'] = true
312   roles ['geo_secondary_role']
313   ```
314
3151. Edit `/etc/gitlab/gitlab.rb` on every Patroni node in the secondary to disable the standby cluster:
316
317   ```ruby
318   patroni['standby_cluster']['enable'] = false
319   ```
320
3211. Reconfigure GitLab on each machine for the changes to take effect:
322
323   ```shell
324   sudo gitlab-ctl reconfigure
325   ```
326
3271. Promote the **secondary** to **primary**. SSH into a single application server and execute:
328
329   ```shell
330   sudo gitlab-rake geo:set_secondary_as_primary
331   ```
332
3331. Verify you can connect to the newly-promoted **primary** using the URL used
334   previously for the **secondary**.
3351. If successful, the **secondary** site is now promoted to the **primary** site.
336
337#### Promoting a **secondary** site with an external PostgreSQL database running GitLab 14.5 and later
338
339The `gitlab-ctl geo promote` command can be used in conjunction with
340an external PostgreSQL database, but it can only perform changes on
341a **secondary** PostgreSQL database managed by Omnibus.
342You must promote the replica database associated with the **secondary**
343site first.
344
3451. Promote the replica database associated with the **secondary** site. This
346   sets the database to read-write. The instructions vary depending on where your database is hosted:
347   - [Amazon RDS](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_ReadRepl.html#USER_ReadRepl.Promote)
348   - [Azure PostgreSQL](https://docs.microsoft.com/en-us/azure/postgresql/howto-read-replicas-portal#stop-replication)
349   - [Google Cloud SQL](https://cloud.google.com/sql/docs/mysql/replication/manage-replicas#promote-replica)
350   - For other external PostgreSQL databases, save the following script in your
351     secondary node, for example `/tmp/geo_promote.sh`, and modify the connection
352     parameters to match your environment. Then, execute it to promote the replica:
353
354     ```shell
355     #!/bin/bash
356
357     PG_SUPERUSER=postgres
358
359     # The path to your pg_ctl binary. You may need to adjust this path to match
360     # your PostgreSQL installation
361     PG_CTL_BINARY=/usr/lib/postgresql/10/bin/pg_ctl
362
363     # The path to your PostgreSQL data directory. You may need to adjust this
364     # path to match your PostgreSQL installation. You can also run
365     # `SHOW data_directory;` from PostgreSQL to find your data directory
366     PG_DATA_DIRECTORY=/etc/postgresql/10/main
367
368     # Promote the PostgreSQL database and allow read/write operations
369     sudo -u $PG_SUPERUSER $PG_CTL_BINARY -D $PG_DATA_DIRECTORY promote
370     ```
371
3721. SSH to every Sidekiq, PostgresSQL, and Gitaly node in the **secondary** site and run one of the following commands:
373
374   - To promote the secondary node to primary:
375
376     ```shell
377     sudo gitlab-ctl geo promote
378     ```
379
380   - To promote the secondary node to primary **without any further confirmation**:
381
382     ```shell
383     sudo gitlab-ctl geo promote --force
384     ```
385
3861. SSH into each Rails node on your **secondary** site and run one of the following commands:
387
388   - To promote the secondary node to primary:
389
390     ```shell
391     sudo gitlab-ctl geo promote
392     ```
393
394   - To promote the secondary node to primary **without any further confirmation**:
395
396     ```shell
397     sudo gitlab-ctl geo promote --force
398     ```
399
4001. Verify you can connect to the newly-promoted **primary** site using the URL used
401   previously for the **secondary** site.
4021. If successful, the **secondary** site is now promoted to the **primary** site.
403
404#### Promoting a **secondary** site with an external PostgreSQL database running GitLab 14.4 and earlier
405
406WARNING:
407The `gitlab-ctl promote-to-primary-node` and `gitlab-ctl promoted-db` commands are
408deprecated in GitLab 14.5 and later, and are scheduled to [be removed in GitLab 15.0](https://gitlab.com/gitlab-org/gitlab/-/issues/345207).
409Use `gitlab-ctl geo promote` instead.
410
411The `gitlab-ctl promote-to-primary-node` command cannot be used in conjunction with
412an external PostgreSQL database, as it can only perform changes on a **secondary**
413node with GitLab and the database on the same machine. As a result, a manual process is
414required:
415
4161. Promote the replica database associated with the **secondary** site. This
417   sets the database to read-write. The instructions vary depending on where your database is hosted:
418   - [Amazon RDS](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_ReadRepl.html#USER_ReadRepl.Promote)
419   - [Azure PostgreSQL](https://docs.microsoft.com/en-us/azure/postgresql/howto-read-replicas-portal#stop-replication)
420   - [Google Cloud SQL](https://cloud.google.com/sql/docs/mysql/replication/manage-replicas#promote-replica)
421   - For other external PostgreSQL databases, save the following script in your
422     secondary node, for example `/tmp/geo_promote.sh`, and modify the connection
423     parameters to match your environment. Then, execute it to promote the replica:
424
425     ```shell
426     #!/bin/bash
427
428     PG_SUPERUSER=postgres
429
430     # The path to your pg_ctl binary. You may need to adjust this path to match
431     # your PostgreSQL installation
432     PG_CTL_BINARY=/usr/lib/postgresql/10/bin/pg_ctl
433
434     # The path to your PostgreSQL data directory. You may need to adjust this
435     # path to match your PostgreSQL installation. You can also run
436     # `SHOW data_directory;` from PostgreSQL to find your data directory
437     PG_DATA_DIRECTORY=/etc/postgresql/10/main
438
439     # Promote the PostgreSQL database and allow read/write operations
440     sudo -u $PG_SUPERUSER $PG_CTL_BINARY -D $PG_DATA_DIRECTORY promote
441     ```
442
4431. Edit `/etc/gitlab/gitlab.rb` on every node in the **secondary** site to
444   reflect its new status as **primary** by removing any of the following
445   lines that might be present:
446
447   ```ruby
448   geo_secondary_role['enable'] = true
449   roles ['geo_secondary_role']
450   ```
451
452   After making these changes [Reconfigure GitLab](../../restart_gitlab.md#omnibus-gitlab-reconfigure)
453   on each node so the changes take effect.
454
4551. Promote the **secondary** to **primary**. SSH into a single secondary application
456   node and execute:
457
458   ```shell
459   sudo gitlab-rake geo:set_secondary_as_primary
460   ```
461
4621. Verify you can connect to the newly-promoted **primary** using the URL used
463   previously for the **secondary**.
4641. If successful, the **secondary** site is now promoted to the **primary** site.
465
466### Step 4. (Optional) Updating the primary domain DNS record
467
468Updating the DNS records for the primary domain to point to the **secondary** site
469to prevent the need to update all references to the primary domain to the
470secondary domain, like changing Git remotes and API URLs.
471
4721. SSH into the **secondary** site and login as root:
473
474   ```shell
475   sudo -i
476   ```
477
4781. Update the primary domain's DNS record. After updating the primary domain's
479   DNS records to point to the **secondary** site, edit `/etc/gitlab/gitlab.rb` on the
480   **secondary** site to reflect the new URL:
481
482   ```ruby
483   # Change the existing external_url configuration
484   external_url 'https://<new_external_url>'
485   ```
486
487   NOTE:
488   Changing `external_url` does not prevent access via the old secondary URL, as
489   long as the secondary DNS records are still intact.
490
4911. Reconfigure the **secondary** site for the change to take effect:
492
493   ```shell
494   gitlab-ctl reconfigure
495   ```
496
4971. Execute the command below to update the newly promoted **primary** site URL:
498
499   ```shell
500   gitlab-rake geo:update_primary_node_url
501   ```
502
503   This command uses the changed `external_url` configuration defined
504   in `/etc/gitlab/gitlab.rb`.
505
5061. For GitLab 11.11 through 12.7 only, you may need to update the **primary**
507   node's name in the database. This bug has been fixed in GitLab 12.8.
508
509   To determine if you need to do this, search for the
510   `gitlab_rails["geo_node_name"]` setting in your `/etc/gitlab/gitlab.rb`
511   file. If it is commented out with `#` or not found at all, then you
512   need to update the **primary** site's name in the database. You can search for it
513   like so:
514
515   ```shell
516   grep "geo_node_name" /etc/gitlab/gitlab.rb
517   ```
518
519   To update the **primary** site's name in the database:
520
521   ```shell
522   gitlab-rails runner 'Gitlab::Geo.primary_node.update!(name: GeoNode.current_node_name)'
523   ```
524
5251. Verify you can connect to the newly promoted **primary** using its URL.
526   If you updated the DNS records for the primary domain, these changes may
527   not have yet propagated depending on the previous DNS records TTL.
528
529### Step 5. (Optional) Add **secondary** Geo site to a promoted **primary** site
530
531Promoting a **secondary** site to **primary** site using the process above does not enable
532Geo on the new **primary** site.
533
534To bring a new **secondary** site online, follow the [Geo setup instructions](../index.md#setup-instructions).
535
536### Step 6. (Optional) Removing the secondary's tracking database
537
538Every **secondary** has a special tracking database that is used to save the status of the synchronization of all the items from the **primary**.
539Because the **secondary** is already promoted, that data in the tracking database is no longer required.
540
541The data can be removed with the following command:
542
543```shell
544sudo rm -rf /var/opt/gitlab/geo-postgresql
545```
546
547If you have any `geo_secondary[]` configuration options enabled in your `gitlab.rb`
548file, these can be safely commented out or removed, and then [reconfigure GitLab](../../restart_gitlab.md#omnibus-gitlab-reconfigure)
549for the changes to take effect.
550
551## Promoting secondary Geo replica in multi-secondary configurations
552
553If you have more than one **secondary** site and you need to promote one of them, we suggest you follow
554[Promoting a **secondary** Geo site in single-secondary configurations](#promoting-a-secondary-geo-site-in-single-secondary-configurations)
555and after that you also need two extra steps.
556
557### Step 1. Prepare the new **primary** site to serve one or more **secondary** sites
558
5591. SSH into the new **primary** site and login as root:
560
561   ```shell
562   sudo -i
563   ```
564
5651. Edit `/etc/gitlab/gitlab.rb`:
566
567   ```ruby
568   ## Enable a Geo Primary role (if you haven't yet)
569   roles ['geo_primary_role']
570
571   ##
572   # Allow PostgreSQL client authentication from the primary and secondary IPs. These IPs may be
573   # public or VPC addresses in CIDR format, for example ['198.51.100.1/32', '198.51.100.2/32']
574   ##
575   postgresql['md5_auth_cidr_addresses'] = ['<primary_node_ip>/32', '<secondary_node_ip>/32']
576
577   # Every secondary server needs to have its own slot so specify the number of secondary nodes you're going to have
578   postgresql['max_replication_slots'] = 1
579
580   ##
581   ## Disable automatic database migrations temporarily
582   ## (until PostgreSQL is restarted and listening on the private address).
583   ##
584   gitlab_rails['auto_migrate'] = false
585   ```
586
587   (For more details about these settings you can read [Configure the primary server](../setup/database.md#step-1-configure-the-primary-server))
588
5891. Save the file and reconfigure GitLab for the database listen changes and
590   the replication slot changes to be applied:
591
592   ```shell
593   gitlab-ctl reconfigure
594   ```
595
596   Restart PostgreSQL for its changes to take effect:
597
598   ```shell
599   gitlab-ctl restart postgresql
600   ```
601
6021. Re-enable migrations now that PostgreSQL is restarted and listening on the
603   private address.
604
605   Edit `/etc/gitlab/gitlab.rb` and **change** the configuration to `true`:
606
607   ```ruby
608   gitlab_rails['auto_migrate'] = true
609   ```
610
611   Save the file and reconfigure GitLab:
612
613   ```shell
614   gitlab-ctl reconfigure
615   ```
616
617### Step 2. Initiate the replication process
618
619Now we need to make each **secondary** site listen to changes on the new **primary** site. To do that you need
620to [initiate the replication process](../setup/database.md#step-3-initiate-the-replication-process) again but this time
621for another **primary** site. All the old replication settings are overwritten.
622
623## Promoting a secondary Geo cluster in GitLab Cloud Native Helm Charts
624
625When updating a Cloud Native Geo deployment, the process for updating any node that is external to the secondary Kubernetes cluster does not differ from the non Cloud Native approach. As such, you can always defer to [Promoting a secondary Geo site in single-secondary configurations](#promoting-a-secondary-geo-site-in-single-secondary-configurations) for more information.
626
627The following sections assume you are using the `gitlab` namespace. If you used a different namespace when setting up your cluster, you should also replace `--namespace gitlab` with your namespace.
628
629WARNING:
630In GitLab 13.2 and 13.3, promoting a secondary site to a primary while the
631secondary is paused fails. Do not pause replication before promoting a
632secondary. If the site is paused, be sure to resume before promoting. This
633issue has been fixed in GitLab 13.4 and later.
634
635### Step 1. Permanently disable the **primary** cluster
636
637WARNING:
638If the **primary** site goes offline, there may be data saved on the **primary** site
639that has not been replicated to the **secondary** site. This data should be treated
640as lost if you proceed.
641
642If an outage on the **primary** site happens, you should do everything possible to
643avoid a split-brain situation where writes can occur in two different GitLab
644instances, complicating recovery efforts. So to prepare for the failover, you
645must disable the **primary** site:
646
647- If you have access to the **primary** Kubernetes cluster, connect to it and disable the GitLab webservice and Sidekiq pods:
648
649  ```shell
650  kubectl --namespace gitlab scale deploy gitlab-geo-webservice-default --replicas=0
651  kubectl --namespace gitlab scale deploy gitlab-geo-sidekiq-all-in-1-v1 --replicas=0
652  ```
653
654- If you do not have access to the **primary** Kubernetes cluster, take the cluster offline and
655  prevent it from coming back online by any means at your disposal.
656  You might need to:
657
658  - Reconfigure the load balancers.
659  - Change DNS records (for example, point the primary DNS record to the
660    **secondary** site to stop usage of the **primary** site).
661  - Stop the virtual servers.
662  - Block traffic through a firewall.
663  - Revoke object storage permissions from the **primary** site.
664  - Physically disconnect a machine.
665
666### Step 2. Promote all **secondary** sites external to the cluster
667
668WARNING:
669If the secondary site [has been paused](../../geo/index.md#pausing-and-resuming-replication), this performs
670a point-in-time recovery to the last known state.
671Data that was created on the primary while the secondary was paused is lost.
672
673If you are running GitLab 14.5 and later:
674
6751. SSH to every Sidekiq, PostgresSQL, and Gitaly node in the **secondary** site and run one of the following commands:
676
677   - To promote the secondary node to primary:
678
679     ```shell
680     sudo gitlab-ctl geo promote
681     ```
682
683   - To promote the secondary node to primary **without any further confirmation**:
684
685     ```shell
686     sudo gitlab-ctl geo promote --force
687     ```
688
6891. SSH into each Rails node on your **secondary** site and run one of the following commands:
690
691   - To promote the secondary node to primary:
692
693     ```shell
694     sudo gitlab-ctl geo promote
695     ```
696
697   - To promote the secondary node to primary **without any further confirmation**:
698
699     ```shell
700     sudo gitlab-ctl geo promote --force
701     ```
702
703If you are running GitLab 14.4 and earlier:
704
7051. SSH in to the database node in the **secondary** and trigger PostgreSQL to
706   promote to read-write:
707
708   ```shell
709   sudo gitlab-ctl promote-db
710   ```
711
712   In GitLab 12.8 and earlier, see [Message: `sudo: gitlab-pg-ctl: command not found`](../replication/troubleshooting.md#message-sudo-gitlab-pg-ctl-command-not-found).
713
7141. Edit `/etc/gitlab/gitlab.rb` on the database node in the **secondary** site to
715   reflect its new status as **primary** by removing any lines that enabled the
716   `geo_secondary_role`:
717
718   NOTE:
719   Depending on your architecture, these steps need to run on any GitLab node that is external to the **secondary** Kubernetes cluster.
720
721   ```ruby
722   ## In pre-11.5 documentation, the role was enabled as follows. Remove this line.
723   geo_secondary_role['enable'] = true
724
725   ## In 11.5+ documentation, the role was enabled as follows. Remove this line.
726   roles ['geo_secondary_role']
727   ```
728
729   After making these changes, [reconfigure GitLab](../../restart_gitlab.md#omnibus-gitlab-reconfigure) on the database node.
730
7311. Find the task runner pod:
732
733   ```shell
734   kubectl --namespace gitlab get pods -lapp=task-runner
735   ```
736
7371. Promote the secondary:
738
739   ```shell
740   kubectl --namespace gitlab exec -ti gitlab-geo-task-runner-XXX -- gitlab-rake geo:set_secondary_as_primary
741   ```
742
743### Step 3. Promote the **secondary** cluster
744
7451. Update the existing cluster configuration.
746
747   You can retrieve the existing configuration with Helm:
748
749   ```shell
750   helm --namespace gitlab get values gitlab-geo > gitlab.yaml
751   ```
752
753   The existing configuration contains a section for Geo that should resemble:
754
755   ```yaml
756   geo:
757      enabled: true
758      role: secondary
759      nodeName: secondary.example.com
760      psql:
761         host: geo-2.db.example.com
762         port: 5431
763         password:
764            secret: geo
765            key: geo-postgresql-password
766   ```
767
768   To promote the **secondary** cluster to a **primary** cluster, update `role: secondary` to `role: primary`.
769
770   If the cluster remains as a primary site, you can remove the entire `psql` section; it refers to the tracking database and is ignored whilst the cluster is acting as a primary site.
771
772   Update the cluster with the new configuration:
773
774   ```shell
775   helm upgrade --install --version <current Chart version> gitlab-geo gitlab/gitlab --namespace gitlab -f gitlab.yaml
776   ```
777
7781. Verify you can connect to the newly promoted primary using the URL used previously for the secondary.
779
7801. Success! The secondary has now been promoted to primary.
781
782## Troubleshooting
783
784This section was moved to [another location](../replication/troubleshooting.md#fixing-errors-during-a-failover-or-when-promoting-a-secondary-to-a-primary-node).
785