DSN Reference
Last updated
Was this helpful?
Last updated
Was this helpful?
Was this helpful?
DSN stands for Data Source Name (or Database Source Name) and defines how to connect to your database. The substreams-sink-sql
tool expects a URL input that specifies the driver, connection details, and options.
The generic format of a DSN is:
<scheme>://<username>:<password>@<hostname>:<port>/<database_name>?<options>
The URL's scheme determines the database driver to use (postgres
, clickhouse
, etc.).
postgres://<user>:<password>@<host>:<port>/<database>?<options>
# Alternative schemes also supported:
psql://<user>:<password>@<host>:<port>/<database>?<options>
# Basic connection
postgres://myuser:mypassword@localhost:5432/mydatabase
# With SSL disabled
postgres://myuser:mypassword@localhost:5432/mydatabase?sslmode=disable
# With specific schema
postgres://myuser:mypassword@localhost:5432/mydatabase?schema=public
# Multiple options
postgres://myuser:mypassword@localhost:5432/mydatabase?sslmode=disable&schema=analytics
PostgreSQL DSN supports all options from libpq official documentation. Common options include:
sslmode
: SSL connection mode (disable
, require
, verify-ca
, verify-full
)
schema
: Select a particular schema within the database
connect_timeout
: Connection timeout in seconds
application_name
: Application name for connection tracking
Do not pass user
, password
, host
, port
, or dbname
in the options query parameters as they are automatically extracted from the DSN URL.
clickhouse://<user>:<password>@<host>:<port>/<database>?<options>
# Local ClickHouse (unencrypted)
clickhouse://default:@localhost:9000/default
# ClickHouse with authentication
clickhouse://myuser:mypassword@localhost:9000/mydatabase
# ClickHouse Cloud (encrypted)
clickhouse://default:[email protected]:9440/default?secure=true
# With additional options
clickhouse://myuser:mypassword@localhost:9000/mydatabase?compress=true&debug=true
Unencrypted
9000
Standard ClickHouse native protocol port
Encrypted (Cloud)
9440
Native protocol SSL/TLS port for ClickHouse Cloud
HTTP
8123
HTTP interface (not supported by substreams-sink-sql)
HTTPS
8443
HTTPS interface (not supported by substreams-sink-sql)
secure
: Enable TLS encryption (true
/false
)
skip_verify
: Skip TLS certificate verification (true
/false
)
compress
: Enable compression (true
/false
)
debug
: Enable debug logging (true
/false
)
DSN strings support environment variable substitution using the format ${VARIABLE_NAME}
:
# Using environment variables
export DB_USER="myuser"
export DB_PASS="mypassword"
export DSN="postgres://${DB_USER}:${DB_PASS}@localhost:5432/mydatabase"
substreams-sink-sql from-proto $DSN ./substreams.yaml
ClickHouse "read: EOF" error:
Add ?secure=true
to your DSN for ClickHouse Cloud
Ensure you're using port 9440
for encrypted connections
PostgreSQL connection refused:
Verify the port (usually 5432
)
Check if sslmode=disable
is needed for local development
Authentication failures:
Ensure username and password are URL-encoded if they contain special characters
Verify database user has appropriate permissions
If your username, password, or database name contains special characters, they must be URL-encoded:
# Special characters in password
postgres://myuser:my%40password@localhost:5432/mydatabase
# Special characters in username
postgres://my%2Buser:mypassword@localhost:5432/mydatabase