Skip to content

Commit

Permalink
Merge pull request #798 from malapronta/pg_application_name
Browse files Browse the repository at this point in the history
Add application_name to PostgreSQL driver

fixes #1089
  • Loading branch information
deeky666 committed Jan 10, 2016
2 parents a2701b5 + 252975e commit f7bf60a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
4 changes: 3 additions & 1 deletion docs/en/reference/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ pdo\_pgsql
the server's certificate will be verified to be signed by one of these
authorities.
See http://www.postgresql.org/docs/9.0/static/libpq-connect.html#LIBPQ-CONNECT-SSLROOTCERT
- ``application_name`` (string): Name of the application that is
connecting to database. Optional. It will be displayed at ``pg_stat_activity``.

PostgreSQL behaves differently with regard to booleans when you use
``PDO::ATTR_EMULATE_PREPARES`` or not. To switch from using ``'true'``
Expand Down Expand Up @@ -290,7 +292,7 @@ pdo\_oci / oci8
database.
- ``instancename`` (string): Optional parameter, complete whether to
add the INSTANCE_NAME parameter in the connection. It is generally used
to connect to an Oracle RAC server to select the name of a particular instance.
to connect to an Oracle RAC server to select the name of a particular instance.


pdo\_sqlsrv / sqlsrv
Expand Down
6 changes: 5 additions & 1 deletion lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ private function _constructPdoDsn(array $params)
} else {
// Used for temporary connections to allow operations like dropping the database currently connected to.
// Connecting without an explicit database does not work, therefore "postgres" database is used
// as it is certainly present in every server setup.
// as it is certainly present in every server setup.
$dsn .= 'dbname=postgres' . ' ';
}

Expand All @@ -103,6 +103,10 @@ private function _constructPdoDsn(array $params)
$dsn .= 'sslrootcert=' . $params['sslrootcert'] . ' ';
}

if (isset($params['application_name'])) {
$dsn .= 'application_name=' . $params['application_name'] . ' ';
}

return $dsn;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,23 @@ protected function setUp()
}
}

/**
* @group DBAL-1146
*/
public function testConnectsWithApplicationNameParameter()
{
$parameters = $this->_conn->getParams();
$parameters['application_name'] = 'doctrine';

$user = isset($parameters['user']) ? $parameters['user'] : null;
$password = isset($parameters['password']) ? $parameters['password'] : null;

$connection = $this->driver->connect($parameters, $user, $password);
$statement = $connection->query('SELECT application_name FROM pg_stat_activity');

$this->assertSame('doctrine', $statement->fetchColumn());
}

/**
* {@inheritdoc}
*/
Expand Down

0 comments on commit f7bf60a

Please sign in to comment.