---
name: php186-skill-75408
description: "当代理需要用于 PostgreSQL 的原生 Rust 扩展生命周期时，请使用 pgrx，包括本地构建、测试运行以及跨 PostgreSQL 版本的打包。"
---

# Build, test, and package PostgreSQL extensions in Rust with pgrx

## 使用 pgrx 在 Rust 中构建、测试和打包 PostgreSQL 扩展

 

当代理需要用于 PostgreSQL 的原生 Rust 扩展生命周期时，请使用 pgrx，包括本地构建、测试运行以及跨 PostgreSQL 版本的打包。

 

## 先决条件

 

Rust 工具链、PostgreSQL 开发依赖项和 pgrx

 

## 安装

 

使用与您的环境匹配的上游安装或设置路径：

 

- brew install git icu4c pkg-config
- 在运行 cargo pgrx init 命令之前在命令行中执行
- 项目和旧目录已消失。解决方法是重新运行 cargo pgrx init
- cargo install --locked cargo-pgrx

 

来自上游的要求和注意事项：

 

- † PGRX 没有 MSRV 策略，因此可能需要最新稳定版 Rust，可通过 Rustup 获得 在 Mac 上运行 PGRX 需要一些额外的设置。
- 可通过更新 Xcode 和命令行工具来解决。您可能需要操作系统更新

 

基本用法或入门笔记：

 

- cargo pgrx run：在 psql（或 pgcli）中运行您的扩展并进行交互式测试
- 为了解决这个问题，请运行
- 在做任何其他事情之前，安装 系统依赖项。
- Source: https://github.com/1991513ccie-png/skills
- Extracted from upstream docs: https://raw.githubusercontent.com/pgcentralfoundation/pgrx/HEAD/README.md

 

## 文档

 

- https://github.com/1991513ccie-png/skills
