From 1a13e49d965597d4ba2e0c4628cbe49c3cd9e313 Mon Sep 17 00:00:00 2001 From: Feike Steenbergen Date: Thu, 22 Jun 2017 13:39:20 +0200 Subject: [PATCH] Connect using Connection Service File For those who already have their Connection Service Files setup, it is useful not to have to specify the configuration file. By connection using the service= format we delegate all the resolving of service file locations to libpq. --- README.rst | 2 +- pg_view/__init__.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 0668dd0..f641464 100644 --- a/README.rst +++ b/README.rst @@ -69,7 +69,7 @@ By default, pg_view tries to autodetect all PostgreSQL clusters running on the s - checks all arguments, picking the first that allows it to establish a connection - if pg_view can't get either the port/host or port/socket_directory pair, bail out -If the program can't detect your connection arguments using the algorithm above, you can specify those arguments manually using the configuration file supplied with the -c option. This file should consist of one or more sections, each containing a key = value pair. +If the program can't detect your connection arguments using the algorithm above, you can specify those arguments manually using the configuration file supplied with the -c option. This file should consist of one or more sections, each containing a key = value pair. You can also use your Connection Service File. The title of each section represents a database cluster name (this name is for display purposes only). The dbname parameter is `postgres` by default, and specifies the actual name of the database to connect to. The key-value pairs should contain connection parameters. diff --git a/pg_view/__init__.py b/pg_view/__init__.py index cd9eb47..bb76d0f 100644 --- a/pg_view/__init__.py +++ b/pg_view/__init__.py @@ -204,6 +204,9 @@ def main(): if not establish_user_defined_connection(instance, conn, clusters): logger.error('failed to acquire details about ' + 'the database cluster {0}, the server will be skipped'.format(instance)) + elif options.instance: + if not establish_user_defined_connection(options.instance, {'service': options.instance}, clusters): + logger.error("unable to continue with cluster {0}".format(options.instance)) elif options.host: # try to connet to the database specified by command-line options conn = build_connection(options.host, options.port, options.username, options.dbname)