Fixed "database "" does not exist" error from parallel worker
Description
In Babelfish, we have concept of logical database which is different concept from physical database of Postgres. In Babelfish, we host multiple logical database under one physical database. And hence when planner spawn parallel worker for any backend then it would communicate physical database and logical database may remain NULL or empty string which may subsequently run into an error like "database "" does not exist". Note that this error might be raised upon accessing every schema qualified object.
This commit fixes this issue by creating internal only GUC called, babelfishpg_tsql.current_database which would be set appropriately when USE
Note on GUC
This GUC is not user settable neither can be set through postgresql.conf or postgresql.conf.auto configurations:
jdbc_testdb=# alter system set babelfishpg_tsql.current_database = 'master';
ERROR: parameter "babelfishpg_tsql.current_database" cannot be changed
jdbc_testdb=# set babelfishpg_tsql.current_database = 'master';
ERROR: parameter "babelfishpg_tsql.current_database" cannot be changed
postgres=# \c jdbc_testdb
WARNING: parameter "babelfishpg_tsql.current_database" cannot be changed
You are now connected to database "jdbc_testdb" as user "dddhamel".
jdbc_testdb=# show babelfishpg_tsql.current_database;
babelfishpg_tsql.current_database
-----------------------------------
(1 row)
select set_config('babelfishpg_tsql.current_database', 'ext', 'false')
--------
Msg 33557097, Level 16, State 1, Line 9
parameter "babelfishpg_tsql.current_database" cannot be changed
Issues Resolved
Task: BABEL-4420
Test Scenarios Covered
Given JDBC test cases are sufficient but currently parallel worker is running into other crashes or issues so we can not really show tests here.
Check List
- [x] Commits are signed per the DCO using --signoff
By submitting this pull request, I confirm that my contribution is under the terms of the Apache 2.0 and PostgreSQL licenses, and grant any person obtaining a copy of the contribution permission to relicense all or a portion of my contribution to the PostgreSQL License solely to contribute all or a portion of my contribution to the PostgreSQL open source project.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.