sunng87/pgwire
sunng87/pgwire has 811 GitHub stars and 90 forks. GitHot measured 0 stars in 24 hours. Last checked 2026-11-09 06:49 UTC. Last push 2026-11-02.
PostgreSQL wire protocol implemented as a rust library.
Measured star growth
- in 24h
- 0
- in 7 days
- Update delayed
- in 15 days
- Update delayed
- in 1 month
- Update delayed
Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.
README.md
Originalpgwire
Build Postgres compatible access layer for your data service.
This library implements PostgreSQL Wire Protocol, and provide essential APIs to write PostgreSQL compatible servers and clients. It's like hyper, but for postgres wire protocol.
The datafusion-postgres project is a more complete library built on top of pgwire, with datafusion as query engine, as well as pg_catalog implementation over datafusion.
If you are interested in related topic, you can check project ideas to build on top of this library.
Status
- Message format
- Frontend-Backend protocol messages
- 3.0
- 3.2, Postgres 18
- Streaming replication protocol
- Logical streaming replication protocol message
- Frontend-Backend protocol messages
- Backend TCP/TLS server on Tokio
- Frontend TCP/TLS client on Tokio
- Frontend-Backend interaction over TCP
- SSL Request and Response
- PostgreSQL 17 direct SSL negotiation
- GSSAPI Request and Response: GSSAPI encryption is not supported
- Startup
- Protocol negotiation
- No authentication
- Clear-text password authentication
- Md5 Password authentication
- SASL SCRAM authentication
- SCRAM-SHA-256
- SCRAM-SHA-256-PLUS
- SASL OAUTH
- Simple Query and Response
- Extended Query and Response
- Parse
- Bind
- Execute
- Describe
- Sync
- Termination
- Cancel
- Error and Notice
- Copy
- Notification
- SSL Request and Response
- Streaming replication over TCP
- Logical streaming replication over TCP
- Data types
- Text format
- Binary format, implemented in
postgres-types
- APIs
- Backend/Server
- 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
- ResultSet builder/encoder API
- Query Cancellation API
- Error and Notice API
- Copy API
- Copy-in
- Copy-out
- Copy-both
- Transaction state
- Streaming replication over TCP
- Logical streaming replication server API
- Startup APIs
- Frontend/Client
- Startup APIs
- Simple Query API
- Extended Query API
- ResultSet decoder API
- Query Cancellation API
- Error and Notice API
- Copy API
- Transaction state
- Streaming replication over TCP
- Logical streaming replication server API
- Backend/Server
About Postgres Wire Protocol
Postgres Wire Protocol is a relatively general-purpose Layer-7 protocol. There are 6 parts of the protocol:
- Startup: client-server handshake and authentication.
- Simple Query: The text-based 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.
- Copy: the subprotocol to copy data from and to postgresql.
- Replication
- Logical Replication
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.
Jelte Fennema-Nio's on talk on PgConf.dev 2024 has a great coverage of how the wire protocol works: https://www.youtube.com/watch?v=nh62VgNj6hY
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.cargo run --features _sqlite --example sqliteexamples/duckdb.rs: Now moved to pgwire-duckdbexamples/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: SCRAMexamples/transaction.rs: see how to control transaction state at wire protocol level.examples/datafusion.rs: Now moved to datafusion-postgresexamples/oauth.rs,examples/keycloak_oauth.rs: Examples for Postgres 18 OAuth authentication.
Client/Frontend
The client/frontend API is progress of development. This API will focus on providing full access of postgres wire protocol. It's designed to build components like postgres proxy. For general purpose postgres driver for application development, you can use rust-postgres.
Projects using pgwire
- GreptimeDB: Cloud-native time-series database
- risinglight: OLAP database system for educational purpose
- PeerDB Postgres first ETL/ELT, enabling 10x faster data movement in and out of Postgres, acquired by Clickhouse
- CeresDB CeresDB is a high-performance, distributed, cloud native time-series database from AntGroup.
- dozer a real-time data platform for building, deploying and maintaining data products.
- pg_catalog Provides a postgres compatibility layer for custom databases.
- SpacetimeDB The database for multiplayer games. It's using pgwire for postgres protocol interface.
- corrosion from fly.io: Gossip-based service discovery (and more) for large distributed systems.
- db9.ai: Postgres but for agents.
Submit a pull request if your project isn't listed here.
Community
Developer Mailing List
If you like the idea of pgwire and want to join the development of the library, or its ecosystem integrations, extensions, you are welcomed to join our developer mailing list: https://groups.io/g/pgwire-dev/
Github Discussion
Github discussion of this repo is also open for more generate questions.
License
This library is released under MIT/Apache dual license.
Explore related projects
Asabeneh/30-Days-Of-Python
The 30 Days of Python programming challenge is a step-by-step guide to learn the Python programming language in 30 days. This challenge may take more than 100 days. Follow your own pace. These videos may help too: https://www.youtube.com/channel/UC7PNRuno1rzYPb1xLa4yktw
78,423 starsgrafana/grafana
The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
77,790 starsredis/redis
For developers, who are building real-time data-driven applications, Redis is the preferred, fastest, and most feature-rich cache, data structure server, and document and vector query engine.
77,309 starsapache/superset
Apache Superset is a Data Visualization and Data Exploration Platform
75,455 stars