Skip to content

Commit d5d5229

Browse files
authored
Merge pull request #299021 from AbhishekMallick01/Apr-29-2025-PSQLFlex
PSQL Flex DB restore updates
2 parents 0fd89f4 + 7270054 commit d5d5229

File tree

3 files changed

+87
-33
lines changed

3 files changed

+87
-33
lines changed

articles/backup/backup-azure-database-postgresql-flex-support-matrix.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Azure Database for PostgreSQL- Flexible server support matrix
33
description: Provides a summary of support settings and limitations of Azure Database for PostgreSQL- Flexible server backup.
44
ms.topic: reference
5-
ms.date: 04/11/2025
5+
ms.date: 04/30/2025
66
ms.custom: references_regions, ignite-2024
77
ms.service: azure-backup
88
author: jyothisuri
@@ -41,6 +41,22 @@ Azure Database for PostgreSQL – Flexible Server backups include the following
4141
- Vaulted backups support full backups only; incremental or differential backups aren't supported.
4242

4343

44+
### Restore limitations
45+
- The use of **create role** scripts for `azure_su`, `azure_pg_admin`, `replication`, `localadmin`, and `Entra Admin` causes the following errors during restoration on another flexible server, which you can safely ignore.
46+
47+
- `role "azure_pg_admin" already exists.`
48+
- `role "azuresu" already exists.`
49+
- `role "replication" already exists.`
50+
- `ERROR: must be superuser to create superusers`
51+
- `ERROR: Only roles with privileges of role "azuresu" may grant privileges as this role. permission denied granting privileges as role "azuresu"`
52+
- `ERROR: permission denied granting privileges as role "azuresu" SQL state: 42501 Detail: Only roles with privileges of role "azuresu" may grant privileges.`
53+
- `Ignore any errors related to pg_catalog, pg _aadauth extensions as it is owned by azure_su and localadmin does not have access to directly create this extension on flexible server, but these are automatically created on new flexible servers or when you enable Microsoft entra authentication.`
54+
- `ERROR: Only roles with the ADMIN option on role "pg_use_reserved_connections" may grant this role. permission denied to grant role "pg_use_reserved_connections"`
55+
- `ERROR: permission denied to grant role "pg_use_reserved_connections" SQL state: 42501 Detail: Only roles with the ADMIN option on role "pg_use_reserved_connections" may grant this role.`
56+
57+
- In PostgreSQL **community version 16**, the requirement for superuser privileges to set the Bypass Row -level security (RLS) attribute was removed. So, in versions 16 and higher, you can grant the Bypass RLS to azure_pg_admin allowing others to set the RLS. For versions lower than 16, the bypasses attribute is granted only to the server admin and no other nonsuperuser roles.
58+
- If you're using Entra Admins after restoration, you might encounter the **Owner Change Issue** : As a workaround, use the **grant** option to provide ownership.
59+
4460

4561
## Next steps
4662

170 KB
Loading
Lines changed: 70 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
---
2-
title: Restore Azure Database for PostgreSQL -Flexible server using Azure portal
3-
description: Learn about how to restore Azure Database for PostgreSQL -Flexible backups.
2+
title: Restore Azure PostgreSQL-Flexible server as Files using Azure portal
3+
description: Learn about how to restore Azure PostgreSQL-Flexible server as Files.
44
ms.topic: how-to
5-
ms.date: 03/18/2025
5+
ms.date: 04/30/2025
66
ms.service: azure-backup
77
ms.custom:
88
- ignite-2024
99
author: jyothisuri
1010
ms.author: jsuri
1111
---
1212

13-
# Restore Azure Database for PostgreSQL - Flexible Server using Azure portal
13+
# Restore Azure PostgreSQL-Flexible server as Files using Azure portal
1414

15-
This article describes how to restore an Azure PostgreSQL -Flexible Server backed up using Azure portal.
15+
This article describes how to restore an Azure PostgreSQL-Flexible server as Files backed up using Azure portal.
1616

1717
## Prerequisites
1818

@@ -26,7 +26,10 @@ Before you restore from Azure Database for PostgreSQL Flexible server backups, r
2626

2727
## Restore Azure PostgreSQL-Flexible database
2828

