• Stars
    star
    163
  • Rank 231,141 (Top 5 %)
  • Language
    Rust
  • License
    Apache License 2.0
  • Created over 2 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

PostgreSQL wire protocol implemented as a rust library.

pgwire

CI Docs

This library implements PostgreSQL Wire Protocol, and provide essential APIs to write PostgreSQL comptible servers and clients.

This library is a work in progress and in its relatively early stage. There is no guarantee for API stability. I'm constantly introducing break changes during this period. And also sorry for lack of API docs, examples may get you familiar with its usage.

Status

  • Message format
    • Frontend-Backend protocol messages
    • Logical replication streaming protocol message
  • Backend TCP/TLS server on Tokio
  • Frontend-Backend interaction over TCP
    • SSL Request and Response
    • Startup
      • No authentication
      • Clear-text password authentication
      • Md5 Password authentication
      • SASL SCRAM authentication
        • SCRAM-SHA-256
        • SCRAM-SHA-256-PLUS
    • Simple Query and Response
    • Extended Query and Response
      • Parse
      • Bind
      • Execute
      • Describe
      • Sync
    • Termination
    • Cancel
    • Error and Notice
    • Copy
  • Logical replication over TCP
  • APIs
    • Startup APIs
      • AuthSource API, fetching and hashing passwords
      • Server parameters API, ready but not very good
    • Simple Query API
    • Extended Query API
      • QueryParser API, for transforming prepared statement
      • PortalStore API, for caching statements and portals
    • ResultSet builder/encoder API
    • Query Cancellation API
    • Error and Notice API
    • Copy API
      • Copy-in
      • Copy-out
      • Copy-both
    • Logical replication server API

About Postgres Wire Protocol

Postgres Wire Protocol is a relatively general-purpose Layer-7 protocol. There are 3 parts of the protocol:

  • Startup: client-server handshake and authentication.
  • Simple Query: The legacy query protocol of postgresql. Query are provided as string, and server is allowed to stream data in response.
  • Extended Query: A new sub-protocol for query which has ability to cache the query on server-side and reuse it with new parameters. The response part is identical to Simple Query.

Also note that Postgres Wire Protocol has no semantics about SQL, so literally you can use any query language, data formats or even natural language to interact with the backend.

The response are always encoded as data row format. And there is a field description as header of the data to describe its name, type and format.

Usage

Server/Backend

To use pgwire in your server application, you will need to implement two key components: startup processor and query processor. For query processing, there are two kinds of queries: simple and extended. By adding SimpleQueryHandler to your application, you will get psql command-line tool compatibility. And for more language drivers and additional prepared statement, binary encoding support, ExtendedQueryHandler is required.

Examples are provided to demo the very basic usage of pgwire on server side:

  • examples/sqlite.rs: uses an in-memory sqlite database at its core and serves it with postgresql protocol. This is a full example with both simple and extended query implementation.
  • examples/gluesql.rs: uses an in-memory gluesql at its core and serves it with postgresql protocol.
  • examples/server.rs: demos a server that always returns fixed results.
  • examples/secure_server.rs: demos a server with ssl support and always returns fixed results.
  • examples/scram.rs: demos how to configure more secure authentication mechanism: SCRAM
  • examples/datafusion.rs: demos a postgres compatible server backed by datafusion query engine. This example allows you to LOAD csv files as datafusion table and run SELECT queries on them.

Client/Frontend

I think in most case you do not need pgwire to build a postgresql client, existing postgresql client like rust-postgres should fit your scenarios. Please rise an issue if there is a scenario.

Projects using pgwire

License

This library is released under MIT/Apache dual license.

More Repositories

1

handlebars-rust

Rust templating with Handlebars
Rust
1,089
star
2

node-geohash

geohash library for nodejs
JavaScript
565
star
3

heatcanvas

Pixel based heatmap with html5 canvas.
JavaScript
401
star
4

slacker

Transparent, non-incursive RPC by clojure and for clojure
Clojure
356
star
5

diehard

Clojure resilience library for flexible retry, circuit breaker and rate limiter
Clojure
309
star
6

ring-jetty9-adapter

An enhanced version of jetty adapter for ring, with additional features like websockets, http/2 and http/3
Clojure
228
star
7

shake

