weed/server/postgres/README.md
This package implements PostgreSQL wire protocol support for SeaweedFS, enabling universal compatibility with PostgreSQL clients, tools, and applications.
weed/server/postgres/
├── README.md # This documentation
├── server.go # Main PostgreSQL server implementation
├── protocol.go # Wire protocol message handlers with MQ integration
├── DESIGN.md # Architecture and design documentation
└── IMPLEMENTATION.md # Complete implementation guide
server.goprotocol.goThe PostgreSQL server now directly integrates with SeaweedFS Message Queue topics, providing:
weed-sql commandUSE database syntaximport "github.com/seaweedfs/seaweedfs/weed/server/postgres"
config := &postgres.PostgreSQLServerConfig{
Host: "localhost",
Port: 5432,
AuthMethod: postgres.AuthMD5,
Users: map[string]string{"admin": "secret"},
Database: "default",
MaxConns: 100,
IdleTimeout: time.Hour,
}
server, err := postgres.NewPostgreSQLServer(config, "localhost:9333")
if err != nil {
return err
}
err = server.Start()
if err != nil {
return err
}
// Server is now accepting PostgreSQL connections
The package supports three authentication methods:
AuthMethod: postgres.AuthTrust
AuthMethod: postgres.AuthPassword,
Users: map[string]string{"user": "password"}
AuthMethod: postgres.AuthMD5,
Users: map[string]string{"user": "password"}
Enable TLS encryption for secure connections:
cert, err := tls.LoadX509KeyPair("server.crt", "server.key")
if err != nil {
return err
}
config.TLSConfig = &tls.Config{
Certificates: []tls.Certificate{cert},
}
This implementation is compatible with:
psql - PostgreSQL command line clientpgcli - Enhanced command line with auto-completionSELECT * FROM topic_name;
SELECT id, message FROM topic_name WHERE condition;
SELECT COUNT(*) FROM topic_name;
SELECT MIN(id), MAX(id), AVG(amount) FROM topic_name;
SHOW DATABASES;
SHOW TABLES;
DESCRIBE topic_name;
DESC topic_name;
SELECT version();
SELECT current_database();
SELECT current_user;
SELECT id, message, _timestamp_ns, _key, _source FROM topic_name;
The package provides PostgreSQL-compliant error responses:
Run PostgreSQL package tests:
go test ./weed/server/postgres
Use the provided Python test client:
python postgres-examples/test_client.py --host localhost --port 5432
Connect with psql:
psql -h localhost -p 5432 -U seaweedfs -d default
weed-db -help✅ POSTGRESQL ONLY: SeaweedFS SQL engine exclusively supports PostgreSQL syntax:
engine.go uses custom PostgreSQL parser for proper dialect supportKey Benefits of PostgreSQL Parser:
pg_catalog, information_schema queries|| string concatenation, PostgreSQL-specific operatorsPostgreSQL Syntax Support:
") for identifiers|| operatorpg_catalog) and functionsImplementation Features:
protocol.goSELECT version(), BEGIN, etc.)This package provides enterprise-grade PostgreSQL compatibility, enabling seamless integration of SeaweedFS with the entire PostgreSQL ecosystem.