diff --git a/Bugzilla/DB/Pg.pm b/Bugzilla/DB/Pg.pm index 695ea4640..6345df1ed 100644 --- a/Bugzilla/DB/Pg.pm +++ b/Bugzilla/DB/Pg.pm @@ -35,8 +35,8 @@ use constant BLOB_TYPE => {pg_type => DBD::Pg::PG_BYTEA}; sub BUILDARGS { my ($class, $params) = @_; - my ($user, $pass, $host, $dbname, $port) - = @$params{qw(db_user db_pass db_host db_name db_port)}; + my ($user, $pass, $host, $dbname, $port, $dbservice) + = @$params{qw(db_user db_pass db_host db_name db_port db_service)}; # The default database name for PostgreSQL. We have # to connect to SOME database, even if we have @@ -44,13 +44,24 @@ sub BUILDARGS { $dbname ||= 'template1'; # construct the DSN from the parameters we got - my $dsn = "dbi:Pg:dbname=$dbname"; - $dsn .= ";host=$host" if $host; - $dsn .= ";port=$port" if $port; + my $dsn; + if ($dbservice) { + $dsn = "dbi:Pg:service=$dbservice"; + } + elsif ($ENV{PGSERVICE}) { + $dbservice = $ENV{PGSERVICE}; + $dsn = "dbi:Pg:service=$dbservice"; + } + else { + $dsn = "dbi:Pg:dbname=$dbname"; + $dsn .= ";host=$host" if $host; + $dsn .= ";port=$port" if $port; + } # This stops Pg from printing out lots of "NOTICE" messages when # creating tables. - $dsn .= ";options='-c client_min_messages=warning'"; + $dsn .= ";options='-c client_min_messages=warning'" + unless $dbservice or $ENV{PGSERVICE}; my $attrs = {pg_enable_utf8 => Bugzilla->params->{'utf8'}}; diff --git a/Bugzilla/Install/Localconfig.pm b/Bugzilla/Install/Localconfig.pm index ee08842ee..7be7a79c0 100644 --- a/Bugzilla/Install/Localconfig.pm +++ b/Bugzilla/Install/Localconfig.pm @@ -57,6 +57,7 @@ use constant LOCALCONFIG_VARS => ( {name => 'webservergroup', default => \&_sensible_group,}, {name => 'use_suexec', default => 0,}, {name => 'db_driver', default => 'mysql',}, + {name => 'db_service', default => '',}, {name => 'db_host', default => 'localhost',}, {name => 'db_name', default => 'bugs',}, { diff --git a/template/en/default/setup/strings.txt.pl b/template/en/default/setup/strings.txt.pl index 54974aadb..2b0863418 100644 --- a/template/en/default/setup/strings.txt.pl +++ b/template/en/default/setup/strings.txt.pl @@ -178,6 +178,10 @@ END can be obtained by listing Bugzilla/DB directory - every module corresponds to one supported database and the name of the module (before ".pm") corresponds to a valid value for this variable. +END + localconfig_db_service => <<'END', +The name of the service defining the database connection +parameters. Replaces db_host, db_user, db_name. END localconfig_db_host => <<'END', The DNS name or IP address of the host that the database server runs on.