World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
[#11122 ][#11112] docs(upgrade): Improve PostgreSQL backup format and add rollback instructions (#11461)
Danhua Wangfcb3bb4c5b12
diff --git a/docs/how-to-upgrade.md b/docs/how-to-upgrade.mdindex ba1563bce2..26b63ba3c9 100644--- a/docs/how-to-upgrade.md+++ b/docs/how-to-upgrade.md@@ -49,14 +49,18 @@ by creating a copy of the directory containing your database.For PostgreSQL, you can use the following command to backup your database:```shell-pg_dump -U username -h hostname -d database_name -n schema_name -a -F c -f data_backup.sql+pg_dump -U username -h hostname -d database_name -n schema_name -Fc -f data_backup.dump```+The `-Fc` option produces a compressed binary dump in PostgreSQL's+custom format, which can be restored with `pg_restore`. Unlike a+schema-only dump, this backup includes both schema and data, which+is necessary for a full rollback.If you are running an Iceberg REST Catalog (IRC) service backed by a separate PostgreSQL database,back it up as well:```shell-pg_dump -U username -h hostname -d irc_database_name -n schema_name -a -F c -f data_backup_irc.sql+pg_dump -U username -h hostname -d irc_database_name -n schema_name -Fc -f data_backup_irc.dump```### Step 3: Dump the Gravitino Database@@ -86,9 +90,13 @@ Note that you may need to specify your h2 file path, username and passwordFor PostgreSQL, you can use the following command to dump the database schema to a file:```shell-pg_dump -U username -h hostname -d database_name -n schema_name -s -F c -f schema-x.y.z-postgresql.sql+pg_dump -U username -h hostname -d database_name -n schema_name -s -f schema-x.y.z-postgresql.sql```+Note: The `-s` flag dumps schema-only in plain SQL format. This is+different from the `-Fc` custom format used in Step 2 for backup,+which produces a binary dump that must be restored with `pg_restore`.+### Step 4: Determine Differences Between the Existing Schema and the Official SchemaThe schema upgrade scripts assume that the schema you are upgrading@@ -98,8 +106,12 @@ Gravitino. The files in this directory with names likecorresponding to each of the released versions of Gravitino. You candetermine differences between your schema and the official schemaby comparing the contents of the official dump with the schema dump-you created in the previous step. Some differences are acceptable and will not interfere-with the upgrade process, but others need to be resolved manually+you created in the previous step.++Some differences are acceptable and will not interfere+with the upgrade process, such as differences in object ordering or+comments. However, differences in table structures, column types, or+missing tables/indexes need to be resolved manuallyor the upgrade scripts will fail to complete.### Step 5: Apply the Upgrade Scripts@@ -206,4 +218,51 @@ Confirm the running image tag matches the target version:kubectl get pods -n <namespace> -o jsonpath='{.items[*].spec.containers[*].image}'```+## Rollback if Upgrade Fails++> **Important:** Stop the Gravitino server before restoring the database+> to avoid data corruption from concurrent writes.++If you encounter errors during the upgrade process, you can+restore your database from the backup created in Step 2.++### MySQL++Use the backup file to restore your database. The `mysqldump`+backup contains `DROP TABLE` statements by default (via `--opt`),+so it will replace the upgraded tables automatically:++```shell+mysql -u username -h hostname --database=db_name < backup.sql+```++### H2++Replace the current database directory with the copy you made+during the backup step:++```shell+rm -rf <db_directory>+cp -r <db_directory_backup> <db_directory>+```++### PostgreSQL++Use `pg_restore` with `--clean` to drop existing objects before+restoring them in one transaction. This is safer than manually+dropping the schema first:++```shell+pg_restore -U username -h hostname -d database_name -n schema_name --clean --if-exists --single-transaction data_backup.dump+```++Note: `pg_restore --clean` only drops objects that are present in the+dump file. If the upgrade scripts added new tables or sequences not+present in the backup, those objects will not be removed automatically.+Verify the schema matches the expected state after restoring.++After restoring, verify that your Gravitino instance starts+successfully with the restored database before attempting the+upgrade again.+<img src="https://analytics.apache.org/matomo.php?idsite=62&rec=1&bots=1&action_name=HowToUpgrade" alt="" />