Connecting
This page shows how clients reach the server: which protocol listens where, how TLS and unix sockets work, connection strings for psql and common drivers, and how a connection picks its database. Every flag named here is listed in Configuration.
Protocols and ports
| Protocol | Default address | Turned on by | Clients |
|---|---|---|---|
| PostgreSQL wire protocol | 127.0.0.1:5432 | --protocol pgwire or --protocol both | psql, libpq, JDBC, Npgsql, sqlx, tokio-postgres, node-postgres, psycopg, ORMs |
| Native protocol (rastcp) | 127.0.0.1:61170 | --protocol rastcp (the default) or --protocol both | rasterizeddb_client, the .NET client, Studio |
| MySQL / MariaDB | off | --mysql-port <PORT> or --mysql-socket <PATH> | mysql, mariadb, MySQL drivers |
| SQL Server (TDS) | off | --mssql-port <PORT> or --mssql-socket <PATH> | sqlcmd, Microsoft.Data.SqlClient, tiberius |
| Redis (RESP) | off | --kv-port <PORT> or --kv-socket <PATH> | redis-cli, Redis clients |
All of them serve the same databases and check logins against the same roles. Every listener binds 127.0.0.1 by default; give its address flag (--pg-addr, --rdb-addr, --mysql-addr, --mssql-addr, --kv-addr) the value 0.0.0.0 to accept other machines.
The default --protocol is rastcp, the native protocol alone. If psql reports "connection refused" on port 5432, start the server with --protocol both.
A typical server for both PostgreSQL clients and native clients, reachable from the network:
export RASTERIZEDDB_PG_PASSWORD='choose-a-strong-password'
rasterizeddb --location /var/lib/rasterizeddb --protocol both \
--pg-addr 0.0.0.0 --rdb-addr 0.0.0.0The message broker adds its own ports (--broker-port, --kafka-port, --amqp-port, --mqtt-port), all off unless given. See Message broker.
PostgreSQL protocol
TLS
--pg-tls decides what the PostgreSQL listener accepts over TCP:
--pg-tls | Cleartext connection | Encrypted connection | Client sslmode that works |
|---|---|---|---|
require (default) | refused with SQLSTATE 08004 | accepted | require |
prefer | accepted | accepted | disable, prefer, require |
disable | accepted | refused | disable, prefer |
With no --pg-cert/--pg-key, the server makes a new self-signed certificate at every start. A client can encrypt to it but cannot verify it, so sslmode=require (encrypt, do not verify) works and verify-ca/verify-full do not. To let clients verify the server, give it a certificate your clients trust:
rasterizeddb --location /var/lib/rasterizeddb --protocol both --pg-addr 0.0.0.0 \
--pg-cert /etc/rasterizeddb/server.crt --pg-key /etc/rasterizeddb/server.keyBoth files are PEM; the certificate file may hold the whole chain. The server warns at --log-level warn when the PostgreSQL listener is on a non-loopback address without --pg-tls require, since the login exchange and every row would then cross the network in the clear.
Authentication
--pg-auth sets how logins are checked: scram-sha-256 (the default), md5, password (cleartext, only safe under TLS) or trust (no check). See Security.
Connection strings
The examples use the default role rasterized, the default database postgres, and the default TLS setting with the self-signed certificate.
psql and libpq:
psql "postgresql://rasterized@db.example.com:5432/postgres?sslmode=require"
psql "host=db.example.com port=5432 user=rasterized dbname=postgres sslmode=require"Put the password in PGPASSWORD or ~/.pgpass rather than in the URL. With libpq, sslmode=require checks the certificate anyway if a root certificate file (~/.postgresql/root.crt) exists; move it aside, or give the server a certificate signed by that root.
JDBC (pgjdbc):
jdbc:postgresql://db.example.com:5432/postgres?user=rasterized&password=secret&sslmode=requireNpgsql (.NET):
Host=db.example.com;Port=5432;Database=postgres;Username=rasterized;Password=secret;SSL Mode=Require;Trust Server Certificate=trueTrust Server Certificate=true makes Npgsql versions before 8 accept the self-signed certificate. From Npgsql 8, SSL Mode=Require encrypts without verifying and the option is no longer needed.
sqlx (Rust): enable a TLS feature of sqlx (for example tls-rustls), then:
use sqlx::postgres::PgPoolOptions;
#[tokio::main]
async fn main() -> Result<(), sqlx::Error> {
let pool = PgPoolOptions::new()
.max_connections(5)
.connect("postgres://rasterized:secret@db.example.com:5432/postgres?sslmode=require")
.await?;
let row: (i64,) = sqlx::query_as("SELECT 1::BIGINT").fetch_one(&pool).await?;
assert_eq!(row.0, 1);
Ok(())
}tokio-postgres (Rust): tokio-postgres verifies certificates through whichever TLS connector you give it. On one machine, the simplest is a server started with --pg-tls prefer and a cleartext loopback connection:
use tokio_postgres::NoTls;
#[tokio::main]
async fn main() -> Result<(), tokio_postgres::Error> {
let (client, connection) = tokio_postgres::connect(
"host=127.0.0.1 port=5432 user=rasterized password=secret dbname=postgres sslmode=disable",
NoTls,
)
.await?;
tokio::spawn(connection);
let row = client.query_one("SELECT 1::BIGINT", &[]).await?;
let one: i64 = row.get(0);
assert_eq!(one, 1);
Ok(())
}Across a network, give the server a real certificate and use a verifying connector (tokio-postgres-rustls or postgres-native-tls).
node-postgres:
const { Client } = require("pg");
const client = new Client({
host: "db.example.com",
port: 5432,
user: "rasterized",
password: "secret",
database: "postgres",
ssl: { rejectUnauthorized: false },
});
(async () => {
await client.connect();
const result = await client.query("SELECT 1 AS one");
console.log(result.rows[0].one);
await client.end();
})();rejectUnauthorized: false accepts the self-signed certificate. With a real certificate, pass its CA instead: ssl: { ca: fs.readFileSync("ca.pem") }.
psycopg (Python):
import psycopg
with psycopg.connect("host=db.example.com port=5432 user=rasterized password=secret dbname=postgres sslmode=require") as conn:
print(conn.execute("SELECT 1").fetchone())Startup parameters
The server honours statement_timeout and lock_timeout sent at connect time, on their own or inside options:
psql "host=127.0.0.1 user=rasterized dbname=postgres sslmode=require options='-c statement_timeout=5s'"Other parameters a driver sends at startup (application_name, client_encoding, DateStyle) are accepted. The server reports itself as PostgreSQL 16.3 (server_version) with UTF8 encoding and the UTC time zone.
Cancelling a statement
PostgreSQL cancel requests are supported: Ctrl+C in psql, Statement.cancel() in JDBC, NpgsqlCommand.Cancel(), and the cancel token of other drivers stop the running statement.
Connection limits and timeouts
| Flag | Default | Effect |
|---|---|---|
--max-connections | 500 | One more session is refused with SQLSTATE 53300, "sorry, too many clients already". |
--authentication-timeout | 60s | A client that has not finished TLS and login by then is closed. |
--idle-in-transaction-session-timeout | off | Ends sessions idle inside a transaction (25P03). |
--idle-session-timeout | off | Ends idle sessions (57P05). |
Use a connection pool in the application, or PgBouncer in front of the server, when you need more clients than --max-connections.
Native protocol
The native protocol is what rasterizeddb_client (Rust), the .NET client and Studio use. Over TCP it is always TLS 1.3, and logins use SCRAM-SHA-256 bound to the TLS connection, so a password never crosses the wire and an intercepted exchange cannot be replayed onto another connection.
use rasterizeddb_client::{Client, Login, Options};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = Client::connect(
"db.example.com:61170",
Options {
login: Login::password("rasterized", "secret"),
database: Some("postgres".into()),
..Options::default()
},
)
.await?;
let rows = client.query("SELECT 1", &[]).await?;
println!("{} row", rows.len());
Ok(())
}See Rust client: connecting for every option, including verifying the server's certificate.
| Flag | Default | Effect |
|---|---|---|
--rdb-addr | 127.0.0.1 | A non-loopback address is refused at start unless a password is set (--rdb-password, RASTERIZEDDB_PASSWORD, or a role with one). |
--rdb-port | 61170 | |
--rdb-auth | scram-sha-256 | scram-sha-256 or trust. md5 and cleartext are not offered. |
--rdb-cert, --rdb-key | self-signed at every start | A certificate clients can verify. |
--rdb-request-timeout | 30 seconds | Longest one statement may run (57014); also closes connections idle that long. |
Under --protocol both the native protocol accepts the same role and password as the PostgreSQL side. Keep --pg-auth scram-sha-256 then: the native protocol answers only SCRAM, so a role whose password was stored for md5 cannot log in over it.
Unix sockets
On Linux every listener can also serve a unix socket for clients on the same machine, and its TCP port can be turned off. A socket has no TLS; who may connect is decided by the socket file's permissions.
| Listener | Socket flag | TCP off | Socket authentication |
|---|---|---|---|
| PostgreSQL | --pg-socket-dir DIR (creates DIR/.s.PGSQL.<pg-port>) | --pg-tcp off | --pg-socket-auth, defaults to --pg-auth |
| Native | --rdb-socket PATH | --rdb-tcp off | --rdb-socket-auth, defaults to --rdb-auth |
| MySQL | --mysql-socket PATH | leave out --mysql-port | --mysql-socket-auth |
| SQL Server | --mssql-socket PATH | leave out --mssql-port | --mssql-socket-auth |
| Redis | --kv-socket PATH | leave out --kv-port | --kv-auth |
rasterizeddb --location /var/lib/rasterizeddb --protocol both \
--pg-socket-dir /run/rasterizeddb --pg-socket-auth peer \
--rdb-socket /run/rasterizeddb/native.sock \
--socket-mode 660 --socket-group appConnect over the PostgreSQL socket by giving the directory as the host:
psql "host=/run/rasterizeddb port=5432 user=$USER dbname=postgres"--socket-mode(octal, default600) and--socket-groupapply to every socket. Connecting needs write permission, so660with a group admits that group's members, which is how a service running as another user gets access.peerauthentication, offered on sockets only, logs a role in without a password when its name is the operating-system user connecting. The role must exist and be allowed to log in.trustis allowed on a socket only when its mode admits nobody outside its owner and group.- A socket file left behind by a server that did not shut down is replaced at start. One another server is listening on is refused.
- A socket path must fit in about 107 bytes on Linux.
- Under
--pg-socket-dira TLS request is answered "no", whatever--pg-tlssays, so--pg-tls requireapplies to TCP only.
MySQL and SQL Server clients
rasterizeddb --location /var/lib/rasterizeddb --protocol both \
--mysql-port 3306 --mssql-port 1433
mysql -h 127.0.0.1 -P 3306 -u rasterized -p postgres
sqlcmd -S 127.0.0.1,1433 -U rasterized -P 'secret' -d postgres -CMySQL clients log in with caching_sha2_password; a role's first login over TCP needs TLS, which the mysql client uses by default. SQL Server clients use SQL Server authentication (Windows authentication is not offered); -C makes sqlcmd accept the self-signed certificate. Both listeners use --pg-cert/--pg-key unless given their own. What each dialect supports is on MySQL and SQL Server clients.
Redis clients
rasterizeddb --location /var/lib/rasterizeddb --protocol both --kv-port 6379
redis-cli -p 6379 --user rasterized --pass 'secret' PINGAUTH <password> without a user name is checked as --kv-user (default --pg-user). See Key/value cache.
Selecting a database
Each connection works in one database, chosen when it connects. A name that does not exist is refused with SQLSTATE 3D000, database "<name>" does not exist; the server never silently gives you a different database.
| Client | How to name the database |
|---|---|
| libpq URL | the path: postgresql://host/analytics |
| libpq keywords | dbname=analytics |
| JDBC | the path: jdbc:postgresql://host:5432/analytics |
| Npgsql | Database=analytics |
rasterizeddb_client | Options::database |
| MySQL | the database argument, or USE analytics |
| SQL Server | -d analytics, or Database= in the connection string |
A connection that names none gets --pg-default-db (postgres by default), the database stored in the data directory itself. Roles are per database: a login is checked against the roles of the database the connection names. See Databases.
Limits
- Unix sockets and
peerauthentication are Linux-only. - The self-signed certificate changes at every start, so it cannot be pinned. Use
--pg-cert/--rdb-certfor clients that verify. --max-connectionshas no unlimited setting.- A transaction cannot span two databases; open one connection per database.