[9.x] Alternative database name in Postgres DSN, allow pgbouncer aliased databases to continue working on 9.x #43542
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I encountered this issue that prevented migrations from running after upgrading to Laravel 9: #43536 (
php artisan migratefails after attempting to createmigrationstable that already exists)It is caused by my (fringe?) pgbouncer setup + the introduction of the
table_catalogparameter into queries in 9.x via #35530Here's a repo to reproduce the issue: https://github.com/AlbinoDrought/l9-pgsql-pgbouncer-alias
When using pgbouncer, the "database" name used to connect is just a pool name - pgbouncer can connect to a differently-named database behind the scenes. As an example, a
sample_appdatabase could have asample_app_backgroundpool and asample_app_webpool. In Laravel you would specify['database' => 'sample_app_background']or['database' => 'sample_app_web']to connect.In Laravel <9, the
databaseconfig var does not appear to be referenced by thePostgresConnectorafter DSN generation. The above pgbouncer setup works transparently.In Laravel 9, the
databaseconfig var is referenced duringPostgresConnectorDSN generation,hasTable, andgetColumnListing. The above pgbouncer setup now causes issues.If we're connected to the
sample_app_webpool,hasTableandgetColumnListingqueryinformation_schemaabout thesample_app_webdatabase, but that database doesn't exist. This causeshasTableto always returnfalsewhich is problematic during migrations. We wanthasTableandgetColumListingto query about thesample_appdatabase instead.I don't know what
getColumnListingis used for (something about guarded attributes?) but it also references thedatabaseconfig var, possibly outside of migrations.This proposed fix allows specifying a different database name used only during
PostgresConnectorDSN generation. The pool name should be specified here. I currently chose the config namedatabase_connectbut don't really like it. Users would specify a config like['database' => 'sample_app', 'database_connect' => 'sample_app_web']to continue using a pgbouncer setup like above.I'm not sure how common this kind of setup is. If this change isn't wanted upstream, it can be accomplished by overriding PostgresConnector in a third-party package (this is what I'm currently doing).
Thanks!