clojure library that shakes your shell
Java
122
star
8

handlebars-iron

Handlebars middleware for Iron web framework
Rust
118
star
9

slacker-cluster

Clojure Micro-Service framework based on Slacker RPC
Clojure
77
star
10

pyclj

talking clojure with python - an edn implementation for python
Python
63
star
11

lein-jlink

A lein plugin creates and manages custom java environment
Clojure
59
star
12

hbs

clojure templating by handlebars.java
Clojure
48
star
13

papaline

Clojure concurrent pipleline on core.async
Clojure
47
star
14

rigui

Hierarchical Timing Wheels for Clojure and ClojureScript
Clojure
45
star
15

urdict

command line urban dictionary
Rust
42
star
16

stavka

Stavka manages configuration from various sources, for your Clojure application.
Clojure
41
star
17

exaile-doubanfm-plugin

An alternative choice to enjoy personalized music from douban.fm
Python
40
star
18

openbirdingmap

eBird location and observation data rendered on OpenStreetMap
Clojure
35
star
19

metriki

Rust metrics ported from dropwizard metrics
Rust
27
star
20

reddit.clj

A clojure wrapper for Reddit API
Clojure
25
star
21

rustmann

A riemann client on tokio, async/await
Rust
20
star
22

clojalk

A beanstalkd (distributed task queue) clone in clojure
Clojure
20
star
23

Exaile-Soundmenu-Indicator

integrate exaile with sound menu indicator
Python
19
star
24

cljts

A clojure wrapper of JTS, implements Simple Feature Specification of OGC
Clojure
17
star
25

clojuredocs-android

An Android app for ClojureDocs
JavaScript
14
star
26

lein-control

A lein plugin for clojure control
Clojure
12
star
27

tojson_macros

Simple rust syntax extension generates default ToJson implementation
Rust
11
star
28

timing

clojure syntax sugars for perf4j
Clojure
11
star
29

iron-json-response

Json response middleware for iron
Rust
10
star
30

stages

SEDA framework
Java
7
star
31

exaile-doubanfm-gnome-shell-extension

Exaile DoubanFM Control on GNOME-shell
JavaScript
7
star
32

bason

annotaion driven bson mapping tookit
Java
6
star
33

rageviewer

A rage comic viewer in clojure
Clojure
6
star
34

slacker-rust

Slacker RPC implemented by Rust and for Rust
Rust
4
star
35

greptimedb-bin.aur

AUR repository for GreptimeDB
Shell
4
star
36

lein-bootclasspath-deps

A Leiningen plugin to manage your bootclasspath.
Clojure
4
star
37

slacker-python

python client for slacker
Python
3
star
38

lazypress

Simplified online writing and publishing
JavaScript
3
star
39

sway-im.aur

Sway with input method popup support, packaged as AUR
Shell
2
star
40

mapzei

A maps extension for Ruman Nurik's live wallpaper app Muzei.
Java
2
star
41

karmalet

working in progress
Clojure
2
star
42

debug

Clojure port of nodejs debug
Clojure
2
star
43

link-socketio

Socketio server with link API
Clojure
2
star
44

slacker-htrace

Distributed tracing support for Slacker RPC using Apache HTrace
Clojure
2
star
45

nordenize

A project aimed to transform any webpage into nord color theme.
TypeScript
2
star
46

Artificial301

a simple firefox plugin and google appengine help you to get real link behind feedburner/feedproxy.google.com and url shorten services
JavaScript
2
star
47

alpine-jlink-base

Minimal base image for custom JRE created from jlink
1
star
48

handlebars-gotham

Handlebars templating middleware for Gotham
Rust
1
star
49

slacker-metrics

The metrics middleware for slacker RPC
Clojure
1
star
50

athtool

Command line TOTP generator
Rust
1
star
51

radar

redis proxy [WIP]
Clojure
1
star
52

metaq

A set of metaq API in favour of clojure
Clojure
1
star
53

leancloud-rtm-blacklist

LeanCloud ćźžæ—¶é€šäżĄèŠć€©ćź€é»‘ćć•èŒƒäŸ‹
JavaScript
1
star
54

datafusion-postgres

Rust
1
star
55

greptimedb-metabase-driver

A metabase driver plugin for GreptimeDB
Clojure
1
star