> For the complete documentation index, see [llms.txt](https://docs.docbits.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.docbits.com/chinese/gao-ji-gong-neng-yu-gong-ju/powerbi/connect-via-read-only-database.md).

# 通过只读数据库连接

本指南将介绍如何使用 **PostgreSQL ODBC 驱动程序**将 **DocBits 只读数据库连接到 Power BI Desktop**。内容涵盖驱动程序安装、ODBC 配置、Power BI 集成和计划刷新。

{% embed url="<https://youtu.be/O1MtuXf_R_M>" %}

#### 1. 安装 PostgreSQL ODBC 驱动程序

* 从官方网站下载最新的 PostgreSQL ODBC 驱动程序（**psqlODBC**）：
  * <https://www.postgresql.org/ftp/odbc/releases/>
* 运行安装程序并按照安装向导操作。

#### 2. 配置 ODBC 数据源

* 通过控制面板或 Windows 搜索打开 **ODBC 数据源管理器（64 位）**。
* 转到 **系统 DSN** 选项卡，然后点击 **添加**。
* 从列表中选择 **PostgreSQL Unicode(x64)** 驱动程序，然后点击 **完成**。
* 使用以下位置提供的凭据填写必填字段：\n **DocBits → 设置 → 文档处理 → 模块 → AI 仪表板 → 只读数据库访问**

<figure><img src="https://1870485400-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlPczlNw8zzYNLfjfispX%2Fuploads%2Fgit-blob-1ae4c197eaf00269f81f21dd4eba8a537883aeee%2Fconnect_read_only_4.png?alt=media" alt=""><figcaption></figcaption></figure>

**必填字段：**

* **名称：** 连接名称（例如，`Sandbox-Read_Only`）
* **服务器：** 从 DocBits 复制主机值
* **端口：** 从 DocBits 复制端口值
* **数据库：** 从 DocBits 复制数据库名称
* **用户名：** 从 DocBits 复制用户名
* **密码：** 从 DocBits 复制密码
* **SSL 模式：** 设置为 **Require**（确保通信加密）

#### 3. 将只读数据库连接到 Power BI

* 打开 **Power BI Desktop**。
* 选择 **获取数据** → **ODBC** → **连接**。

  <figure><img src="https://1870485400-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlPczlNw8zzYNLfjfispX%2Fuploads%2Fgit-blob-2df574ab7d5cc13b422d6bb0c4d92ffdb0ca334d%2Fpowerbi_get_data_odbc.png?alt=media" alt="Power BI 获取数据 ODBC"><figcaption></figcaption></figure>
* 在 DSN 列表中，选择已配置的数据源（例如，`Sandbox-Read_Only`）。

<figure><img src="https://1870485400-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlPczlNw8zzYNLfjfispX%2Fuploads%2Fgit-blob-3a675e1a3c179dd8adfebc36fed5ee7e8463d2ba%2Fconnect_read_only_3.png?alt=media" alt=""><figcaption></figcaption></figure>

* 点击 **确定**。如果系统提示，请再次输入凭据。
  * <mark style="color:red;">**注意：**</mark> 如果看到错误 **“password authentication failed for user”**，请尝试将密码用\*\*花括号 `{}`\*\*括起来后输入。

#### 4. 加载和转换数据

* 在 **导航器**窗格中展开架构列表。
* 打开 **`public`** 架构。
* 选择要导入的表。

![](https://1870485400-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlPczlNw8zzYNLfjfispX%2Fuploads%2Fgit-blob-d9da40801794e260ea47cac0838dd469e1269bd1%2Fconnect_read_only_1.png?alt=media) ![](https://1870485400-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlPczlNw8zzYNLfjfispX%2Fuploads%2Fgit-blob-8f99c506f8a97119aa800ed841b89dfec3dcebc6%2Fconnect_read_only_2.png?alt=media)

* 选择：
  * **加载** → 直接导入 Power BI
  * **转换数据** → 打开 Power Query，在加载前整理和筛选数据

#### 5. 可视化数据

* 使用 Power BI 报表画布构建仪表板。
* 拖动字段、添加切片器、选择图表类型并应用 DAX 计算。
* 创建可视化内容前，使用 **Power Query 编辑器**清理或联接数据。
* 参考：[Power BI 文档](https://learn.microsoft.com/en-us/power-bi/?utm_source=chatgpt.com)

#### 6. 启用计划刷新（可选）

<mark style="color:red;">**注意：**</mark> **需要 Power BI Pro 或 Premium 以及网关**

* 若要使报表与 ClickHouse 保持同步：
* 将 `.pbix` 文件发布到 **Power BI Service**。
* 在可访问 ClickHouse 网络的计算机上以标准模式安装 **Power BI Gateway**。
* 在 Power BI Service 中：
  * 转到数据集 → **设置** → **计划刷新**
  * 映射 DSN 并提供凭据
* 更多信息请参阅[此处](https://learn.microsoft.com/en-us/power-bi/connect-data/service-gateway-deployment-guidance)。

#### 7. 仪表板和数据视图示例

<div><figure><img src="https://1870485400-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlPczlNw8zzYNLfjfispX%2Fuploads%2Fgit-blob-e9d42f908877f27b20b7fef6aabcefc2a62ee612%2Fpowerbi_dashboard_example_1.png?alt=media" alt="Power BI 仪表板示例 1"><figcaption></figcaption></figure> <figure><img src="https://1870485400-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlPczlNw8zzYNLfjfispX%2Fuploads%2Fgit-blob-76245fedbfc1c38d4fd16788c385f6555ef9c3e8%2Fpowerbi_dashboard_example_2.png?alt=media" alt="Power BI 仪表板示例 2"><figcaption></figcaption></figure> <figure><img src="https://1870485400-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlPczlNw8zzYNLfjfispX%2Fuploads%2Fgit-blob-fbe836770a7c4c8c3eb506b0411a7be9a7c0bb8c%2Fpowerbi_dashboard_example_3.png?alt=media" alt="Power BI 仪表板示例 3"><figcaption></figcaption></figure> <figure><img src="https://1870485400-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FlPczlNw8zzYNLfjfispX%2Fuploads%2Fgit-blob-66bc278fabf8217eea1c56aac2e11c91bea5cb66%2Fpowerbi_dashboard_example_4.png?alt=media" alt="Power BI 仪表板示例 4"><figcaption></figcaption></figure></div>


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.docbits.com/chinese/gao-ji-gong-neng-yu-gong-ju/powerbi/connect-via-read-only-database.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
