Message-ID: From: "MarekUniq (@MarekUniq)" To: "pgjdbc/pgjdbc" Date: Thu, 20 Oct 2022 19:12:49 +0000 Subject: [pgjdbc/pgjdbc] PR #2646: feat: improve libpq compatibility for URL parsing, environment variables, passfile, and property naming List-Id: X-GitHub-Author-Id: 42849684 X-GitHub-Author-Login: MarekUniq X-GitHub-Issue: 2646 X-GitHub-Repo: pgjdbc/pgjdbc X-GitHub-State: open X-GitHub-Type: pull_request X-GitHub-Url: https://github.com/pgjdbc/pgjdbc/pull/2646 Content-Type: text/plain; charset=utf-8 ### 1. Compatibility with libpq is improved regarding URL syntax and resolving url values #### 1.1. `user` and `password` are supported Complete syntax: `jdbc:postgresql://[[user][:password]@][host1[:port1][,host2[:port2]][,...]][/database][?property1=value1[&property2=value2][&...]]` URL may include: `user` (Optional) is the user to connect. Defaults to operating system username. `password` (Optional) is the password to connect. No default value. #### 1.2. property `passfile` is supported Example: ``` Properties props = new Properties(); PGProperty.PASSFILE.set(props, "/mydir/mypass"); Connection conn = DriverManager.getConnection(url, props); ``` #### 1.3. Code is more clear regarding Properties override rules (source and result are logged at FINE logging level) There are multiple sources for connection properties. If same property is specified in multiple sources then highest priority source is used. Priority list is here: ``` 1) URL arguments (values after `?` mark) 2) URL values (values before `?` mark) 3) Properties given to `DriverManager.getConnection()` 4) values provided by `service` (from resource `.pg_service.conf`) 5) values in Java System Properties 6) values in Operating System environment 7) values from driverconfig file(s) (`org/postgresql/driverconfig.properties`) 8) global defaults (`dbname`, `host`, `pgpass`, `port`, `user`) ``` #### 1.4. References Related to: #2260 #2278 #2398 #2393 #2395 #2424 #2569 #2641 #2644 ### All Submissions: * [x] Have you followed the guidelines in our [Contributing](https://github.com/pgjdbc/pgjdbc/blob/master/CONTRIBUTING.md) document? * [x] Have you checked to ensure there aren't other open [Pull Requests](../../pulls) for the same update/change? ### New Feature Submissions: 1. [x] Does your submission pass tests? 2. [x] Does `./gradlew autostyleCheck checkstyleAll` pass ? 6. [x] Have you added your new test classes to an existing test suite in alphabetical order? ### Changes to Existing Features: * [x] Have you added an explanation of what your changes do and why you'd like us to include them? * [x] Have you written new tests for your core changes, as applicable? * [x] Have you successfully run tests with your changes locally?