

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# RDS Proxy 的故障診斷
<a name="rds-proxy.troubleshooting"></a>

 您可在下列內容中找到某些常見 RDS Proxy 問題的故障診斷想法，以及 RDS Proxy 的 CloudWatch 日誌的相關資訊。

 在 RDS Proxy 日誌中，每個項目均會以關聯的代理端點名稱作為前綴。此名稱可以是您針對使用者定義端點所指定的名稱。也可以是執行讀取/寫入請求之代理預設端點的特殊名稱 `default`。如需代理端點的詳細資訊，請參閱[使用 Amazon RDS Proxy 端點](rds-proxy-endpoints.md).

**Topics**
+ [驗證代理的連線能力](#rds-proxy-verifying)
+ [常見問題與解決方案](#rds-proxy-diagnosis)
+ [針對 RDS for MySQL 的 RDS Proxy 問題進行疑難排解](#rds-proxy-MySQL-troubleshooting)
+ [針對 RDS for PostgreSQL 的 RDS Proxy 問題進行疑難排解](#rds-proxy-PostgreSQL-troubleshooting)

## 驗證代理的連線能力
<a name="rds-proxy-verifying"></a>

 您可以使用下列命令來驗證連線中的所有元件 (例如代理、資料庫和運算執行個體) 可以彼此通訊。

 使用 [describe-db-proxies](https://docs.aws.amazon.com/cli/latest/reference/rds/describe-db-proxies.html) 命令檢查代理本身。也請使用 [describe-db-proxy-target-groups](https://docs.aws.amazon.com/cli/latest/reference/rds/describe-db-proxy-target-groups.html) 命令檢查相關聯的目標群組。檢查目標的詳細資訊是否符合您打算與 Proxy 建立關聯的 RDS 資料庫執行個體。使用如下命令。

```
aws rds describe-db-proxies --db-proxy-name $DB_PROXY_NAME
aws rds describe-db-proxy-target-groups --db-proxy-name $DB_PROXY_NAME
```

 若要確認代理可連線至基礎資料庫，請使用 [describe-db-proxy-targets](https://docs.aws.amazon.com/cli/latest/reference/rds/describe-db-proxy-targets.html) 命令檢查目標群組中指定的目標。使用如下命令。

```
aws rds describe-db-proxy-targets --db-proxy-name $DB_PROXY_NAME
```

 [describe-db-proxy-targets](https://docs.aws.amazon.com/cli/latest/reference/rds/describe-db-proxy-targets.html) 命令的輸出包含 `TargetHealth` 欄位。您可以檢查 `State` 內的 `Reason`、`Description` 和 `TargetHealth` 欄位，以檢查代理是否能與基礎資料庫執行個體進行通訊。
+  `State` 的 `AVAILABLE` 值表示代理可連線至資料庫執行個體。
+  `State` 的 `UNAVAILABLE` 值表示暫時或永久的連線問題。在這種情況下，請檢查 `Reason` 和 `Description` 欄位。例如，如果 `Reason` 具有 `PENDING_PROXY_CAPACITY` 的值，請在代理完成其擴展操作後嘗試再次連線。如果 `Reason` 具有 `UNREACHABLE`、`CONNECTION_FAILED` 或 `AUTH_FAILURE` 的值，請使用來自 `Description` 欄位的解說，協助您診斷此問題。
+  `State` 欄位在變更為 `REGISTERING` 或 `AVAILABLE` 前，可能短暫具有 `UNAVAILABLE` 的值。

 如果下列 Netcat 命令 (`nc`) 成功，您可以從 EC2 執行個體或登入的其他系統存取代理端點。如果您與代理和關聯的資料庫不在同一 VPC 中，則此命令會回報失敗。您可能可以直接登入資料庫，而不需要在同一個 VPC 中。然而除非您位於同一個 VPC 中，否則無法登入代理。

```
nc -zx MySQL_proxy_endpoint 3306

nc -zx PostgreSQL_proxy_endpoint 5432
```

 您可以使用下列命令確定您的 EC2 執行個體具有需要的屬性。特別是，EC2 執行個體的 VPC 必須與 Proxy 連線的 的 VPC 相同。

```
aws ec2 describe-instances --instance-ids your_ec2_instance_id
```

 檢查用於代理的 Secrets Manager 秘密。

```
aws secretsmanager list-secrets
aws secretsmanager get-secret-value --secret-id your_secret_id
```

 請確定 `get-secret-value` 所顯示的 `SecretString` 欄位已編碼為包含 `username` 和 `password` 欄位的 JSON 字串。下列範例顯示 `SecretString` 欄位的格式。

```
{
  "ARN": "some_arn",
  "Name": "some_name",
  "VersionId": "some_version_id",
  "SecretString": '{"username":"some_username","password":"some_password"}',
  "VersionStages": [ "some_stage" ],
  "CreatedDate": some_timestamp
}
```

疑難排解 IAM 身分驗證問題時，請確認下列事項：
+ 資料庫已啟用 IAM 身分驗證。
+ 代理已設定正確的身分驗證機制。
+ 提供給代理的 IAM 角色中的 IAM 政策會將必要的`rds-db:connect`許可授予適當的資料庫及其使用者名稱。
+ 對於end-to-end IAM 身分驗證，存在符合 IAM 使用者或角色名稱的資料庫使用者。
+ 連線已啟用 SSL/TLS。

## 常見問題與解決方案
<a name="rds-proxy-diagnosis"></a>

本節說明使用 RDS Proxy 時的一些常見問題和潛在解決方案。

執行 `aws rds describe-db-proxy-targets` CLI 命令之後，如果 `TargetHealth` 描述說明 `Proxy does not have any registered credentials`，請驗證下列事項：
+ 有已註冊的憑證，供使用者存取代理。
+ 用來存取代理所使用之 Secrets Manager 秘密的 IAM 角色是有效的。

建立或連線至資料庫代理時，您可能會遇到下列 RDS 事件。


| 類別 | RDS 事件 ID | 說明 | 
| --- | --- | --- | 
|  失敗  | RDS-EVENT-0243 | RDS 無法佈建代理的容量，因為子網路中沒有足夠的可用 IP 地址。若要修正此問題，請確認您的子網路具有最低數目的未使用 IP 地址。若要確定執行個體類別的建議數量，請參閱 [規劃 IP 地址容量](rds-proxy-network-prereqs.md#rds-proxy-network-prereqs.plan-ip-address)。 | 
|  失敗  | RDS-EVENT-0275 |  RDS 對部分連往資料庫代理*名稱*的連線進行限流。從用戶端到代理的同時連線要求數目已超過限制。  | 

 建立新代理或連線至代理時，可能會遇到下列問題。


|  錯誤  |  原因或因應措施  | 
| --- | --- | 
|   `403: The security token included in the request is invalid`   |  選取現有的 IAM 角色，而不是選擇建立新的 IAM 角色。 | 

## 針對 RDS for MySQL 的 RDS Proxy 問題進行疑難排解
<a name="rds-proxy-MySQL-troubleshooting"></a>

 連線到 MySQL 代理時可能會遇到下列問題。


|  錯誤  |  原因或因應措施  | 
| --- | --- | 
|  ERROR 1040 (HY000): Connections rate limit exceeded (limit\$1value)  |  從用戶端到代理的連線要求速率已超過限制。 | 
|  ERROR 1040 (HY000): IAM authentication rate limit exceeded  |  從用戶端到代理器的 IAM 身分驗證同時請求數目已超過限制。 | 
|  ERROR 1040 (HY000): Number simultaneous connections exceeded (limit\$1value)  |  從用戶端到代理的同時連線要求數目超過限制。 | 
|   `ERROR 1045 (28000): Access denied for user 'DB_USER'@'%' (using password: YES)`   |  代理使用的 Secrets Manager 私密不符合現有資料庫使用者的使用者名稱和密碼。更新 Secrets Manager 私密中的登入資料，或確認資料庫使用者存在，且具有與私密中相同的密碼。 | 
|  ERROR 1105 (HY000): Unknown error  |  發生未知的錯誤。 | 
|  ERROR 1231 (42000): Variable ''character\$1set\$1client'' can't be set to the value of value  |   為 `character_set_client` 參數設定的值無效。例如，值 `ucs2` 是無效的，因為它可能會讓 MySQL 伺服器當機。  | 
|  ERROR 3159 (HY000): This RDS Proxy requires TLS connections.  |   您已在代理中啟用**需要 Transport Layer Security**設定，但您的連線已在 MySQL 用戶端中包含參數 `ssl-mode=DISABLED`。執行下列任何一項： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/AmazonRDS/latest/UserGuide/rds-proxy.troubleshooting.html)  | 
|  ERROR 2026 (HY000): SSL connection error: Internal Server Error  |   TLS 與代理的交握失敗。一些可能的原因包括： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/AmazonRDS/latest/UserGuide/rds-proxy.troubleshooting.html)  | 
|  ERROR 9501 (HY000): Timed-out waiting to acquire database connection  |   代理等候取得資料庫連線逾時。一些可能的原因包括： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/AmazonRDS/latest/UserGuide/rds-proxy.troubleshooting.html)  | 

## 針對 RDS for PostgreSQL 的 RDS Proxy 問題進行疑難排解
<a name="rds-proxy-PostgreSQL-troubleshooting"></a>

 連線到 PostgreSQL 代理時可能會遇到下列問題。


|  錯誤  |  原因  |  解決方案  | 
| --- | --- | --- | 
|   `ERROR 28000: IAM authentication is allowed only with SSL connections.`   |   使用者嘗試使用 PostgreSQL 用戶端中的 `sslmode=disable` 設定，透過 IAM 身分驗證連線至資料庫。  |   使用者需要使用 PostgreSQL 用戶端中 `sslmode=require` 的最小設定連接到資料庫。如需詳細資訊，請參閱 [PostgreSQL SSL 支援](https://www.postgresql.org/docs/current/libpq-ssl.html)文件。  | 
|  `ERROR 28000: This RDS proxy has no credentials for the role role_name. Check the credentials for this role and try again.`   |   這個角色沒有 Secrets Manager 秘密   |   新增此角色的 Secrets Manager 秘密。如需詳細資訊，請參閱[設定 RDS Proxy 的 IAM 身分驗證](rds-proxy-iam-setup.md)。  | 
|  `ERROR 28000: RDS supports only IAM, MD5, or SCRAM authentication.`   |   用來連線到代理的資料庫用戶端正在使用代理目前不支援的身分驗證機制。  |   如果您未使用 IAM 身分驗證，請使用 MD5 或 SCRAM 密碼身分驗證。  | 
|  `ERROR 28000: A user name is missing from the connection startup packet. Provide a user name for this connection.`   |   嘗試建立連線時，用來連線至 Proxy 的資料庫用戶端並未傳送使用者名稱。  |   使用您選擇的 PostgreSQL 用戶端設定與代理連線時，請務必定義使用者名稱。  | 
|  `ERROR 28000: IAM is allowed only with SSL connections.`   |   用戶端嘗試使用 IAM 驗證進行連線，但未啟用 SSL。  |   在用戶端中啟用 SSL。  | 
|  `ERROR 28000: This RDS Proxy requires TLS connections.`   |   使用者啟用**需要 Transport Layer Security**選項，但嘗試使用 PostgreSQL 用戶端中的 `sslmode=disable` 連線。  |   若要修正此錯誤，請執行下列其中一項操作： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/AmazonRDS/latest/UserGuide/rds-proxy.troubleshooting.html)  | 
|  `ERROR 28P01: IAM authentication failed for user user_name. Check the IAM token for this user and try again.`   |   此錯誤可能由下列原因造成： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/AmazonRDS/latest/UserGuide/rds-proxy.troubleshooting.html)  |   若要修正此錯誤，請執行下列動作： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/AmazonRDS/latest/UserGuide/rds-proxy.troubleshooting.html)  | 
|  `ERROR 28P01: The password that was provided for the role role_name is wrong.`   |   此角色的密碼與 Secrets Manager 密碼不符。  |   在 Secrets Manager 檢查此角色的密碼，以查看密碼是否與 PostgreSQL 用戶端中使用的密碼相同。  | 
|  `ERROR 28P01: The IAM authentication failed for the role role_name. Check the IAM token for this role and try again.`   |   用於 IAM 驗證的 IAM 符記發生問題。  |   產生一個新的身分驗證符記，並在新的連線中加以使用。  | 
|  `ERROR 0A000: Feature not supported: RDS Proxy supports only version 3.0 of the PostgreSQL messaging protocol.`   |   用於連線到代理的 PostgreSQL 用戶端使用的通訊協定早於 3.0。  |   使用支援 3.0 訊息通訊協定的較新 PostgreSQL 用戶端。如果您使用的是 PostgreSQL `psql` CLI，請使用大於或等於 7.4 的版本。  | 
|  `ERROR 0A000: Feature not supported: RDS Proxy currently doesn't support streaming replication mode.`   |   用來連線至 Proxy 的 PostgreSQL 用戶端正在嘗試使用串流複寫模式，而 RDS Proxy 目前不支援這種模式。  |   關閉用於連線的 PostgreSQL 用戶端中的串流複寫模式。  | 
|  `ERROR 0A000: Feature not supported: RDS Proxy currently doesn't support the option option_name.`   |   透過啟動訊息，用來連線至 Proxy 的 PostgreSQL 用戶端正在要求 RDS Proxy 目前不支援的選項。  |   在用於連線的 PostgreSQL 用戶端中，關閉上述訊息中顯示為不支援的選項。  | 
|  `ERROR 53300: The IAM authentication failed because of too many competing requests.`   |   從用戶端到代理器的 IAM 身分驗證同時請求數目已超過限制。  |   降低使用 PostgreSQL 用戶端的 IAM 驗證建立連線的速率。  | 
|  `ERROR 53300: The maximum number of client connections to the proxy exceeded number_value.`   |   從用戶端到代理的同時連線要求數目超過限制。  |   減少從 PostgreSQL 用戶端到此 RDS Proxy 的作用中連線數目。  | 
|  `ERROR 53300: Rate of connection to proxy exceeded number_value.`   |   從用戶端到代理的連線要求速率已超過限制。  |   降低從 PostgreSQL 用戶端建立連線的速率。  | 
|  `ERROR XX000: Unknown error.`   |   發生未知的錯誤。  |   請聯絡 AWS Support 以調查問題。  | 
|  `ERROR 08000: Timed-out waiting to acquire database connection.`   |   代理逾時等待在 `ConnectionBorrowTimeout` 設定指定的持續時間內取得資料庫連線。一些可能的原因包括： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/AmazonRDS/latest/UserGuide/rds-proxy.troubleshooting.html)  |   可能的解決方案如下： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/AmazonRDS/latest/UserGuide/rds-proxy.troubleshooting.html)  | 
|  `ERROR XX000: Request returned an error: database_error.`   |   從 Proxy 建立的資料庫連線傳回錯誤。  |   解決方案取決於特定的資料庫錯誤。其中一個範例為 `Request returned an error: database "your-database-name" does not exist`。這表示指定的資料庫名稱不存在於資料庫伺服器上。或者，它表示用作資料庫名稱的使用者名稱 (如果未指定資料庫名稱) 不存在於伺服器上。  | 
|  `ERROR 53300: The IAM authentication failed because of too many competing requests.`  |  從用戶端到代理器的 IAM 身分驗證同時請求數目已超過限制。  |  降低使用 PostgreSQL 用戶端的 IAM 驗證建立連線的速率。  | 
|  `ERROR 28000: Enable IAM authentication for the client connection to the proxy and try again.`  |  RDS Proxy 無法連線至資料庫，因為用戶端連線至代理未啟用 IAM 身分驗證。當代理的`DefaultAuthScheme`參數設為`IAM_AUTH`具有註冊使用者的 ，但用戶端使用密碼身分驗證而非 IAM 身分驗證時，就會發生這種情況。  |  啟用用戶端連線至代理的 IAM 身分驗證，然後再試一次。  | 
|  `ERROR 28000: Configure IAM authentication as the DefaultAuthScheme in your proxy and try again.`  |  RDS Proxy 無法連線至資料庫，因為 `DefaultAuthScheme`未設定為 `IAM_AUTH`。代理的 `DefaultAuthScheme` 參數設定為 `NONE`，但用戶端嘗試使用 IAM 身分驗證。  |  `IAM_AUTH` 為您的代理將 `DefaultAuthScheme`設定為 ，然後再試一次。  | 

### 針對已刪除的 `postgres` 資料庫進行疑難排解
<a name="rds-proxy-PostgreSQL-troubleshooting.postgresDBDelete"></a>

如果您錯誤地從執行個體刪除 `postgres` 資料庫，則需要還原資料庫以還原執行個體的連線。在您的資料庫執行個體內執行下列命令：

```
CREATE DATABASE postgres;
GRANT CONNECT ON DATABASE postgres TO rdsproxyadmin;
```