Skip to content

Support Unix domain sockets for the cache PostgreSQL connection #9

Open

Description

@drag0n-app

Summary

When pgcache and its cache PostgreSQL run on the same host or in the same container (e.g. the official Docker image), [cache] currently only supports host/port over TCP. Please consider allowing a Unix socket directory as cache.host (libpq convention: a value starting with /), keeping TCP loopback as the default.

Motivation

  • On a cache hit, every query already goes pgcache → cache PostgreSQL, so this hop is on the hot path of every hit and adds per-query latency.
  • Unix sockets skip the TCP stack and need no exposed port. Access can be restricted via filesystem permissions, and multiple instances on one host avoid port conflicts.
  • The gain is likely modest and workload-dependent, so I'd suggest benchmarking before committing.

Proposal

  • Accept a directory path in cache.host (and --cache_host); the socket file is /.s.PGSQL..
  • Unix-only; TCP stays the default and the fallback on other platforms.
  • Benchmark TCP loopback vs. Unix socket with a read-heavy workload (e.g. pgbench -S through pgcache), comparing p50/p99 latency and throughput.

Thanks again for your time and for the great work on pgcache!

Activity

  1. philip-pgcache commented on Nov 25, 2026

    @philip-pgcache
    Contributor

    Well received and we're looking into it! Thanks for flagging this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions