

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

# 使用 PostgreSQL 互動式終端機 (psql) 存取 Aurora DSQL
<a name="accessing-psql"></a>

## 使用 AWS CloudShell 以 PostgreSQL 互動式終端機 (psql) 存取 Aurora DSQL
<a name="accessing-sql-clients-psql"></a>

使用下列程序，從 使用 PostgreSQL 互動式終端機存取 Aurora DSQL AWS CloudShell。如需詳細資訊，請參閱[什麼是 AWS CloudShell](https://docs.aws.amazon.com/cloudshell/latest/userguide/welcome.html) 。

**使用 連線 AWS CloudShell**

1. 登入 [Aurora DSQL 主控台](https://console.aws.amazon.com/dsql)。

1. 選擇您要在 CloudShell 中開啟的叢集。如果您尚未建立叢集，請遵循 [步驟 1：建立 Aurora DSQL 單一區域叢集](getting-started.md#getting-started-create-cluster) 或 [建立多區域叢集](getting-started.md#getting-started-multi-region) 中的步驟。

1. 選擇**與查詢編輯器連線**，然後選擇**與 CloudShell 連線**。

1. 選擇您要以管理員身分或使用[自訂資料庫角色](https://docs.aws.amazon.com/aurora-dsql/latest/userguide/authentication-authorization.html#authentication-authorization-iam-role-connect)進行連線。

1. 選擇**在 CloudShell 中啟動**，然後在下列 CloudShell 對話方塊中選擇**執行**。

## 使用本機 CLI 透過 PostgreSQL 互動式終端機 (psql) 存取 Aurora DSQL
<a name="accessing-sql-clients-psql-local"></a>

使用`psql`終端機型前端到 PostgreSQL 公用程式 ，以互動方式輸入查詢、將查詢發行到 PostgreSQL，以及檢視查詢結果。

**注意**  
若要提升查詢回應效能，請使用 PostgreSQL 17 版客戶端。如果您在不同的環境中使用 CLI，請務必手動設定 Python 3.8\$1 版和 psql 14\$1 版。

請從 [PostgreSQL Downloads](https://www.postgresql.org/download/) 頁面下載適用於您作業系統的安裝程式。如需 的詳細資訊`psql`，請參閱 [PostgreSQL 網站上的 PostgreSQL 用戶端應用程式](https://www.postgresql.org/docs/current/app-psql.htm)。 *PostgreSQL* 

如果您已 AWS CLI 安裝 ，請使用下列範例來連接至您的叢集。

```
# Aurora DSQL requires a valid IAM token as the password when connecting.  
# Aurora DSQL provides tools for this and here we're using Python.  
export PGPASSWORD=$(aws dsql generate-db-connect-admin-auth-token \
  --region us-east-1 \
  --expires-in 3600 \
  --hostname your_cluster_endpoint)  
  
# Aurora DSQL requires SSL and will reject your connection without it.  
export PGSSLMODE=require  
  
# Connect with psql, which automatically uses the values set in PGPASSWORD and PGSSLMODE.  
# Quiet mode suppresses unnecessary warnings and chatty responses but still outputs errors.  
psql --quiet \
  --username admin \
  --dbname postgres \
  --host your_cluster_endpoint
```