PostgRPC

Latest Version Documentation

Query your Postgres databases directly using gRPC, gRPC-web, or transcoded JSON.

Table of Contents

  1. Introduction
    1. Why
    2. Similar Projects
    3. Goals
    4. Non-Goals
  2. Getting Started
    1. Installation
    2. Configuration
    3. Usage
  3. Examples
    1. JSON Transcoding
    2. gRPC-web
    3. Load Balancing
    4. Auth
  4. FAQ
  5. Roadmap

Introduction

Why?

Sometimes you want to use the full power of a Postgres database, but you aren't able to make direct connections or you don't want to write a custom API service that wraps your database queries. PostgRPC gives you the power of SQL over gRPC or JSON, handling distributed transactions and connection management on your behalf.

Similar Projects

PostgRPC fills a similar niche as the excellent PostgREST and PostGraphile projects. Unlike those projects, PostgRPC lets you use SQL directly rather than wrapping the interface in another query language (i.e. a REST DSL or GraphQL, respectively). In addition, PostgRPC lets you work with lower-level database constructs like transactions through the same gRPC or JSON interface used to query your database.

Goals

Non-Goals

Getting Started

Installation

For binary installations, use cargo install postgrpc. The compilation of the postgrpc executable can be customized with --features.

For library installations, use cargo add postgrpc within a cargo-managed Rust project.

Configuration

The postgrpc executable can be configured with the following environment variables:

In addition, the default connection pool can be configured with the following environment variables:

Usage

With PostgRPC running on the default port and host, grpcurl can be used to query the database:

```bash grpcurl \ -plaintext \ -d '{"statement":"select 1 + 1 as two"}' \

{ "two": 2 }

```

To use a different (pre-existing) ROLE than the one used to connect to the database initially, use the X-Postgres-Role header:

```bash grpcurl \ -plaintext \ -d '{"statement":"select current_user"}' \ -H 'X-Postgres-Role: my-other-user' \

{ "current_user": "my-other-user" }

```

Examples

All examples can be run from the ./examples directory using docker-compose. Click on the links below to learn more about each example.

FAQ

  1. Who built PostgRPC? The team at Platter.
  2. Is PostgRPC ready for production? PostgRPC should be considered alpha-level software, and no warranty is given or implied. If you still want to run PostgRPC yourself, be sure to run it as a part of a stack that includes robust authentication and authorization, and ensure that you harden your Postgres database against malicious queries! But you were doing that with your Postgres database anyway, right?
  3. How do you pronounce PostgRPC? "post-ger-puck"

Contributing

Contributions are welcome in the form of bug reporting, feature requests, software fixes, and documentation updates. Please submit all code contributions as pull requests through GitHub.

Roadmap

Associated Crates

Postguard

Latest Version Documentation