Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,27 @@ psql -h <IP_cluster> -U <username_cluster> -d <database_cluster> -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 <database_name> SET default_transaction_read_only = on;
```

Remember to revert this after the restore completes:

```sql
ALTER DATABASE <database_name> 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.

Expand All @@ -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.

Expand All @@ -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:

Expand Down Expand Up @@ -119,7 +139,27 @@ psql -h <IP_cluster> -U <username_cluster> -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 <database_name> SET default_transaction_read_only = on;
```

Remember to revert this after the restore completes:

```sql
ALTER DATABASE <database_name> SET default_transaction_read_only = off;
```

***

### Step 3 — Export All Databases

Choose one of the two export approaches below.

Expand Down Expand Up @@ -151,7 +191,7 @@ pg_dump -h <IP_single> -U <username_single> -d <db_name> \

***

### 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.

Expand All @@ -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:

Expand Down Expand Up @@ -193,7 +233,7 @@ ALTER ROLE <role_name> WITH PASSWORD '<new_password>';

***

### Step 5 — Verify Each Database
### Step 6 — Verify Each Database

After the restore, verify every database on Postgres Cluster:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,27 @@ psql -h <IP_cluster> -U <username_cluster> -d <database_cluster> -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 <database_name> SET default_transaction_read_only = on;
```

Nhớ tắt lại sau khi restore hoàn tất:

```sql
ALTER DATABASE <database_name> 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.

Expand All @@ -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.

Expand All @@ -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:

Expand Down Expand Up @@ -119,7 +139,27 @@ psql -h <IP_cluster> -U <username_cluster> -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 <database_name> SET default_transaction_read_only = on;
```

Nhớ tắt lại sau khi restore hoàn tất:

```sql
ALTER DATABASE <database_name> 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.

Expand Down Expand Up @@ -151,7 +191,7 @@ pg_dump -h <IP_single> -U <username_single> -d <db_name> \

***

### 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.

Expand All @@ -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`:

Expand Down Expand Up @@ -193,7 +233,7 @@ ALTER ROLE <role_name> WITH PASSWORD '<new_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:

Expand Down
Loading