You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/postgresql/flexible-server/how-to-read-replicas-portal.md
+283-1Lines changed: 283 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -76,6 +76,127 @@ Before setting up a read replica for Azure Database for PostgreSQL, ensure the p
76
76
77
77
:::image type="content" source="./media/how-to-read-replicas-portal/primary-compute.png" alt-text="Screenshot of server settings." lightbox="./media/how-to-read-replicas-portal/primary-compute.png":::
78
78
79
+
#### [CLI](#tab/cli)
80
+
81
+
> [!NOTE]
82
+
> The commands provided in this guide are applicable for Azure CLI version 2.56.0 or higher. Ensure that you have the required version or a later one installed to execute these commands successfully. You can check your current Azure CLI version by running `az --version` in your command line interface. To update Azure CLI to the latest version, follow the instructions provided in the [Azure CLI documentation](/cli/azure/update-azure-cli).
83
+
84
+
85
+
To view the configuration and current status of an Azure PostgreSQL Flexible Server, use the `az postgres flexible-server show` command. This command provides detailed information about the specified server.
86
+
87
+
```azurecli-interactive
88
+
az postgres flexible-server show \
89
+
--resource-group <resource-group> \
90
+
--name <server-name>
91
+
```
92
+
93
+
Replace `<resource-group>` and `<server-name>` with your specific resource group and the name of the server you wish to view.
94
+
95
+
Review and note the following settings:
96
+
97
+
- Compute Tier, Processor, Size (ex `Standard_D8ads_v5`).
To obtain information about the configuration of a server in Azure Database for PostgreSQL - Flexible Server, especially to view settings for recently introduced features like storage auto-grow or private link, you should use the latest API version `2023-06-01-preview`. The `GET` request for this would be formatted as follows:
@@ -204,6 +325,21 @@ To create a read replica, follow these steps:
204
325
205
326
:::image type="content" source="./media/how-to-read-replicas-portal/list-replica.png" alt-text="Screenshot of viewing the new replica in the replication window." lightbox="./media/how-to-read-replicas-portal/list-replica.png":::
206
327
328
+
#### [CLI](#tab/cli)
329
+
330
+
You can create a read replica for your Azure PostgreSQL Flexible Server by using the [`az postgres flexible-server replica create`](/cli/azure/postgres/flexible-server/replica#az-postgres-flexible-server-replica-create) command.
331
+
332
+
```azurecli-interactive
333
+
az postgres flexible-server replica create \
334
+
--replica-name <replica-name> \
335
+
--resource-group <resource-group> \
336
+
--source-server <source-server-name> \
337
+
--location <location>
338
+
```
339
+
340
+
Replace `<replica-name>`, `<resource-group>`, `<source-server-name>` and `<location>` with your specific values.
341
+
342
+
207
343
#### [REST API](#tab/restapi)
208
344
209
345
Initiate an `HTTP PUT` request by using the [create API](/rest/api/postgresql/flexibleserver/servers/create):
@@ -274,6 +410,21 @@ Here, you need to replace `{subscriptionId}`, `{resourceGroupName}`, and `{repli
274
410
275
411
:::image type="content" source="./media/how-to-read-replicas-portal/replica-promote-attempt.png" alt-text="Screenshot of promotion error when missing virtual endpoint.":::
276
412
413
+
#### [CLI](#tab/cli)
414
+
You can create a virtual endpoint by using the [`az postgres flexible-server virtual-endpoint create`](/cli/azure/postgres/flexible-server/virtual-endpoint#az-postgres-flexible-server-virtual-endpoint-create) command.
415
+
416
+
```azurecli-interactive
417
+
az postgres flexible-server virtual-endpoint create \
418
+
--resource-group <resource-group> \
419
+
--server-name <primary-name> \
420
+
--name <virtual-endpoint-name> \
421
+
--endpoint-type ReadWrite \
422
+
--members <replica-name>
423
+
```
424
+
425
+
Replace `<resource-group>`, `<primary-name>`, `<virtual-endpoint-name>`, and `<replica-name>` with your specific values.
426
+
427
+
277
428
#### [REST API](#tab/restapi)
278
429
279
430
To create a virtual endpoint in a preview environment using Azure's REST API, you would use an `HTTP PUT` request. The request would look like this:
@@ -312,6 +463,30 @@ To list virtual endpoints in the preview version of Azure Database for PostgreSQ
312
463
313
464
:::image type="content" source="./media/how-to-read-replicas-portal/virtual-endpoints-show.png" alt-text="Screenshot of virtual endpoints list." lightbox="./media/how-to-read-replicas-portal/virtual-endpoints-show.png":::
314
465
466
+
#### [CLI](#tab/cli)
467
+
468
+
You can view the details of the virtual endpoint using either the [`list`](/cli/azure/postgres/flexible-server/virtual-endpoint#az-postgres-flexible-server-virtual-endpoint-list) or [`show`](/cli/azure/postgres/flexible-server/virtual-endpoint#az-postgres-flexible-server-virtual-endpoint-show) command. Given that only one virtual endpoint is allowed per primary-replica pair, both commands will yield the same result.
469
+
470
+
Here's an example of how to use the `list` command:
471
+
472
+
```azurecli-interactive
473
+
az postgres flexible-server virtual-endpoint list \
474
+
--resource-group <resource-group> \
475
+
--server-name <server-name>
476
+
```
477
+
478
+
Replace `<server-name>` with the name of your primary server and `<resource-group>` with the name of your resource group.
479
+
480
+
Here's how you can use the `show` command:
481
+
482
+
```azurecli-interactive
483
+
az postgres flexible-server virtual-endpoint show \
484
+
--name <virtual-endpoint-name>
485
+
--resource-group <resource-group> \
486
+
--server-name <server-name>
487
+
```
488
+
In this command, replace `<virtual-endpoint-name>`,`<server-name>`, and `<resource-group>` with the respective names. `<server-name>` is the name of your primary server.
489
+
315
490
#### [REST API](#tab/restapi)
316
491
317
492
```http request
@@ -350,6 +525,20 @@ To promote replica from the Azure portal, follow these steps:
350
525
351
526
6. Select **Promote** to begin the process. Once it's completed, the roles reverse: the replica becomes the primary, and the primary will assume the role of the replica.
352
527
528
+
#### [CLI](#tab/cli)
529
+
530
+
When promoting a replica to a primary server in Azure PostgreSQL Flexible Server, use the `az postgres flexible-server replica promote` command. This process is essential for elevating a replica server to function as the primary server and demotion of current primary to replica role. Specify `--promote-mode switchover` and `--promote-option planned` in the command.
531
+
532
+
```azurecli-interactive
533
+
az postgres flexible-server replica promote \
534
+
--resource-group <resource-group> \
535
+
--name <replica-server-name> \
536
+
--promote-mode switchover \
537
+
--promote-option planned
538
+
```
539
+
540
+
Replace `<resource-group>` and `<replica-server-name>` with your specific resource group and replica server name. This command ensures a smooth transition of the replica to a primary role in a planned manner.
541
+
353
542
#### [REST API](#tab/restapi)
354
543
355
544
When promoting a replica to a primary server, use an `HTTP PATCH` request with a specific `JSON` body to set the promotion options. This process is crucial when you need to elevate a replica server to act as the primary server.
@@ -401,6 +590,20 @@ Repeat the same operations to promote the original server to the primary.
401
590
402
591
6. Select **Promote**, the process begins. Once it's completed, the roles reverse: the replica becomes the primary, and the primary will assume the role of the replica.
403
592
593
+
#### [CLI](#tab/cli)
594
+
595
+
This time, change the `<replica-server-name>` in the `az postgres flexible-server replica promote` command to refer to your old primary server, which is currently acting as a replica, and execute the request again.
596
+
597
+
```azurecli-interactive
598
+
az postgres flexible-server replica promote \
599
+
--resource-group <resource-group> \
600
+
--name <replica-server-name> \
601
+
--promote-mode switchover \
602
+
--promote-option planned
603
+
```
604
+
605
+
Replace `<resource-group>` and `<replica-server-name>` with your specific resource group and current replica server name.
606
+
404
607
#### [REST API](#tab/restapi)
405
608
406
609
This time, change the `{replicaserverName}` in the API request to refer to your old primary server, which is currently acting as a replica, and execute the request again.
@@ -457,6 +660,21 @@ Create a secondary read replica in a separate region to modify the reader virtua
457
660
458
661
:::image type="content" source="./media/how-to-read-replicas-portal/primary-updating.png" alt-text="Screenshot of primary entering into updating status." lightbox="./media/how-to-read-replicas-portal/primary-updating.png":::
459
662
663
+
#### [CLI](#tab/cli)
664
+
665
+
You can create a secondary read replica by using the [`az postgres flexible-server replica create`](/cli/azure/postgres/flexible-server/replica#az-postgres-flexible-server-replica-create) command.
666
+
667
+
```azurecli-interactive
668
+
az postgres flexible-server replica create \
669
+
--replica-name <replica-name> \
670
+
--resource-group <resource-group> \
671
+
--source-server <source-server-name> \
672
+
--location <location>
673
+
```
674
+
675
+
Choose a distinct name for `<replica-name>` to differentiate it from the primary server and any other replicas.
676
+
Replace `<resource-group>`, `<source-server-name>` and `<location>` with your specific values.
677
+
460
678
#### [REST API](#tab/restapi)
461
679
462
680
You can create a secondary read replica by using the [create API](/rest/api/postgresql/flexibleserver/servers/create):
@@ -499,6 +717,21 @@ The location is set to `westus3`, but you can adjust this based on your geograph
499
717
500
718
5. Select **Save**. The reader endpoint will now be pointed at the secondary replica, and the promote operation will now be tied to this replica.
501
719
720
+
#### [CLI](#tab/cli)
721
+
722
+
You can now modify your reader endpoint to point to the newly created secondary replica by using a `az postgres flexible-server virtual-endpoint update` command. Remember to replace `<replica-name>` with the name of the newly created read replica.
723
+
724
+
```azurecli-interactive
725
+
az postgres flexible-server virtual-endpoint update \
726
+
--resource-group <resource-group> \
727
+
--server-name <server-name> \
728
+
--name <virtual-endpoint-name> \
729
+
--endpoint-type ReadWrite \
730
+
--members <replica-name>
731
+
```
732
+
733
+
Replace `<resource-group>`, `<server-name>`, `<virtual-endpoint-name>` and `<replica-name>` with your specific values.
734
+
502
735
#### [REST API](#tab/restapi)
503
736
504
737
You can now modify your reader endpoint to point to the newly created secondary replica by using a `PATCH` request. Remember to replace `{replicaserverName}` with the name of the newly created read replica.
@@ -541,6 +774,20 @@ Rather than switchover to a replica, it's also possible to break the replication
541
774
6. Select **Promote**, the process begins. Once completed, the server will no longer be a replica of the primary.
542
775
543
776
777
+
#### [CLI](#tab/cli)
778
+
779
+
When promoting a replica in Azure PostgreSQL Flexible Server, the default behavior is to promote it to an independent server. This is achieved using the [`az postgres flexible-server replica promote`](/cli/azure/postgres/flexible-server/replica#az-postgres-flexible-server-replica-promote) command without specifying the `--promote-mode` option, as `standalone` mode is assumed by default.
780
+
781
+
```azurecli-interactive
782
+
az postgres flexible-server replica promote \
783
+
--resource-group <resource-group> \
784
+
--name <replica-server-name>
785
+
```
786
+
787
+
In this command, replace `<resource-group>` and `<replica-server-name>` with your specific resource group name and the name of the first replica server that you created, that is not part of virtual endpoint anymore.
788
+
789
+
790
+
544
791
#### [REST API](#tab/restapi)
545
792
546
793
You can promote a replica to a standalone server using a `PATCH` request. To do this, send a `PATCH` request to the specified Azure Management REST API URL with the first `JSON` body, where `PromoteMode` is set to `standalone` and `PromoteOption` to `planned`. The second `JSON` body format, setting `ReplicationRole` to `None`, is deprecated but still mentioned here for backward compatibility.
4. A delete confirmation dialog will appear. It will warn you: "This action will delete the virtual endpoint `virtualendpointName`. Any clients connected using these domains may lose access." Acknowledge the implications and confirm by clicking on **Delete**.
589
836
590
837
838
+
#### [CLI](#tab/cli)
839
+
840
+
To remove a virtual endpoint from an Azure PostgreSQL Flexible Server, you can use the [`az postgres flexible-server virtual-endpoint delete`](/cli/azure/postgres/flexible-server/virtual-endpoint#az-postgres-flexible-server-virtual-endpoint-delete) command. This action permanently deletes the specified virtual endpoint.
841
+
842
+
```azurecli-interactive
843
+
az postgres flexible-server virtual-endpoint delete \
844
+
--resource-group <resource-group> \
845
+
--server-name <server-name> \
846
+
--name <virtual-endpoint-name>
847
+
```
848
+
849
+
In this command, replace `<resource-group>`, `<server-name>`, and `<virtual-endpoint-name>` with your specific resource group, server name, and the name of the virtual endpoint you wish to delete.
850
+
851
+
591
852
#### [REST API](#tab/restapi)
592
853
593
854
To delete a virtual endpoint in a preview environment using Azure's REST API, you would issue an `HTTP DELETE` request. The request URL would be structured as follows:
@@ -596,7 +857,6 @@ To delete a virtual endpoint in a preview environment using Azure's REST API, yo
@@ -621,6 +881,17 @@ You can also delete the read replica from the **Replication** window by followin
621
881
622
882
5. Acknowledge **Delete** operation.
623
883
884
+
#### [CLI](#tab/cli)
885
+
To delete a primary or replica server, use the [`az postgres flexible-server delete`](/cli/azure/postgres/flexible-server#az-postgres-flexible-server-delete) command. If server has read replicas then read replicas should be deleted first before deleting the primary server.
886
+
887
+
```azurecli-interactive
888
+
az postgres flexible-server delete \
889
+
--resource-group <resource-group> \
890
+
--name <server-name>
891
+
```
892
+
893
+
Replace `<resource-group>` and `<server-name>` with the name of your resource group name and the replica server name you wish to delete.
894
+
624
895
#### [REST API](#tab/restapi)
625
896
To delete a primary or replica server, use the [delete API](/rest/api/postgresql/flexibleserver/servers/delete). If server has read replicas then read replicas should be deleted first before deleting the primary server.
626
897
@@ -648,6 +919,17 @@ To delete a server from the Azure portal, follow these steps:
648
919
649
920
:::image type="content" source="./media/how-to-read-replicas-portal/delete-primary-confirm.png" alt-text="Screenshot of confirming to delete the primary server.":::
650
921
922
+
#### [CLI](#tab/cli)
923
+
To delete a primary or replica server, use the [`az postgres flexible-server delete`](/cli/azure/postgres/flexible-server#az-postgres-flexible-server-delete) command. If server has read replicas then read replicas should be deleted first before deleting the primary server.
924
+
925
+
```azurecli-interactive
926
+
az postgres flexible-server delete \
927
+
--resource-group <resource-group> \
928
+
--name <server-name>
929
+
```
930
+
931
+
Replace `<resource-group>` and `<server-name>` with the name of your resource group name and the primary server name you wish to delete.
932
+
651
933
#### [REST API](#tab/restapi)
652
934
To delete a primary or replica server, use the [delete API](/rest/api/postgresql/flexibleserver/servers/delete). If server has read replicas then read replicas should be deleted first before deleting the primary server.
0 commit comments