From 32c979f885e03ed56e4c860558aeea88c83c5c3f Mon Sep 17 00:00:00 2001 From: tuannt12 Date: Fri, 15 May 2026 10:56:19 +0700 Subject: [PATCH] =?UTF-8?q?[docs]=20vDB=20=E2=80=94=20Add=20Stop=20Write?= =?UTF-8?q?=20step=20before=20dump=20=E2=80=94=20VI=20+=20EN?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...migrate-from-postgres-single-to-cluster.md | 54 ++++++++++++++++--- ...migrate-tu-postgres-single-sang-cluster.md | 54 ++++++++++++++++--- 2 files changed, 94 insertions(+), 14 deletions(-) diff --git a/English/vdb/relational-database-service-rds/postgresql/migrate-from-postgres-single-to-cluster.md b/English/vdb/relational-database-service-rds/postgresql/migrate-from-postgres-single-to-cluster.md index abf9a9f9..51a22fab 100644 --- a/English/vdb/relational-database-service-rds/postgresql/migrate-from-postgres-single-to-cluster.md +++ b/English/vdb/relational-database-service-rds/postgresql/migrate-from-postgres-single-to-cluster.md @@ -36,7 +36,27 @@ psql -h -U -d -c "SELECT 1;" *** -### Step 2 — Export the Database +### Step 2 — Stop Write Operations + +Before exporting, prevent any write operations to the source database to ensure a consistent snapshot. Some approaches: + +**Option 1 — Stop from the application:** Shut down or pause the application writing to the source database. + +**Option 2 — Set the source database to read-only:** + +```sql +ALTER DATABASE SET default_transaction_read_only = on; +``` + +Remember to revert this after the restore completes: + +```sql +ALTER DATABASE SET default_transaction_read_only = off; +``` + +*** + +### Step 3 — Export the Database Use `pg_dump` to export the source database. Choose the format that matches your preferred restore method. @@ -61,7 +81,7 @@ The custom format (`-Fc`) produces a compressed binary file and supports multi-j *** -### Step 3 — Restore on Postgres Cluster +### Step 4 — Restore on Postgres Cluster Restore the dump to the target cluster using the method that matches your export format. @@ -88,7 +108,7 @@ The flags `--no-owner` and `--no-privileges` (shown above for `pg_restore`) supp *** -### Step 4 — Verify the Restored Data +### Step 5 — Verify the Restored Data After the restore completes, validate the data on Postgres Cluster before cutting over traffic. Recommended checks: @@ -119,7 +139,27 @@ psql -h -U -c "\l" *** -### Step 2 — Export All Databases +### Step 2 — Stop Write Operations + +Before exporting, prevent any write operations to the source database to ensure a consistent snapshot. Some approaches: + +**Option 1 — Stop from the application:** Shut down or pause the application writing to the source database. + +**Option 2 — Set the source database to read-only:** + +```sql +ALTER DATABASE SET default_transaction_read_only = on; +``` + +Remember to revert this after the restore completes: + +```sql +ALTER DATABASE SET default_transaction_read_only = off; +``` + +*** + +### Step 3 — Export All Databases Choose one of the two export approaches below. @@ -151,7 +191,7 @@ pg_dump -h -U -d \ *** -### Step 3 — Recreate Roles and Tablespaces (if needed) +### Step 4 — Recreate Roles and Tablespaces (if needed) If your databases rely on specific roles or custom tablespaces, recreate them on Postgres Cluster before restoring. Roles created here will need passwords set manually. @@ -165,7 +205,7 @@ If you used `pg_dumpall`, the SQL file contains role definitions, but some state *** -### Step 4 — Restore on Postgres Cluster +### Step 5 — Restore on Postgres Cluster **If you used pg\_dumpall (Option A)**, restore with `psql` connecting to the default `postgres` database: @@ -193,7 +233,7 @@ ALTER ROLE WITH PASSWORD ''; *** -### Step 5 — Verify Each Database +### Step 6 — Verify Each Database After the restore, verify every database on Postgres Cluster: diff --git a/Vietnamese/vdb/relational-database-service-rds/postgresql/migrate-tu-postgres-single-sang-cluster.md b/Vietnamese/vdb/relational-database-service-rds/postgresql/migrate-tu-postgres-single-sang-cluster.md index 9507ec96..1e11dd05 100644 --- a/Vietnamese/vdb/relational-database-service-rds/postgresql/migrate-tu-postgres-single-sang-cluster.md +++ b/Vietnamese/vdb/relational-database-service-rds/postgresql/migrate-tu-postgres-single-sang-cluster.md @@ -36,7 +36,27 @@ psql -h -U -d -c "SELECT 1;" *** -### Bước 2 — Xuất dữ liệu +### Bước 2 — Dừng ghi dữ liệu + +Trước khi export, ngăn các thao tác write vào database nguồn để đảm bảo dữ liệu export là nhất quán. Một số cách gợi ý: + +**Cách 1 — Dừng từ ứng dụng:** Tắt hoặc tạm dừng ứng dụng đang write vào database nguồn. + +**Cách 2 — Set read-only trên database nguồn:** + +```sql +ALTER DATABASE SET default_transaction_read_only = on; +``` + +Nhớ tắt lại sau khi restore hoàn tất: + +```sql +ALTER DATABASE SET default_transaction_read_only = off; +``` + +*** + +### Bước 3 — Xuất dữ liệu Dùng `pg_dump` để xuất database nguồn. Chọn định dạng phù hợp với phương thức restore bạn muốn sử dụng. @@ -61,7 +81,7 @@ Custom format (`-Fc`) tạo ra file binary được nén và hỗ trợ restore *** -### Bước 3 — Restore trên Postgres Cluster +### Bước 4 — Restore trên Postgres Cluster Restore dữ liệu lên cluster đích theo đúng định dạng đã export. @@ -88,7 +108,7 @@ Các flag `--no-owner` và `--no-privileges` (dùng với `pg_restore`) sẽ ng *** -### Bước 4 — Xác minh dữ liệu sau restore +### Bước 5 — Xác minh dữ liệu sau restore Sau khi restore hoàn tất, hãy kiểm tra dữ liệu trên Postgres Cluster trước khi chuyển traffic sang. Khuyến nghị một số kiểm tra: @@ -119,7 +139,27 @@ psql -h -U -c "\l" *** -### Bước 2 — Xuất toàn bộ database +### Bước 2 — Dừng ghi dữ liệu + +Trước khi export, ngăn các thao tác write vào database nguồn để đảm bảo dữ liệu export là nhất quán. Một số cách gợi ý: + +**Cách 1 — Dừng từ ứng dụng:** Tắt hoặc tạm dừng ứng dụng đang write vào database nguồn. + +**Cách 2 — Set read-only trên database nguồn:** + +```sql +ALTER DATABASE SET default_transaction_read_only = on; +``` + +Nhớ tắt lại sau khi restore hoàn tất: + +```sql +ALTER DATABASE SET default_transaction_read_only = off; +``` + +*** + +### Bước 3 — Xuất toàn bộ database Chọn một trong hai cách xuất dữ liệu dưới đây. @@ -151,7 +191,7 @@ pg_dump -h -U -d \ *** -### Bước 3 — Tạo lại Role và Tablespace (nếu cần) +### Bước 4 — Tạo lại Role và Tablespace (nếu cần) Nếu database của bạn phụ thuộc vào các role hoặc tablespace cụ thể, hãy tạo lại chúng trên Postgres Cluster trước khi restore. Các role được tạo ở đây cần đặt mật khẩu thủ công. @@ -165,7 +205,7 @@ Nếu bạn dùng `pg_dumpall`, file SQL chứa định nghĩa role nhưng một *** -### Bước 4 — Restore trên Postgres Cluster +### Bước 5 — Restore trên Postgres Cluster **Nếu dùng pg\_dumpall (Tùy chọn A)**, restore bằng `psql` kết nối vào database mặc định `postgres`: @@ -193,7 +233,7 @@ ALTER ROLE WITH PASSWORD ''; *** -### Bước 5 — Xác minh từng database +### Bước 6 — Xác minh từng database Sau khi restore, kiểm tra toàn bộ database trên Postgres Cluster. Khuyến nghị một số kiểm tra: