pgjdbc-ng | new JDBC driver for PostgreSQL | DB Client library
kandi X-RAY | pgjdbc-ng Summary
kandi X-RAY | pgjdbc-ng Summary
A new JDBC driver for PostgreSQL aimed at supporting the advanced features of JDBC and Postgres
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Maps a given codepoint from a given codepoint .
- Get JDBC type from value .
- Retrieves the properties of a procedure .
- Parse an IPv6 address .
- Parse a connection spec from a URL .
- Parse and dispatch a handler .
- Updates the system parameter with the given value .
- Returns the private key for the specified alias .
- Parses server address .
- Convert string to SASl format .
pgjdbc-ng Key Features
pgjdbc-ng Examples and Code Snippets
Community Discussions
Trending Discussions on pgjdbc-ng
QUESTION
We use connection pool in our application. While I understand that we should close and get connections as needed since we are using a connection pool. I implemented a cache update mechanism by receiving Postgres LISTEN
notifications. The code is pretty much similar to the canonical example given by the documentation.
As you can see in the code, the query is initiated in the constructor and the connection is re used. This may pose problem when the connection is closed out of band due to any factor. One solution to this is to get the connection before every use, but as you can see the statement is only executed once in the constructor but still I can receive the notification in the polling. So if I get the connection every time, it will force me to re issue the statement for every iteration(after delay). I'm not sure if that's an expensive operation.
What is the middle ground here?
...ANSWER
Answered 2022-Mar-08 at 03:01The connection pool is the servant, not the master. Keep the connection for as long as you are using it to LISTEN on, i.e. ideally forever. If the connection ever does close, then you will miss whatever notices were sent while it was closed. So to keep the cache in good shape, you would need to discard the whole thing and start over. Obviously not something you would want to do on a regular basis, or what would be the point of having it in the first place?
The other doc you show is just an ancient version of the first one. The dummy query just before polling is there to poke the underlying socket code to make sure it has absorbed all the messages. This is no longer necessary. I don't know if it ever was necessary, it might have just been some cargo cult that found its way into the docs.
You would probably be better off with the blocking version of this code, by using getNotifications(0)
and getting rid of sleep(delay)
. This will block until a notice becomes available, rather than waking up twice a second and consuming some (small) amount of resources before sleeping again. Also, once a notice does arrive it will be processed almost immediately, instead of waiting for what is left of a half-second timeout to expire (so, on average, about a quarter second).
QUESTION
I am using Spring Boot 2.4.0 with Spring Boot Data JPA to connect to PostgreSQL and perform typical read and write operations with JPA based repositories. Since the database is also used by other services, I use the LISTEN/NOTIFY functionality (https://www.postgresql.org/docs/9.1/sql-listen.html) to be notified about changes from PostgeSQL. For this I use the driver com.impossibl.postgres.jdbc.PGDriver
instead of the default driver and the following code to make Spring listen for changes to the database:
ANSWER
Answered 2021-Apr-23 at 06:31Not the same issue, but I had a similar problem. When my database was restarted, Hikari couldn't close the active listener connection, and the whole notification stopped working.
I found a possible solution for this. The reason why Hikari can't close the connection when it's dead because you are unwrapping the connection from the proxied Connection here:
QUESTION
I am using Apache Camel on Spring Boot and want a route to listen to PostgreSQL notify calls.
- Camel version: 3.4.4
- Spring Boot version: 2.3.3
I have tried using the PgEvent component from Camel, but have found the documentation quite lacking when you want to use a DataSource object to fill in the database specifics (i.e. url, username, password). I have neither found any examples of working solutions in stackoverflow, nor around the web.
Below are some sources I found helpful:
- How to receive PostgreSQL LISTEN/NOTIFY with Apache Camel?
- https://impossibl.github.io/pgjdbc-ng/docs/current/user-guide/
In the end, the "normal" jdbc:postgresql:/...
url I was using did not work. So I followed the linked SO-answer, suggesting using the pgjdbc-ng driver (my colleague suggested the same). Following the documentation of the second link I found that my Camel route started working. All I needed to do was change the previous DataSource url to jdbc:pgsql:/...
.
Hope this helps other people with similar problems. Wasted all too many hours on this little problem.
...ANSWER
Answered 2020-Nov-13 at 13:22I'm copying my own solution from the question into the answer section, as it may help others find the solution when the question is marked solved. Below is the copy of the final solution:
In the end, the "normal" jdbc:postgresql:/... url I was using did not work. So I followed the linked SO-answer, suggesting using the pgjdbc-ng driver (my colleague suggested the same). Following the documentation of the second link I found that my Camel route started working. All I needed to do was change the previous DataSource url to jdbc:pgsql:/....
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install pgjdbc-ng
You can use pgjdbc-ng like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the pgjdbc-ng component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page