pgx

Code

package main

import (
  "context"
  "fmt"
  "os"

  "github.com/jackc/pgx/v5"
)

func main() {
  conn, err := pgx.Connect(context.Background(), os.Getenv("DATABASE_URL"))
  if err != nil {
    panic(err)
  }
  defer conn.Close(context.Background())

  var greeting string
  err = conn.QueryRow(context.Background(), "SELECT $1::text AS greeting", "Hello world!").Scan(&greeting)
  fmt.Println(greeting)
}

Elephantshark transcript

listening ...
connected at t0 = 2025-10-08 22:40:14 +0200
client -> script: "\x00\x00\x00\x08\x04\xd2\x16\x2f" = SSLRequest
script -> client: "S" = SSL supported
TLSv1.3/TLS_AES_128_GCM_SHA256 connection established with client
  server name via SNI: localhost
client -> script: "\x00\x00\x00\x26" = 38 bytes of startup message "\x00\x03\x00\x00" = protocol version
  "user\x00" = key "frodo\x00" = value
  "database\x00" = key "postgres\x00" = value
  "\x00" = end
connecting to Postgres server: localhost
script -> server: "\x00\x00\x00\x08\x04\xd2\x16\x2f" = SSLRequest
server -> script: "S" = SSL supported
TLSv1.3/TLS_AES_256_GCM_SHA384 connection established with server
forwarding client startup message to server
script -> server: "\x00\x00\x00\x26" = 38 bytes of startup message "\x00\x03\x00\x00" = protocol version
  "user\x00" = key "frodo\x00" = value
  "database\x00" = key "postgres\x00" = value
  "\x00" = end
forwarding all later traffic
server -> client: "R" = Authentication "\x00\x00\x00\x2a" = 42 bytes "\x00\x00\x00\x0a" = AuthenticationSASL
  "SCRAM-SHA-256-PLUS\x00" = SASL mechanism
  "SCRAM-SHA-256\x00" = SASL mechanism
  "\x00" = end
^^ 43 bytes forwarded at +0.02s, 0 bytes left in buffer
client -> server: "p" = SASLInitialResponse "\x00\x00\x00\x36" = 54 bytes
  "SCRAM-SHA-256\x00" = selected mechanism
  "\x00\x00\x00\x20" = 32 bytes follow
  "n,,n=,r=O3Js+vCSLTnARx3HaYCffxKW" = SCRAM client-first-message
^^ 55 bytes forwarded at +0.02s, 0 bytes left in buffer
server -> client: "R" = Authentication "\x00\x00\x00\x5c" = 92 bytes "\x00\x00\x00\x0b" = AuthenticationSASLContinue
  "r=O3Js+vCSLTnARx3HaYCffxKW2QrKcWJJ4cPBt/Z613xkW64r,s=ZPXsknNfrTfGBNripnqk4A==,i=4096" = SCRAM server-first-message
^^ 93 bytes forwarded at +0.03s, 0 bytes left in buffer
client -> server: "p" = SASLResponse "\x00\x00\x00\x6c" = 108 bytes
  "c=biws,r=O3Js+vCSLTnARx3HaYCffxKW2QrKcWJJ4cPBt/Z613xkW64r,p=eDFfKWC4372SBP5QQRiGViEPzDjuVa+sJYKd0bCny7Y=" = SCRAM client-final-message
^^ 109 bytes forwarded at +0.03s, 0 bytes left in buffer
server -> client: "R" = Authentication "\x00\x00\x00\x36" = 54 bytes "\x00\x00\x00\x0c" = AuthenticationSASLFinal
  "v=wc+oYw7eYP3cVRxAOYDOtk2QIQ4TcHRdoETo0V25zho=" = SCRAM server-final-message
