Skip to content

Commit 1a36019

Browse files
Merge pull request #263165 from AlicjaKucharczyk/patch-4
cli
2 parents 7c8a346 + 10ca5ec commit 1a36019

File tree

1 file changed

+283
-1
lines changed

1 file changed

+283
-1
lines changed

articles/postgresql/flexible-server/how-to-read-replicas-portal.md

Lines changed: 283 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,127 @@ Before setting up a read replica for Azure Database for PostgreSQL, ensure the p
7676

7777
:::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":::
7878

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`).
98+
- Storage
99+
- Type
100+
- Storage size (ex `128`)
101+
- autoGrow
102+
- Network
103+
- High Availability
104+
- Enabled / Disabled
105+
- Availability zone settings
106+
- Backup settings
107+
- Retention period
108+
- Redundancy Options
109+
110+
**Sample response**
111+
112+
```json
113+
{
114+
"administratorLogin": "myadmin",
115+
"administratorLoginPassword": null,
116+
"authConfig": {
117+
"activeDirectoryAuth": "Disabled",
118+
"passwordAuth": "Enabled",
119+
"tenantId": null
120+
},
121+
"availabilityZone": "2",
122+
"backup": {
123+
"backupRetentionDays": 7,
124+
"earliestRestoreDate": "2024-01-06T11:43:44.485537+00:00",
125+
"geoRedundantBackup": "Disabled"
126+
},
127+
"createMode": null,
128+
"dataEncryption": {
129+
"geoBackupEncryptionKeyStatus": null,
130+
"geoBackupKeyUri": null,
131+
"geoBackupUserAssignedIdentityId": null,
132+
"primaryEncryptionKeyStatus": null,
133+
"primaryKeyUri": null,
134+
"primaryUserAssignedIdentityId": null,
135+
"type": "SystemManaged"
136+
},
137+
"fullyQualifiedDomainName": "{serverName}.postgres.database.azure.com",
138+
"highAvailability": {
139+
"mode": "Disabled",
140+
"standbyAvailabilityZone": null,
141+
"state": "NotEnabled"
142+
},
143+
"id": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/flexibleServers/{serverName}",
144+
"identity": null,
145+
"location": "East US",
146+
"maintenanceWindow": {
147+
"customWindow": "Disabled",
148+
"dayOfWeek": 0,
149+
"startHour": 0,
150+
"startMinute": 0
151+
},
152+
"minorVersion": "0",
153+
"name": "{serverName}",
154+
"network": {
155+
"delegatedSubnetResourceId": null,
156+
"privateDnsZoneArmResourceId": null,
157+
"publicNetworkAccess": "Enabled"
158+
},
159+
"pointInTimeUtc": null,
160+
"privateEndpointConnections": null,
161+
"replica": {
162+
"capacity": 5,
163+
"promoteMode": null,
164+
"promoteOption": null,
165+
"replicationState": null,
166+
"role": "Primary"
167+
},
168+
"replicaCapacity": 5,
169+
"replicationRole": "Primary",
170+
"resourceGroup": "{resourceGroupName}",
171+
"sku": {
172+
"name": "Standard_D8ads_v5",
173+
"tier": "GeneralPurpose"
174+
},
175+
"sourceServerResourceId": null,
176+
"state": "Ready",
177+
"storage": {
178+
"autoGrow": "Disabled",
179+
"iops": 500,
180+
"storageSizeGb": 128,
181+
"throughput": null,
182+
"tier": "P10",
183+
"type": ""
184+
},
185+
"systemData": {
186+
"createdAt": "2023-11-08T11:27:48.972812+00:00",
187+
"createdBy": null,
188+
"createdByType": null,
189+
"lastModifiedAt": null,
190+
"lastModifiedBy": null,
191+
"lastModifiedByType": null
192+
},
193+
"tags": {},
194+
"type": "Microsoft.DBforPostgreSQL/flexibleServers",
195+
"version": "16"
196+
}
197+
198+
```
199+
79200
#### [REST API](#tab/restapi)
80201

81202
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:
204325

205326
:::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":::
206327

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+
207343
#### [REST API](#tab/restapi)
208344

209345
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
274410
275411
:::image type="content" source="./media/how-to-read-replicas-portal/replica-promote-attempt.png" alt-text="Screenshot of promotion error when missing virtual endpoint.":::
276412

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+
277428
#### [REST API](#tab/restapi)
278429

279430
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
312463

313464
:::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":::
314465

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+
315490
#### [REST API](#tab/restapi)
316491

317492
```http request
@@ -350,6 +525,20 @@ To promote replica from the Azure portal, follow these steps:
350525

351526
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.
352527

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+
353542
#### [REST API](#tab/restapi)
354543

355544
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.
401590

402591
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.
403592

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+
404607
#### [REST API](#tab/restapi)
405608

406609
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
457660

458661
:::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":::
459662

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+
460678
#### [REST API](#tab/restapi)
461679

462680
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
499717

500718
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.
501719

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+
502735
#### [REST API](#tab/restapi)
503736

504737
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
541774
6. Select **Promote**, the process begins. Once completed, the server will no longer be a replica of the primary.
542775

543776

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+
544791
#### [REST API](#tab/restapi)
545792

546793
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.
@@ -588,6 +835,20 @@ PATCH https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups
588835
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**.
589836

590837

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+
591852
#### [REST API](#tab/restapi)
592853

593854
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
596857
DELETE https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBForPostgreSql/flexibleServers/{serverName}/virtualendpoints/{virtualendpointName}?api-version=2023-06-01-preview
597858
```
598859

599-
600860
---
601861

602862
## Delete a replica
@@ -621,6 +881,17 @@ You can also delete the read replica from the **Replication** window by followin
621881

622882
5. Acknowledge **Delete** operation.
623883

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+
624895
#### [REST API](#tab/restapi)
625896
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.
626897

@@ -648,6 +919,17 @@ To delete a server from the Azure portal, follow these steps:
648919

649920
:::image type="content" source="./media/how-to-read-replicas-portal/delete-primary-confirm.png" alt-text="Screenshot of confirming to delete the primary server.":::
650921

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+
651933
#### [REST API](#tab/restapi)
652934
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.
653935

0 commit comments

Comments
 (0)