Skip to content

Commit fe55cdd

Browse files
authored
Merge pull request #227585 from AwdotiaRomanowna/patch-21
dumping roles on FLex
2 parents 1a5ae19 + c800884 commit fe55cdd

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

articles/postgresql/single-server/how-to-upgrade-using-dump-and-restore.md

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ To step through this how-to-guide, you need:
4343

4444
- A **source** PostgreSQL database server running a lower version of the engine that you want to upgrade.
4545
- A **target** PostgreSQL database server with the desired major version [Azure Database for PostgreSQL server - Single Server](quickstart-create-server-database-portal.md) or [Azure Database for PostgreSQL - Flexible Server](../flexible-server/quickstart-create-server-portal.md).
46-
- A PostgreSQL client system to run the dump and restore commands. It is recommended to use the higher database version. For example, if you are upgrading from PostgreSQL version 9.6 to 11, please use PostgreSQL version 11 client.
46+
- A PostgreSQL client system to run the dump and restore commands. It's recommended to use the higher database version. For example, if you're upgrading from PostgreSQL version 9.6 to 11, please use PostgreSQL version 11 client.
4747
- It can be a Linux or Windows client that has PostgreSQL installed and that has the [pg_dump](https://www.postgresql.org/docs/current/static/app-pgdump.html) and [pg_restore](https://www.postgresql.org/docs/current/static/app-pgrestore.html) command-line utilities installed.
4848
- Alternatively, you can use [Azure Cloud Shell](https://shell.azure.com) or by selecting the Azure Cloud Shell on the menu bar at the upper right in the [Azure portal](https://portal.azure.com). You will have to login to your account `az login` before running the dump and restore commands.
4949
- Your PostgreSQL client preferably running in the same region as the source and target servers.
@@ -72,37 +72,45 @@ In this guide, the following source and target servers and database names are us
7272
| Target user name | pg@pg-11 |
7373

7474
>[!NOTE]
75-
> Flexible server supports PostgreSQL version 11 onwards. Also, flexible server user name does not require @dbservername.
75+
> Flexible server supports PostgreSQL version 11 onwards. Also, flexible server user name doesn't require @dbservername.
7676
7777
## Upgrade your databases using offline migration methods
7878

7979
You may choose to use one of the methods described in this section for your upgrades. You can use the following tips while performing the tasks.
8080

81-
- If you are using the same password for source and the target database, you can set the `PGPASSWORD=yourPassword` environment variable. Then you don’t have to provide password every time you run commands like psql, pg_dump, and pg_restore. Similarly you can setup additional variables like `PGUSER`, `PGSSLMODE` etc. see to [PostgreSQL environment variables](https://www.postgresql.org/docs/11/libpq-envars.html).
81+
- If you're using the same password for source and the target database, you can set the `PGPASSWORD=yourPassword` environment variable. Then you don’t have to provide password every time you run commands like psql, pg_dump, and pg_restore. Similarly you can setup additional variables like `PGUSER`, `PGSSLMODE` etc. see to [PostgreSQL environment variables](https://www.postgresql.org/docs/11/libpq-envars.html).
8282

8383
- If your PostgreSQL server requires TLS/SSL connections (on by default in Azure Database for PostgreSQL servers), set an environment variable `PGSSLMODE=require` so that the pg_restore tool connects with TLS. Without TLS, the error may read `FATAL: SSL connection is required. Please specify SSL options and retry.`
8484

8585
- In the Windows command line, run the command `SET PGSSLMODE=require` before running the pg_restore command. In Linux or Bash run the command `export PGSSLMODE=require` before running the pg_restore command.
8686

8787
>[!Important]
88-
> The steps and methods provided in this document are to give some examples of pg_dump/pg_restore commands and do not represent all possible ways to perform upgrades. It is recommended to test and validate the commands in a test environment before you use them in production.
88+
> The steps and methods provided in this document are to give some examples of pg_dump/pg_restore commands and don't represent all possible ways to perform upgrades. It's recommended to test and validate the commands in a test environment before you use them in production.
8989
9090
### Migrate the Roles
9191

92-
Roles (Users) are global objects and needed to be migrated separately to the new cluster before restoring the database. You can use `pg_dumpall` binary with -r (--roles-only) option to dump them.
93-
To dump all the roles from the source server:
92+
Roles (Users) are global objects and needed to be migrated separately to the new cluster **before** restoring the database(s). You can use `pg_dumpall` binary with -r (--roles-only) option to dump them.
93+
To dump all the roles **with passwords** from the source **Single Server**:
9494

9595
```azurecli-interactive
96-
pg_dumpall -r --host=mySourceServer --port=5432 --username=myUser --database=mySourceDB > roles.sql
96+
pg_dumpall -r --host=mySourceServer --port=5432 --username=myUser@mySourceServer --database=mySourceDB > roles.sql
9797
```
9898

99+
To dump all the roles names, **without passwords** from the source **Flexible Server**:
100+
```azurecli-interactive
101+
pg_dumpall -r --no-role-passwords --host=mySourceServer --port=5432 --username=myUser --database=mySourceDB > roles.sql
102+
```
103+
104+
> [!IMPORTANT]
105+
> In Azure Database for PostgreSQL - Flexible Server users are not allowed to access pg_authid table which contains information about database authorization identifiers together with user's passwords. Therefore retrieving passwords for users is not possible. Please consider using [Azure Key Vault](../../key-vault/secrets/about-secrets.md) to securely store your secrets.
106+
99107
Edit the `roles.sql` and remove references of `NOSUPERUSER` and `NOBYPASSRLS` before restoring the content using psql in the target server:
100108

101109
```azurecli-interactive
102110
psql -f roles.sql --host=myTargetServer --port=5432 --username=myUser --dbname=postgres
103111
```
104112

105-
The dump script should not be expected to run completely without errors. In particular, because the script will issue CREATE ROLE for every role existing in the source cluster, it is certain to get a “role already exists” error for the bootstrap superuser like azure_pg_admin or azure_superuser. This error is harmless and can be ignored. Use of the `--clean` option is likely to produce additional harmless error messages about non-existent objects, although you can minimize those by adding `--if-exists`.
113+
The dump script shouldn't be expected to run completely without errors. In particular, because the script will issue CREATE ROLE for every role existing in the source cluster, it's certain to get a “role already exists” error for the bootstrap superuser like azure_pg_admin or azure_superuser. This error is harmless and can be ignored. Use of the `--clean` option is likely to produce additional harmless error messages about non-existent objects, although you can minimize those by adding `--if-exists`.
106114

107115
### Method 1: Using pg_dump and psql
108116

@@ -114,9 +122,9 @@ In this method of upgrade, you first create a dump from the source server using
114122

115123
### Method 3: Using streaming the dump data to the target database
116124

117-
If you do not have a PostgreSQL client or you want to use Azure Cloud Shell, then you can use this method. The database dump is streamed directly to the target database server and does not store the dump in the client. Hence, this can be used with a client with limited storage and even can be run from the Azure Cloud Shell.
125+
If you don't have a PostgreSQL client or you want to use Azure Cloud Shell, then you can use this method. The database dump is streamed directly to the target database server and doesn't store the dump in the client. Hence, this can be used with a client with limited storage and even can be run from the Azure Cloud Shell.
118126

119-
1. Make sure the database exists in the target server using `\l` command. If the database does not exist, then create the database.
127+
1. Make sure the database exists in the target server using `\l` command. If the database doesn't exist, then create the database.
120128
```azurecli-interactive
121129
psql "host=myTargetServer port=5432 dbname=postgres user=myUser password=###### sslmode=mySSLmode"
122130
```
@@ -138,7 +146,7 @@ If you do not have a PostgreSQL client or you want to use Azure Cloud Shell, the
138146
3. Once the upgrade (migration) process completes, you can test your application with the target server.
139147
4. Repeat this process for all the databases within the server.
140148
141-
As an example, the following table illustrates the time it took to migrate using streaming dump method. The sample data is populated using [pgbench](https://www.postgresql.org/docs/10/pgbench.html). As your database can have different number of objects with varied sizes than pgbench generated tables and indexes, it is highly recommended to test dump and restore of your database to understand the actual time it takes to upgrade your database.
149+
As an example, the following table illustrates the time it took to migrate using streaming dump method. The sample data is populated using [pgbench](https://www.postgresql.org/docs/10/pgbench.html). As your database can have different number of objects with varied sizes than pgbench generated tables and indexes, it's highly recommended to test dump and restore of your database to understand the actual time it takes to upgrade your database.
142150
143151
| **Database Size** | **Approx. time taken** |
144152
| ----- | ------ |
@@ -210,4 +218,4 @@ ANALYZE
210218
- For Azure Database for PostgreSQL - Single server only. If you want to use the same database endpoint as the source server, then after you had deleted your old source database server, you can create a read replica with the old database server name. Once the steady replication state is established, you can stop the replica, which will promote the replica server to be an independent server. See [Replication](./concepts-read-replicas.md) for more details.
211219
212220
>[!Important]
213-
> It is highly recommended to test the new PostgreSQL upgraded version before using it directly for production. This includes comparing server parameters between the older source version source and the newer version target. Please ensure that they are same and check on any new parameters that were added in the new version. Differences between versions can be found [here](https://www.postgresql.org/docs/release/).
221+
> It's highly recommended to test the new PostgreSQL upgraded version before using it directly for production. This includes comparing server parameters between the older source version source and the newer version target. Please ensure that they are same and check on any new parameters that were added in the new version. Differences between versions can be found [here](https://www.postgresql.org/docs/release/).

0 commit comments

Comments
 (0)