29-
Follow these steps:
29+
>[!Note]
30+
>The restore operation transfers all PostgreSQL – flexible server databases to a designated storage account container. After restoration, move the files to a new or existing PostgreSQL – Flexible server.
31+
32+
To restore Azure PostgreSQL-Flexible database, Follow these steps:
3033

3134
1. Go to **Backup vault** > **Backup Instances**. Select the PostgreSQL - Flexible server to be restored and select **Restore**.
3235

@@ -49,41 +52,76 @@ Follow these steps:
4952
1. Submit the Restore operation and track the triggered job under **Backup jobs**.
5053
:::image type="content" source="./media/restore-azure-database-postgresql-flex/validate.png" alt-text="Screenshot showing the validate process page.":::
5154

52-
1. Once the job is finished, the backed-up data is restored into the storage account. Below are the set of files recovered in your storage account after the restore:
5355

54-
- The first file is a marker or timestamp file that gives the customer the time the backup was taken at. The file cannot be restored but if opened with a text editor should tell the customer the UTC time when the backup was taken.
55-
56-
- The Second file **_database_** is an individual database backup for database called tempdata2 taken using pg_dump. Each database has a separate file with format **– {backup_name}_database_{db_name}.sql**
57-
58-
- The Third File **_roles**. Has roles backed up using pg_dumpall
59-
60-
- The Fourth file **_schemas**. backed up using pg_dumpall
61-
62-
- The Fifth file **_tablespaces**. Has the tablespaces backed up using pg_dumpall
56+
After the restore job is completed successfully, go to the storage account container to view the restored databases as files (`.sql` files) from your PostgreSQL – Flexible server. Azure Backup also generates the following backup files:
6357

64-
1. Post restoration completion to the target storage account, you can use pg_restore utility to restore the database and other files to a PostgreSQL Flexible server. Use the following command to connect to an existing postgresql flexible server and an existing database
58+
- `Database.sql file` per database: Contains data and schema information for a particular database.
59+
- `Roles.sql files` for entire instance: Contains all role information ((azure_su(superuser) azure_pg_admin, replication, local admin, Microsoft Entra admins and any other custom roles on the server)) that exists at server level.
60+
- `Tablespace.sql file`: Tablespace file.
61+
- `Schema.sql file`: Contains schema information for all the databases on the server.
6562

66-
`az storage blob download --container-name <container-name> --name <blob-name> --account-name <storage-account-name> --account-key <storage-account-key> --file - | pg_restore -h <postgres-server-url> -p <port> -U <username> -d <database-name> -v -`
63+
>[!Note]
64+
>We recommend you not to run this script on the PostgreSQL - Flexible server because the schema is already part of the `database.sql` script.
6765
68-
* `--account-name`: Name of the Target Storage Account.
69-
* `--container-name`: Name of the blob container.
70-
* `--blob-name`: Name of the blob.
71-
* `--account-key`: Storage Account Key.
72-
* `-Fd`: The directory format.
73-
* `-j`: The number of jobs.
74-
* `-C`: Begin the output with a command to create the database itself and then reconnect to it.
66+
:::image type="content" source="./media/restore-azure-database-postgresql-flex/database-files.png" alt-text="Screenshot shows the database schema per database." lightbox="./media/restore-azure-database-postgresql-flex/database-files.png":::
7567

76-
If you have more than one database to restore, re-run the earlier command for each database.
68+
## Restore the backup files from storage container to a new or existing PostgreSQL – Flexible server
7769

78-
Also, by using multiple concurrent jobs `-j`, you can reduce the time it takes to restore a large database on a multi-vCore target server. The number of jobs can be equal to or less than the number of vCPUs that are allocated for the target server.
70+
To restore the backup files from storage container to a new or existing PostgreSQL – Flexible server, follow these steps:
7971

