> 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-cn/integrations/llms-and-databases/database-integration.md).

# 数据库集成

## **目的**

\
通过向公共或私有数据库添加一个或多个集成，您可以使用 AI 代理的强大功能安全地查询您的数据，从而启用高级应用程序和其他功能。

### **支持**

SkyDeck AI 目前支持托管在 AWS 上的 Postgresql 数据库和 Redshift 数据仓库。支持其他数据源并非特别困难，但我们必须有个起点。如果你有其他希望使用的数据源，请联系支持以优先考虑满足你需求的整合。

### **操作指南**

**以下是将您的数据库与SkyDeck AI进行集成的步骤：**

1. 获取或整合一个连接URL。
2. 将连接URL添加到控制中心的集成部分。
3. 在控制中心的工具部分，将该集成指派给智能工具或AI代理。

### 连接网址

如果你运气好，数据库管理员会给你一个已经可以使用的标准网址指向你的数据库。否则，你需要自己组装一个来添加对你的数据库的SkyDeck访问权限。这些指示将使这项任务变得相当容易。

\
\
要设置一个到托管在Amazon AWS上的PostgreSQL或亚马逊红移数据库的连接网址，你需要关于你的数据库的几个信息：主机、端口号、数据库名、用户名和密码。以下是逐步指导：

#### PostgreSQL数据库

1. **主机**：这是您的数据库所在的服务器的地址。对于AWS RDS PostgreSQL，它应该类似于`your-db-instance-name.region-name.rds.amazonaws.com`；对于Amazon Redshift，它应该类似于`your-cluster-name.region-name.redshift.amazonaws.com`。
2. **端口号**：这是您的数据库服务器监听的端口。PostgreSQL的默认端口是5432，Amazon Redshift的端口是5439。
3. **数据库名称**：这是您想要连接的数据库的名称。
4. **用户名和密码**：这些是您需要用来进行数据库身份验证的凭证。

连接URL的一般格式如下：

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

以下是如何创建连接URL的步骤：

1. 首先，以协议开始，对于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的默认端口是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'、'5439'和'your-database-name'替换成你实际的数据库详细信息。

### 添加您的集成

将您的连接 URL 粘贴到添加集成的“凭据”部分。您可以选择 PostgreSQL 作为 postgresql 或 Redshift 数据库。您可以为集成使用任何您想要的名称，但我们建议您选择一个可以帮助您识别特定数据库的名称。

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

### 通过 SkyDeckAI 访问您的数据

今天，用户可以使用 GenStudio 中可用的分析工具访问您的数据库。作为管理员，您可以在控制中心的工具部分将集成分配给分析工具。然后，您可以为该工具分配标签，以确保只有授权人员可以访问该工具及其在 SkyDeck AI GenStudio 工作区中的数据库访问。

<figure><img src="/files/nYJbcsJT2idgAqoJEgAa" 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-cn/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.
