Jump toSuggest an edit
Solving connection errors
Reviewed on 07 February 2024 • Published on 07 February 2024
Database hostname wasn’t sent to server
Problem
The error message below appears when trying to connect to the Serverless SQL Database:
Error: pq: Database hostname wasn't sent to server
Cause
This error happens when the SQL client you are using does not support the TLS Server Name Indication (SNI) feature.
Solution
-
If you are using a third-party tool or library which allows you to input a connection string or optional connection parameters, add
?options=databaseid%3D{databaseid}
at the end of your connection string:"postgresql://{username}:{password}@{host}:5432/{databasename}?sslmode=require&options=databaseid%3D{databaseid}"Or
terraform {backend "pg" {conn_str = "postgresql://{username}:{password}@{host}:5432/{databasename}?sslmode=require&options=databaseid%3D{databaseid}"}required_providers {scaleway = {source = "scaleway/scaleway"}}required_version = ">= 0.13"} -
If you cannot modify the connection string or optional connection parameters, upgrade or change your client library. Refer to the table below for the most common libraries and tools supporting SNI.
Language Library / Tool SNI support Workaround to Partial Support Nodejs node-postgres Yes Nodejs postgres.js Yes Python psycopg2 Yes Python SQLAlchemy Yes Java pgjdbc Yes Go lib/pq Partial Upgrade lib/pq to v1.10.7, which supports SNI. Dart postgres Yes N/A psql Yes N/A pgcli Yes N/A pgAdmin Yes N/A DBeaver Yes N/A Postico 2 Yes N/A IntelliJ (SQL Module) Yes N/A navicat No N/A Stitch No N/A Terraform No Terraform includes an older lib/pq version (v1.10.3) which doesn’t support SNI.