Skip to content

Commit

Permalink
[#13] Support Unix Domain Socket as a PostgreSQL connection
Browse files Browse the repository at this point in the history
  • Loading branch information
jesperpedersen committed Oct 27, 2021
1 parent c4718d4 commit cd898e1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions doc/CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ See a [sample](./etc/pgexporter.conf) configuration for running `pgexporter` on

Note, that PostgreSQL 10+ is required.

Note, that if `host` starts with a `/` it represents a path and `pgexporter` will connect using a Unix Domain Socket.

# pgexporter_users configuration

The `pgexporter_users` configuration defines the users known to the system. This file is created and managed through
Expand Down
14 changes: 13 additions & 1 deletion src/libpgexporter/security.c
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,19 @@ pgexporter_server_authenticate(int server, char* database, char* username, char*
memset(&security_messages[i], 0, SECURITY_BUFFER_SIZE);
}

ret = pgexporter_connect(config->servers[server].host, config->servers[server].port, &server_fd);
if (config->servers[server].host[0] == '/')
{
char pgsql[MISC_LENGTH];

memset(&pgsql, 0, sizeof(pgsql));
snprintf(&pgsql[0], sizeof(pgsql), ".s.PGSQL.%d", config->servers[server].port);
ret = pgexporter_connect_unix_socket(config->servers[server].host, &pgsql[0], &server_fd);
}
else
{
ret = pgexporter_connect(config->servers[server].host, config->servers[server].port, &server_fd);
}

if (ret != 0)
{
goto error;
Expand Down

0 comments on commit cd898e1

Please sign in to comment.