module

Krikri::PluginHelpers::PostgresqlConnection

PostgresqlConnection - pure logic for building a postgres:// connection URI from Ansible-style login_* params. No I/O - postgresql_db.cr/postgresql_user.cr do the actual DB.open.

Constants

DEFAULT_UNIX_SOCKET_DIR = "/var/run/postgresql"

unix_socket, given, takes precedence over host/port (matches real Ansible's postgresql_db/postgresql_user own login_unix_socket precedence). crystal-pg expects a unix socket path via a "host" query param, not the URI's own host component (verified against its actual conninfo parsing source, not assumed) - the URI host is left blank in that case. Debian/Ubuntu's postgresql-common packaging (the target of every real-host benchmark round so far) compiles libpq's default Unix socket directory to this path - matches postgresql.conf's own unix_socket_directories default there.

Class methods

build_uri(host : String | Nil = nil, port : String | Nil = nil, user : String | Nil = nil, password : String | Nil = nil, unix_socket : String | Nil = nil, dbname : String | Nil = nil, sslmode : String | Nil = nil) : String
Source
resolve_login_params(params : Hash(String, String)) : NamedTuple(host: String | Nil, port: String | Nil, user: String | Nil, password: String | Nil, unix_socket: String | Nil)

Resolves the login_host:/login_port:/login_user:/ login_unix_socket: params from a plugin's raw @params, falling back to each one's real-Ansible deprecated alias (host:/port:/login:/unix_socket: respectively - login_password: has none) when the canonical login_* form isn't set. Shared by postgresql_db.cr/postgresql_user.cr/ postgresql_privs.cr so the alias list only lives in one place.

Real bug found benchmarking robertdebock.postgres (round 43): its own "Create postgres users" task writes port: "{{ postgres_port }}" (the alias, for a non-default port like 6543) - each plugin only ever read login_port:, so the connection silently fell back to port 5432's Unix socket instead, which doesn't exist on this host at all (DB::ConnectionRefused / PQ::ConnectionError: Cannot establish connection, confirmed via direct debug instrumentation against a live host - the same URI, built by hand with the correct port included, connected via psql immediately).

Source