80-
1. To restore the other three files (roles, schema and tablespaces), use the psql utility to restore them to a PostgreSQL Flexible server.
72+
1. Ensure that all required [extensions are enabled](/azure/postgresql/extensions/how-to-allow-extensions?tabs=allow-extensions-portal) on the new target Flexible server.
73+
1. [Match the server parameter](/azure/postgresql/flexible-server/how-to-server-parameters-list-all?tabs=portal-list) values from the source PostgreSQL database to the Azure Database for PostgreSQL by accessing the **Server parameters** section in the Azure portal and manually updating the values accordingly. Save the parameter changes, and then restart the Azure Database for PostgreSQL - Flexible server to apply the new configuration.
74+
1. If **Microsoft Entra Authentication** is required on the new server, enable it and create the relevant Microsoft Entra admins.
75+
1. Create a new database for restoration.
8176

82-
`az storage blob download --container-name <container-name> --name <blob-name> --account-name <storage-account-name> --account-key <storage-account-key> --file -
83-
| psql -h <hostname> -U <username> -d <db name> -f <dump directory> -v -`
77+
>[!Note]
78+
>Before the database restoration, you must create a new, empty database. Ensure that your user account has the **`CREATEDB`** permission.
79+
>
80+
>To create the database, use the `CREATE DATABASE Database_name` command.
8481
85-
Re-run the above command for each file.
82+
1. Restore the database using the `database.sql file` as the target admin user.
83+
1.After the target database is created, restore the data in this database (from the dump file) from an Azure storage account by running the following command:
84+
85+
```azurecli-interactive
86+
az storage blob download --container-name <container-name> --name <blob-name> --account-name <storage-account-name> --account-key <storage-account-key> --file - | pg_restore -h <postgres-server-url> -p <port> -U <username> -d <database-name> --no-owner -v –
87+
```
88+
89+
- `--account-name`: Name of the Target Storage Account.
90+
- `--container-name`: Name of the blob container.
91+
- `--blob-name`: Name of the blob.
92+
- `--account-key`: Storage Account Key.
93+
- `-Fd`: The directory format.
94+
- `-j`: The number of jobs.
95+
- `-C`: Begin the output with a command to create the database itself and then reconnect to it.
8696

87-
## Next steps
97+
Alternatively, you can download the backup file and run the restore directly.
98+
99+
1. Restore only the required roles and privileges, and ignore the [common errors](backup-azure-database-postgresql-flex-support-matrix.md#restore-limitations). Skip this step if you're performing the restoration for compliance requirements and data retrieval, as a local admin.
100+
101+
## Restore roles and users for the restored databases
102+
103+
Vaulted backups are primarily restored for compliance needs such as, testing and audits. You can sign in as a local admin and restore using the `database.sql` file; no other roles are needed for data retrieval.
104+
105+
For other uses like accidental deletion protection or disaster recovery, ensure necessary roles are created as per your organization needs. Avoid duplications between `roles.sql` and `database.sql`.
106+
107+
- **Restore the same Flexible server**: Role restoration might not be necessary.
108+
- **Restore to a different Flexible server**: Use the `roles.sql` file to recreate the required roles.
109+
110+
When you restore from `roles.sql`, some roles or attributes might not be valid for the new target server.
111+
112+
For environments with superuser access (on-premises or VMs), you can run all commands seamlessly.
113+
114+
### Key considerations for the Flexible server scenario
115+
116+
Here are the key considerations:
117+
118+
- **Remove Superuser-Only Attributes**: On Flexible server, there's no superuser privileges. So, remove attributes, such as `NOSUPERUSER` and `NOBYPASSRLS` from the roles dump.
119+
- **Exclude Service-Specific Users**: Exclude users specific to Flexible Server services (` azure_su`, `azure_pg_admin`, `replication`, `localadmin`, `Entra Admin`). These specific service roles are automatically recreated when administrators are added to the new Flexible server.
120+
121+
Before you restore the database objects, ensure that you properly dump and clean up the roles. To perform this action, download the `roles.sql`script from your storage container and create all required logins.
122+
- **Create Non-Entra Roles**: Use a local admin account to run the role creation scripts.
123+
- **Create Microsoft Entra Roles**: If you need to create roles for Microsoft Entra users, use a Microsoft Entra administrator account to run the necessary scripts.
124+
125+
## Next steps
88126

89127
[Manage backup of Azure PostgreSQL - Flexible Server using Azure portal](backup-azure-database-postgresql-flex-manage.md).

0 commit comments

Comments
 (0)