Unix Domain Sockets Quickstart
Unix Domain Sockets Quickstart
Available since: v3.14.0 (2026-04-20) — first shipped alongside the Drizzle compat milestone
Build: Unix only (Linux / macOS) — Windows builds are TCP-only
Endpoints: --pg-socket-dir <DIR> (PostgreSQL), --mysql-socket <PATH> (MySQL)
UVP
When your client lives on the same host as the database, the TCP loopback round-trip is paid overhead. HeliosDB Nano can listen on Unix domain sockets for both the PostgreSQL and MySQL wire protocols — psql -h /tmp connects via the libpq default, and PHP mysqli / WordPress with DB_HOST=':/tmp/heliosdb-mysql.sock' works without any TCP. Lower latency, no port conflicts, file-permission ACLs instead of firewall rules. Perfect for embedded same-host deployments.
1. Start with Both Sockets
heliosdb-nano start --memory \ --pg-socket-dir /tmp \ --mysql --mysql-socket /tmp/heliosdb-mysql.sockThe output prints the connection one-liners you’ll use:
psql (UDS): psql -h /tmp -p 5432 mysql (UDS): mysql --socket=/tmp/heliosdb-mysql.sockWhat the flags do:
| Flag | Effect |
|---|---|
--pg-socket-dir /tmp | Bind a Unix listener at /tmp/.s.PGSQL.5432 (libpq’s standard path: <dir>/.s.PGSQL.<port>). The directory is created if missing. |
--mysql --mysql-socket /tmp/heliosdb-mysql.sock | Bind a Unix listener at the exact path you specify. The MySQL TCP listener (--mysql) is independent — pass --mysql-socket alone if you want UDS-only. |
Both sockets get permissive 0o777 mode at startup so any local user can connect (file permissions are the access-control layer, not the wire protocol).
Stale socket files from a previous run are removed before bind. On clean shutdown (Ctrl-C) the files are unlinked again.
2. Connect with psql
psql -h /tmplibpq treats any host that starts with / as a directory containing the socket file. The default port is 5432, so psql -h /tmp resolves to /tmp/.s.PGSQL.5432. Override with -p 5433 for a non-default port.
Same connection from a libpq app:
import psycopg2conn = psycopg2.connect(host="/tmp", dbname="postgres", user="postgres")PGHOST=/tmp psqlPGHOST=/tmp PGUSER=postgres python myapp.pyThe PGHOST env var is libpq’s official knob — most ORMs honour it.
3. Connect with mysql
mysql --socket=/tmp/heliosdb-mysql.sockWelcome to the MySQL monitor.Server version: 8.0.35-HeliosDB-Nanomysql>Or from a config file (~/.my.cnf):
[client]socket = /tmp/heliosdb-mysql.sockuser = root…and then mysql with no flags works.
4. PHP mysqli (Same-Host Apps)
<?php// The leading colon tells mysqli the value is a socket path.$db = new mysqli("localhost:/tmp/heliosdb-mysql.sock", "root", "", "mydb");
// Or pass the path explicitly as the socket argument:$db = new mysqli(null, "root", "", "mydb", 0, "/tmp/heliosdb-mysql.sock");
$result = $db->query("SELECT VERSION()");print_r($result->fetch_row());For WordPress, set DB_HOST in wp-config.php:
define('DB_HOST', 'localhost:/tmp/heliosdb-mysql.sock');See WORDPRESS_DROP_IN.
5. Why Use Unix Sockets
- Latency. No TCP three-way handshake, no Nagle’s algorithm, no loopback IP stack — just a kernel pipe.
- No port conflicts. Run two HeliosDB instances on the same host with different socket paths.
- File-system ACLs. Restrict access by chmod / chown on the socket file. The 0o777 default is permissive; chmod to
0o660and chown to your app user for production. - No
bind: address already in useflakes during fast restart cycles in CI. - Container-friendly when you mount a tmpfs or hostPath shared between containers in the same pod / compose project.
6. Coexistence with TCP
The Unix listeners are additional to TCP, not a replacement:
# Start with both TCP and UDS:heliosdb-nano start --memory \ --port 5432 --pg-socket-dir /tmp \ --mysql --mysql-listen 127.0.0.1:3306 --mysql-socket /tmp/heliosdb-mysql.sockNow any of the four addresses work:
psql -h 127.0.0.1 -p 5432(PG TCP)psql -h /tmp -p 5432(PG UDS)mysql -h 127.0.0.1 -P 3306(MySQL TCP)mysql --socket=/tmp/heliosdb-mysql.sock(MySQL UDS)
All four read and write the same data.
Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: No such file or directory | Server not started with --pg-socket-dir | Add the flag and restart |
mysqli::__construct: No such file or directory | Wrong path in $socket argument | Verify with ls -l /tmp/heliosdb-mysql.sock |
Permission denied on connect | Custom umask narrowed the socket mode | Confirm with ls -l; chmod to 0660 + chown to your app user as needed |
| Socket file persists after crash | Server didn’t exit cleanly | Manually rm /tmp/heliosdb-mysql.sock (or rely on the next start to clear it) |
Windows: --pg-socket-dir is silently ignored | Unix sockets unavailable on Windows | Use TCP on Windows |
Where Next
- WORDPRESS_DROP_IN — same-host PHP / WordPress over MySQL UDS.
- MYSQL_WIRE — full MySQL protocol coverage.
- DRIZZLE_PRISMA_COMPAT — TypeScript ORMs over the PostgreSQL wire (TCP or UDS).