server -> client: "R" = Authentication "\x00\x00\x00\x08" = 8 bytes "\x00\x00\x00\x00" = AuthenticationOk
server -> client: "S" = ParameterStatus "\x00\x00\x00\x17" = 23 bytes "in_hot_standby\x00" = key "off\x00" = value
server -> client: "S" = ParameterStatus "\x00\x00\x00\x19" = 25 bytes "integer_datetimes\x00" = key "on\x00" = value
server -> client: "S" = ParameterStatus "\x00\x00\x00\x15" = 21 bytes "TimeZone\x00" = key "Etc/UTC\x00" = value
server -> client: "S" = ParameterStatus "\x00\x00\x00\x1b" = 27 bytes "IntervalStyle\x00" = key "postgres\x00" = value
server -> client: "S" = ParameterStatus "\x00\x00\x00\x20" = 32 bytes "search_path\x00" = key "\"$user\", public\x00" = value
server -> client: "S" = ParameterStatus "\x00\x00\x00\x14" = 20 bytes "is_superuser\x00" = key "on\x00" = value
server -> client: "S" = ParameterStatus "\x00\x00\x00\x16" = 22 bytes "application_name\x00" = key "\x00" = value
server -> client: "S" = ParameterStatus "\x00\x00\x00\x26" = 38 bytes "default_transaction_read_only\x00" = key "off\x00" = value
server -> client: "S" = ParameterStatus "\x00\x00\x00\x1a" = 26 bytes "scram_iterations\x00" = key "4096\x00" = value
server -> client: "S" = ParameterStatus "\x00\x00\x00\x17" = 23 bytes "DateStyle\x00" = key "ISO, MDY\x00" = value
server -> client: "S" = ParameterStatus "\x00\x00\x00\x23" = 35 bytes "standard_conforming_strings\x00" = key "on\x00" = value
server -> client: "S" = ParameterStatus "\x00\x00\x00\x20" = 32 bytes "session_authorization\x00" = key "frodo\x00" = value
server -> client: "S" = ParameterStatus "\x00\x00\x00\x19" = 25 bytes "client_encoding\x00" = key "UTF8\x00" = value
server -> client: "S" = ParameterStatus "\x00\x00\x00\x31" = 49 bytes "server_version\x00" = key "18.0 (Debian 18.0-1.pgdg13+3)\x00" = value
server -> client: "S" = ParameterStatus "\x00\x00\x00\x19" = 25 bytes "server_encoding\x00" = key "UTF8\x00" = value
server -> client: "K" = BackendKeyData "\x00\x00\x00\x0c" = 12 bytes "\x00\x00\x00\x4b" = process ID "\x0a\xd6\x6b\x27" = secret key
server -> client: "Z" = ReadyForQuery "\x00\x00\x00\x05" = 5 bytes "I" = idle
^^ 521 bytes forwarded at +0.04s, 0 bytes left in buffer
client -> server: "P" = Parse "\x00\x00\x00\x5d" = 93 bytes "stmtcache_8adfd8f2df401f634e3f65386148c4141e63e4bbd1280d9e\x00" = destination prepared statement "SELECT $1::text AS greeting\x00" = SQL query "\x00\x00" = 0 parameter data types follow
client -> server: "D" = Describe "\x00\x00\x00\x40" = 64 bytes "S" = prepared statement "stmtcache_8adfd8f2df401f634e3f65386148c4141e63e4bbd1280d9e\x00" = name of prepared statement
client -> server: "S" = Sync "\x00\x00\x00\x04" = 4 bytes
^^ 164 bytes forwarded at +0.05s, 0 bytes left in buffer
server -> client: "1" = ParseComplete "\x00\x00\x00\x04" = 4 bytes
server -> client: "t" = ParameterDescription "\x00\x00\x00\x0a" = 10 bytes "\x00\x01" = number of parameters "\x00\x00\x00\x19" = parameter type OID: 25
server -> client: "T" = RowDescription "\x00\x00\x00\x21" = 33 bytes "\x00\x01" = 1 columns follow
  "greeting\x00" = column name "\x00\x00\x00\x00" = table OID: 0 "\x00\x00" = table attrib no: 0
  "\x00\x00\x00\x19" = type OID: 25 "\xff\xff" = type length: -1 "\xff\xff\xff\xff" = type modifier: -1 "\x00\x00" = format: text
server -> client: "Z" = ReadyForQuery "\x00\x00\x00\x05" = 5 bytes "I" = idle
^^ 56 bytes forwarded at +0.05s, 0 bytes left in buffer
client -> server: "B" = Bind "\x00\x00\x00\x5a" = 90 bytes "\x00" = destination portal "stmtcache_8adfd8f2df401f634e3f65386148c4141e63e4bbd1280d9e\x00" = source prepared statement
  "\x00\x01" = 1 parameter format codes follow "\x00\x00" = format: text
  "\x00\x01" = 1 parameter values follow "\x00\x00\x00\x0c" = 12 bytes follow "Hello world!" = parameter value
  "\x00\x01" = 1 result format codes follow "\x00\x00" = format: text
client -> server: "D" = Describe "\x00\x00\x00\x06" = 6 bytes "P" = portal "\x00" = name of portal
client -> server: "E" = Execute "\x00\x00\x00\x09" = 9 bytes "\x00" = portal name "\x00\x00\x00\x00" = max rows: 0 = no limit
client -> server: "S" = Sync "\x00\x00\x00\x04" = 4 bytes
^^ 113 bytes forwarded at +0.05s, 0 bytes left in buffer
server -> client: "2" = BindComplete "\x00\x00\x00\x04" = 4 bytes
server -> client: "T" = RowDescription "\x00\x00\x00\x21" = 33 bytes "\x00\x01" = 1 columns follow
  "greeting\x00" = column name "\x00\x00\x00\x00" = table OID: 0 "\x00\x00" = table attrib no: 0
  "\x00\x00\x00\x19" = type OID: 25 "\xff\xff" = type length: -1 "\xff\xff\xff\xff" = type modifier: -1 "\x00\x00" = format: text
server -> client: "D" = DataRow "\x00\x00\x00\x16" = 22 bytes "\x00\x01" = 1 columns follow
  "\x00\x00\x00\x0c" = 12 bytes "Hello world!" = column value
server -> client: "C" = CommandComplete "\x00\x00\x00\x0d" = 13 bytes "SELECT 1\x00" = command tag
server -> client: "Z" = ReadyForQuery "\x00\x00\x00\x05" = 5 bytes "I" = idle
^^ 82 bytes forwarded at +0.05s, 0 bytes left in buffer
client -> server: "X" = Terminate "\x00\x00\x00\x04" = 4 bytes
^^ 5 bytes forwarded at +0.06s, 0 bytes left in buffer
client hung up
connection end

listening ...
connection end