> For the complete documentation index, see [llms.txt](https://docs.skydeck.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.skydeck.ai/zh-hk/integrations/llms-and-databases/database-integration.md).

# 數據庫整合

## **目的**

\
透過將一個或多個整合添加到公共或私有資料庫，您可以使用AI代理的力量安全地查詢您的資料，以啟用進階應用程式和其他功能。

### **支援**

SkyDeck AI 目前支援在 AWS 上托管的 Postgresql 數據庫和Redshift數據倉庫。支持其他數據源並不特別困難，但我們必須從某處開始。如果您有其他希望使用的數據源，請聯繫支持以優先滿足您需要的集成。

### **指示**

**以下是將您的資料庫與SkyDeck AI整合的步驟：**

1. 獲取或組合連線URL。
2. 將連線URL添加到控制中心的整合部分中。
3. 在控制中心的工具部分，將該整合分配給一個智能工具或AI代理。

### 連接URL

如果你很幸運，數據庫管理員將會為你準備好一個指向你的數據庫的標準URL。如果沒有，你將需要自己搭建一個來添加SkyDeck對你的數據庫的訪問權限。這些指導將使得這個任務相對容易。

\
\
要設置一個指向在Amazon AWS上托管的PostgreSQL或Amazon Redshift數據庫的連接URL，你需要關於你的數據庫的幾個資訊：主機、端口號、數據庫名稱、用戶名和密碼。這裡是一個逐步指導:

#### PostgreSQL 資料庫

1. **主機 (Host)**：這是您的資料庫伺服器的位址。如果是 AWS RDS PostgreSQL，應類似於 `your-db-instance-name.region-name.rds.amazonaws.com`，若是 Amazon Redshift，則應為 `your-cluster-name.region-name.redshift.amazonaws.com`。
2. **埠號 (Port Number)**：這是您的資料庫伺服器正在監聽的埠。PostgreSQL 的預設埠為 5432，Amazon Redshift 為 5439。
3. **資料庫名稱 (Database Name)**：這是您要連接的資料庫的名稱。
4. **用戶名 & 密碼 (Username & Password)**：這些是您需要用以驗證資料庫的憑證。

連接 URL 的一般格式如下：

```
protocol://username:password@host:port/database
```

這是如何創建連接 URL 的方法：

1. 從協議（protocol）開始，對於 PostgreSQL 為 'postgresql'，對於 Amazon Redshift 為 'redshift'：

   ```
    postgresql://
   ```
2. 接著，加入您的用戶名和密碼，中間以冒號隔開。如果您的用戶名或密碼包含特殊字符，您需要對其做 URL 編碼。例如，如果您的用戶名是 'user'，您的密碼是 'pass'，它會變為：

   ```
    postgresql://user:pass@
   ```
3. 然後，加入您的主機和埠號，中間以冒號分隔：

   ```
    postgresql://user:pass@your-db-instance-name.region-name.rds.amazonaws.com:5432/
   ```
4. 最後，加入您的資料庫名稱：

   ```
    postgresql://user:pass@your-db-instance-name.region-name.rds.amazonaws.com:5432/your-database-name
   ```

就完成了！您已經創建了您的連接 URL。請確保將 'user', 'pass', 'your-db-instance-name.region-name.rds.amazonaws.com', '5432' 以及 'your-database-name' 替換為您實際的資料庫詳細資料。

請記住不要與任何人分享此 URL，因為它包含您的用戶名和密碼等敏感資訊。

#### RedShift DWH

連接Redshift資料庫的URL會與前面類似，但有幾個關鍵的不同：

1. 這裡的協議將是'jdbc:redshift'，而不是'postgresql'。這是因為JDBC（Java Database Connectivity，Java資料庫連接）常被用來與Redshift資料庫進行連接。
2. Redshift的預設port是5439，而非5432。

以下是Redshift連接URL的一般格式：

```
jdbc:redshift://host:port/database
```

所以，如果你要為Redshift建立一個連接URL，它將看起來如下：

```
jdbc:redshift://user:pass@your-cluster-name.region-name.redshift.amazonaws.com:5439/your-database-name
```

請記住將'user'、'pass'、'your-cluster-name.region-name.redshift.amazonaws.com'，還有'your-database-name'替換為你實際的資料庫詳細資訊。

### 添加您的整合

將您的連接 URL 粘貼到添加整合的「憑證」部分。您可以為 postgresql 或 Redshift 數據庫選擇 PostgreSQL。您可以為整合使用任何您想要的名稱，但我們建議您選擇一些能幫助您識別特定數據庫的名稱。

<figure><img src="/files/g5RCFH7LRfzswf9Wo9Jx" alt="Add a DB Integration to Control Center"><figcaption></figcaption></figure>

### 通過 SkyDeckAI 訪問您的數據

今天用戶可以使用 GenStudio 中可用的分析工具訪問您的數據庫。作為管理員，您可以在控制中心的工具部分將集成分配給分析工具。然後，您可以為該工具分配標籤，以確保只有授權的人員可以訪問該工具及其在 SkyDeck AI GenStudio 工作區中的數據庫訪問。

<figure><img src="/files/TXVgr1MBfCN4pFkwzbZ3" alt="Adding a DB Integration to Analyst Bob"><figcaption><p>將數據庫集成添加到支持它的工具，以便與您組織的成員共享訪問權限。</p></figcaption></figure>

#### 安全注意事項

* 在您的資料庫中創建一個只讀用戶（角色）以用於您的 SkyDeck AI 整合。SkyDeck 不需要對您的系統進行寫入，使用權限不超過必要的憑證是最安全的。然而，該用戶應能查詢您的資料系統的結構以便理解它。
* 不要分享訪問 URL，因為它包含機密的連接信息。
* 您可以通過確保使用該資料庫的工具（例如 Analyst Bob 的副本）被分配僅對您希望擁有訪問權限的用戶相對應的標籤，來限制您組織中哪些用戶可以訪問每個資料庫。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.skydeck.ai/zh-hk/integrations/llms-and-databases/database-integration.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
