PostgreSQL & PGWire

QuestDB supports the Postgres Wire Protocol (PGWire) for data-in.

For querying and data-out, QuestDB is compatible with PostgreSQL protocol.

This means that you can use your favorite PostgreSQL client or driver with QuestDB.

For information querying and data-out, see the Querying & SQL Overview

note

The PostgreSQL storage model is fundamentally different than that of QuestDB.

As a result, some features that exists for PostgreSQL do not exist in QuestDB.

Ingest examples

This example uses the psycopg3 adapter.

To install the client library, use pip:

python3 -m pip install "psycopg[binary]"
import psycopg as pg
import time

# Connect to an existing QuestDB instance

conn_str = 'user=admin password=quest host=127.0.0.1 port=8812 dbname=qdb'
with pg.connect(conn_str, autocommit=True) as connection:

# Open a cursor to perform database operations

with connection.cursor() as cur:

# Execute a command: this creates a new table

cur.execute('''
CREATE TABLE IF NOT EXISTS test_pg (
ts TIMESTAMP,
name STRING,
value INT
) timestamp(ts);
''')

print('Table created.')

# Insert data into the table.

for x in range(10):

# Converting datetime into millisecond for QuestDB

timestamp = time.time_ns() // 1000

cur.execute('''
INSERT INTO test_pg
VALUES (%s, %s, %s);
''',
(timestamp, 'python example', x))

print('Rows inserted.')

#Query the database and obtain data as Python objects.

cur.execute('SELECT * FROM test_pg;')
records = cur.fetchall()
for row in records:
print(row)

# the connection is now closed

For query examples, see Query & SQL Overview.

Query examples

For full query details and examples, see the PostgreSQL section in the Query & SQL Overview.

Compatibility

List of supported features

  • Querying (all types expect BLOB)
  • Prepared statements with bind parameters
  • INSERT statements with bind parameters
  • UPDATE statements with bind parameters
  • DDL execution
  • Batch inserts
  • Plain authentication

List of supported connection properties

NameExampleDescription
databaseqdbShould be set to any value for example qdb, database name is ignored, QuestDB does not have database instance name
useradminUser name configured in pg.user or pg.readonly.user property in server.conf. Default value is admin
passwordquestPassword from pg.password or pg.readonly.password property in server.conf. Default value is quest
options-c statement_timeout=60000The only supported option is statement_timeout. It specifies maximum execution time in milliseconds for SELECT or UPDATE statement

List of unsupported features

  • SSL
  • Remote file upload (COPY from stdin)
  • DELETE statements
  • BLOB transfer

See PGWire client guides for more information about supported PostgreSQL clients and libraries.