jackc/pgx · error

unable to find service

Error message

unable to find service: %v

What it means

The service named in the connection string was not found in the referenced pg_service.conf file. The message shows the service name that was looked up.

Solutions

  1. Check the service name spelling in the connection string
  2. Verify the service exists in the service file with a matching [section] header
  3. Confirm the correct service file is being read
  4. Add the missing service section to the file
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at pgconn/config.go:793 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of jackc/pgx@ec1a0befd2 (2026-08-04). Data as JSON: /api/errors/919f52a8d788a5cb. Report an issue: GitHub.

Appendix: source

Thrown at pgconn/config.go:793

		if key == "user" && val == "" {
			continue
		}
		settings[key] = val
	}

	return settings, nil
}

func parseServiceSettings(servicefilePath, serviceName string) (map[string]string, error) {
	servicefile, err := pgservicefile.ReadServicefile(servicefilePath)
	if err != nil {
		return nil, fmt.Errorf("failed to read service file: %v", servicefilePath)
	}

	service, err := servicefile.GetService(serviceName)
	if err != nil {
		return nil, fmt.Errorf("unable to find service: %v", serviceName)
	}

	settings := make(map[string]string, len(service.Settings))
	for k, v := range service.Settings {
		settings[canonicalConnStringKey(k)] = v
	}

	return settings, nil
}

// configTLS uses libpq's TLS parameters to construct  []*tls.Config. It is
// necessary to allow returning multiple TLS configs as sslmode "allow" and
// "prefer" allow fallback.
func configTLS(settings map[string]string, thisHost string, parseConfigOptions ParseConfigOptions) ([]*tls.Config, error) {
	host := thisHost
	sslmode := settings["sslmode"]
	sslrootcert := settings["sslrootcert"]
	sslcert := settings["sslcert"]

View on GitHub (pinned to ec1a0befd2)