Skip to content

Commit 982a91d

Browse files
committed
Deprecate default PostgreSQL connection database
1 parent e7f7f28 commit 982a91d

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

UPGRADE.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ awareness about deprecated code.
88

99
# Upgrade to 3.5
1010

11+
## Deprecated default PostgreSQL connection database.
12+
13+
Relying on the DBAL connecting to the "postgres" database by default is deprecated. Unless you want to have the server
14+
determine the default database for the connection, specify the database name explicitly.
15+
1116
## Deprecated the "default_dbname" parameter of the wrapper `Connection`.
1217

1318
The "default_dbname" parameter of the wrapper `Connection` has been deprecated. Use "dbname" instead.

src/Driver/PDO/PgSQL/Driver.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,17 @@ private function constructPdoDsn(array $params): string
8282

8383
$dsn .= 'dbname=' . $params['default_dbname'] . ';';
8484
} else {
85+
if (isset($params['user']) && $params['user'] !== 'postgres') {
86+
Deprecation::trigger(
87+
'doctrine/dbal',
88+
'https://github.com/doctrine/dbal/pull/5705',
89+
'Relying on the DBAL connecting to the "postgres" database by default is deprecated.'
90+
. ' Unless you want to have the server determine the default database for the connection,'
91+
. ' specify the database name explicitly.',
92+
);
93+
}
94+
8595
// Used for temporary connections to allow operations like dropping the database currently connected to.
86-
// Connecting without an explicit database does not work, therefore "postgres" database is used
87-
// as it is mostly present in every server setup.
8896
$dsn .= 'dbname=postgres;';
8997
}
9098

0 commit comments

Comments
 (0)