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/single-server/how-to-upgrade-using-dump-and-restore.md
+20-12Lines changed: 20 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -43,7 +43,7 @@ To step through this how-to-guide, you need:
43
43
44
44
- A **source** PostgreSQL database server running a lower version of the engine that you want to upgrade.
45
45
- 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.
47
47
- 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.
48
48
- 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.
49
49
- 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
72
72
| Target user name | pg@pg-11 |
73
73
74
74
>[!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.
76
76
77
77
## Upgrade your databases using offline migration methods
78
78
79
79
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.
80
80
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).
82
82
83
83
- 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.`
84
84
85
85
- 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.
86
86
87
87
>[!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.
89
89
90
90
### Migrate the Roles
91
91
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**:
> 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
+
99
107
Edit the `roles.sql` and remove references of `NOSUPERUSER` and `NOBYPASSRLS` before restoring the content using psql in the target server:
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`.
106
114
107
115
### Method 1: Using pg_dump and psql
108
116
@@ -114,9 +122,9 @@ In this method of upgrade, you first create a dump from the source server using
114
122
115
123
### Method 3: Using streaming the dump data to the target database
116
124
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.
118
126
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.
@@ -138,7 +146,7 @@ If you do not have a PostgreSQL client or you want to use Azure Cloud Shell, the
138
146
3. Once the upgrade (migration) process completes, you can test your application with the target server.
139
147
4. Repeat this process for all the databases within the server.
140
148
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.
142
150
143
151
| **Database Size** | **Approx. time taken** |
144
152
| ----- | ------ |
@@ -210,4 +218,4 @@ ANALYZE
210
218
- 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.
211
219
212
220
>[!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 forproduction. 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 addedin the new version. Differences between versions can be found [here](https://www.postgresql.org/docs/release/).
0 commit comments