Overview
The PostgreSQL wire protocol provides:- SQL INSERT statements for data ingestion
- Standard PostgreSQL compatibility with psql, JDBC, and other drivers
- Prepared statements for efficient repeated inserts
- Authentication with username and password
- Full SQL support including DDL and queries
Configuration
Server Configuration
Configure PostgreSQL wire protocol inconf/server.conf:
Authentication
QuestDB uses cleartext password authentication by default:- Admin user: Full read/write access (default: admin/quest)
- Read-only user: Query-only access (optional, disabled by default)
Connecting to QuestDB
Using psql
Connect using the PostgreSQL command-line client:quest).
Using JDBC
Maven Dependency:Using Python (psycopg2)
Install:Using Node.js (pg)
Install:INSERT Syntax
Single Row Insert
Multiple Row Insert
INSERT with Column Names
INSERT from SELECT
Data Types
QuestDB PostgreSQL wire protocol supports standard SQL types:| SQL Type | QuestDB Type | Example |
|---|---|---|
| BOOLEAN | BOOLEAN | true |
| BYTE | BYTE | 127 |
| SHORT | SHORT | 32767 |
| INT | INT | 2147483647 |
| LONG | LONG | 9223372036854775807 |
| FLOAT | FLOAT | 3.14159 |
| DOUBLE | DOUBLE | 3.141592653589793 |
| STRING | STRING | ’text’ |
| SYMBOL | SYMBOL | ’symbol_value’ |
| TIMESTAMP | TIMESTAMP | ’2022-03-18T18:03:57.609Z’ |
| DATE | DATE | ’2022-03-18’ |
| UUID | UUID | ’11111111-1111-1111-1111-111111111111’ |
| LONG256 | LONG256 | ’0x123abc…’ |
| GEOHASH | GEOHASH | ##0110 |
Prepared Statements
Prepared statements improve performance for repeated inserts:JDBC Example
Python Example
Batch Inserts
For optimal performance, batch multiple rows in a single INSERT:Performance Optimization
Use WAL Tables
WAL (Write-Ahead Log) tables provide best INSERT performance:Batch Size
Optimal batch size depends on row size:- Small rows: 1000-5000 per batch
- Large rows: 100-500 per batch
Connection Pooling
Use connection pooling for concurrent inserts:Partition Strategy
Choose appropriate partitioning for your data:Limitations
Not Supported
- DELETE statements - Use DROP PARTITION or table recreation
- UPDATE statements - QuestDB is append-only
- Transactions - Auto-commit mode only
- Foreign keys - No referential integrity constraints
- Triggers - Not implemented
- Stored procedures - Not implemented
QuestDB-Specific SQL
Some QuestDB SQL extensions may not work through PostgreSQL wire:- SAMPLE BY (use SELECT instead)
- LATEST ON (use SELECT instead)
- Custom timestamp functions
/exec endpoint for QuestDB-specific SQL features.
Error Handling
Common Errors
Connection Refused:pg.enabled=true in server.conf
Authentication Failed:
Monitoring
Monitor PostgreSQL wire connections:/metrics endpoint:
questdb_pg_wire_connections- Active connectionsquestdb_pg_wire_queries_total- Total queries executed
Complete Example
Create and populate a table:Best Practices
- Use prepared statements - Better performance for repeated inserts
- Batch inserts - Group multiple rows in single INSERT
- Enable WAL - Best performance for streaming inserts
- Use symbols - For frequently repeated string values
- Specify timestamp - Don’t rely on system time for historical data
- Connection pooling - For concurrent applications
- Appropriate partitioning - Match data frequency
- Monitor connections - Check sys.connections table
Related Topics
- InfluxDB Line Protocol - High-throughput time-series ingestion
- REST API - HTTP endpoints for SQL execution
- SQL Reference - Complete SQL syntax guide