Retrieve a native connection from hikari-cp connection pool - postgresql

Can I retrieve a native connection from a hikari-cp connection pool or can I cast the proxy connection that it lends to a postgres connection?
I need to get a database connection from there and pass it to CopyManager. If yes, how?

Use the unwrap() API.
PgConnection pc = conn.unwrap(PgConnection.class);
EDIT: Be careful, do not call close() on the unwrapped Connection instance, because HikariCP will not be able to track it properly.

Related

What exactly does a connection pool for databases like PostgreSQL do?

I know the general idea that a connection pool is a pool of reusable connections that speeds up traffic to the database because it can reuse connections instead of constantly creating new ones.
But this is a very high level explanation. It doesn't explain what is meant by a connection and why the connection pool works, since even with a connection pool such as for example client -> PgBouncer -> PostgreSQL, while the client does not have to create a connection to the databasee, it still has to connect to create a connection to the proxy.
So what is the connection created from (e.g.) client -> PgBouncer and why is creating this connection faster than creating the connection PgBouncer -> PostgreSQL?
There are two uses of a connection pool:
it prevents opening and closing database connections all the time
There is certainly a certain overhead with establishing a TCP connection to pgBouncer, but that is way cheaper than establishing a database connection. When you start a database connection, additional work is done:
a server process is started, which is way more expensive than a TCP connection
PostgreSQL loads cached metadata tables
it puts a limit on the number of client connections, thereby preventing database overload
The advantage over limiting max_connections is that connections in excess of the limit won't receive an error, but will be queued waiting for a connection to become free.

How pgbouncer care about session parameters in transaction pooling mode

i connect to Postgresql via JDBC through pgbouncer with transaction pooling mode enabled. As far as I know in this mode pgbouncer can share same connection for several client without breaking session. So several clients may work within a single session sequentially, one by another. The question is does pgbouncer care about reseting session parameters when it detach one client from a connection and attach another client to this connection?
In particular, my app get connection and then issues something like this:
executeQuery(connection,"select set_config('myapp.user','fonar101',false)");
..../*other actions*/
commit(connection);
After commit pgbouncer can detach my app from connection and get it back to its pool, right? So,
if I issue another statements after commit they will probably be
executed within another session with incorrect values of session
parameters
pgbouncer can attach another client to that connection
and that client will proceed with again incorrect session settings
How does pgbouncer care about this things?
I'd say the opposite:
https://pgbouncer.github.io/config.html
transaction
Server is released back to pool after transaction finishes.
Which means that when you SET SESSION (default for SET), without specifying SET LOCAL, you change settings for all transactions that share the session in the pool...
According pgbouncer docs it doesnt support SET/RESET and ON COMMIT DROP for temp tables in transaction pooling mode.

How to disable persistent connection between php and mongodb?

When I use driver MongoDB\Driver in PHP7, php always creates lots of connections with mongo. And I can't close the connection by myself, because MongoDB\Driver hasn't a close() method.
How to disable persistent connection? Or how to configure it?

Is it Possible to Meteor.call({}) using DDP connection in Meteor?

i want to access a data using remote connection using DDP connections,
i can subscribe data which is publish by remote connection but, i need to access more data from remote connection using Meteor.call()
Never used this one but you may check this out
http://docs.meteor.com/#/full/ddp_connect

What will HttpClient do if connection in pool closed

HttpClient has special connection manager(ThreadSafeClientConnManager or PoolingClientConnectionManager or MultiThreadedHttpConnectionManager) which can support multi thread. My understanding is these connection manager will create connection pool and try to reuse existing connection in subsequence request.
My question is, will the existing connection be dropped, like by network device?
and if the connection is dropped, what HttpClient will do, if it will affect next request?
I meet lots of similar issue in these days after deploy our application to Azure, as Azure always close my connection after a few time. I want to make sure if HttpClient can handle this failover correctly.