Skip to content

Instantly share code, notes, and snippets.

@saswata-dutta
Created October 27, 2020 10:39
Show Gist options
  • Save saswata-dutta/debca447bf1b66a7207833f1ea2389a2 to your computer and use it in GitHub Desktop.
Save saswata-dutta/debca447bf1b66a7207833f1ea2389a2 to your computer and use it in GitHub Desktop.
log postgres serverside pid for debugging
private void logServerPID(Connection connection) throws SQLException {
if (connection.isWrapperFor(PGConnection.class)) {
// WARNING this PGConnection will have some mem leak, but cant close it, so only use it for debugging
PGConnection pgConnection = connection.unwrap(PGConnection.class);
log.info("Server PID {}", pgConnection.getBackendPID());
} else {
log.warn("Connection instance is not of pg instance type");
}
}
@Transactional(rollbackOn = Exception.class)
public <T> void run() {
EntityManager entityManager = entityManagerProvider.get();
Session session = entityManager.unwrap(Session.class);
session.doWork(this::logServerPID);
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment