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
<1> The name of the instance you want to restore from
55
56
<2> The backup name you want to restore
57
+
<3> Optional: Point-in-time recovery timestamp. Must be *after* the backup time (in this example, after `2023-03-01 16:52:02`). If omitted, restores to the latest available state.
56
58
57
59
[NOTE]
58
60
====
@@ -64,3 +66,183 @@ The only difference is the backup information in `spec.parameters.restore`.
64
66
65
67
The deletion process of a restored instance is the same as for normal instance.
66
68
Check out xref:vshn-managed/postgresql/delete.adoc[this guide] how to delete a PostgreSQL instance.
69
+
70
+
== Restore a single database
71
+
72
+
This procedure allows you to restore a specific database from a backup to a running VSHNPostgreSQL instance. This is useful when you only need to recover one database instead of restoring an entire instance.
73
+
74
+
=== Overview
75
+
76
+
The restore process involves the following steps:
77
+
78
+
1. Create a temporary VSHNPostgreSQL instance for the restore
79
+
2. Restore the full backup into this temporary instance using the standard restore procedure above
80
+
3. Copy the specific database from the temporary instance to your target instance
81
+
4. Clean up by deleting the temporary instance
82
+
83
+
=== Prerequisites
84
+
85
+
* A running VSHNPostgreSQL instance (the target where you want to restore the database)
86
+
* Access to the backup you want to restore from
87
+
88
+
=== Procedure
89
+
90
+
First, create a new temporary VSHNPostgreSQL instance and restore the full backup into it using the steps documented above in "Restore a Backup".
91
+
92
+
Next, use the following script to copy the specific database from the temporary instance to your target instance.
93
+
94
+
The script performs the following actions:
95
+
96
+
* Creates a temporary pod with the PostgreSQL client tools
97
+
* Connects the pod to both the temporary instance (source) and target instance (destination)
98
+
* Uses `pg_dump` to export the database from the temporary instance
99
+
* Pipes the dump directly into the target instance
100
+
* Displays table statistics before and after to verify the migration
\"ANALYZE;SELECT relname AS table_name, n_live_tup AS row_estimate FROM pg_stat_user_tables ORDER BY n_live_tup DESC;\""
227
+
228
+
229
+
if [[ $? -ne 0 ]]; then
230
+
echo "Error: pg_dump failed. Check pod logs for details."
231
+
kubectl logs "$POD_NAME" --namespace="$NAMESPACE"
232
+
echo "Pod '$POD_NAME' retained for debugging. Delete manually when done."
233
+
exit 1
234
+
fi
235
+
236
+
echo "Database '$DB_NAME' successfully migrated"
237
+
238
+
echo "Deleting pod '$POD_NAME'..."
239
+
kubectl delete pod "$POD_NAME" --namespace="$NAMESPACE" --grace-period=0 --force
240
+
241
+
if [[ $? -eq 0 ]]; then
242
+
echo "Pod '$POD_NAME' deleted successfully."
243
+
else
244
+
echo "Warning: Failed to delete pod '$POD_NAME'. You may need to delete it manually."
245
+
fi
246
+
----
247
+
248
+
After the script completes successfully, the database has been copied from the temporary instance to your target instance. You can now deprovision the temporary restore instance as it is no longer needed.
0 commit comments