Connect
Establishing a JDBC connection to PostgreSQL: URL forms, the non-default properties worth turning on in production, the timeouts that bound each phase of the handshake and the lifetime of an established connection, production connection pooling with HikariCP / Tomcat JDBC / c3p0, multi-host fail-over and load balancing, Unix-domain sockets.
For TLS configuration and authentication see Security ; for the complete reference of every connection property see Connection properties .
- JDBC URL
JDBC URL forms the driver accepts (
jdbc:postgresql:...), host / port / database defaults, IPv6 bracket syntax, percent-encoding of reserved characters, and passing PostgreSQL startupoptionsthrough the URL. - Recommended properties Connection properties worth turning on in production: batch INSERT rewriting, TCP keep-alive, application_name tagging, skipping the startup version round-trip, and load-balancing across replicas.
- DataSource and JNDI
The JDBC
DataSource/ConnectionPoolDataSourceAPI contracts and the two implementations pgJDBC bundles:PGSimpleDataSourcefor direct use andPGPoolingDataSourcefor the no-app-server case. JNDI binding for both. - Timeouts Driver-side timeouts that bound each phase of a connection (TCP connect, SSL / GSS upgrade, wall-clock login, socket reads, query cancel), the JDBC-spec timeouts layered on top, and where the defaults leave gaps under a pool.
- Connection pooling Running pgJDBC under HikariCP, Tomcat JDBC, or c3p0: pool sizing, validation, the per-connection state that survives checkouts (prepared-statement and metadata caches), and the interaction with server-side poolers like PgBouncer.
- Unix sockets
Connecting to PostgreSQL via a Unix-domain socket by plugging the junixsocket
SocketFactoryinto thesocketFactoryandsocketFactoryArgconnection properties, with the URL form and the typical/tmpvs/var/run/postgresqlpaths. - Connection fail-over
Multi-host JDBC URLs for HA: candidate iteration in URL order,
targetServerTypefor primary or standby selection, theloadBalanceHostsshuffle, and the host-status cache that remembers failed nodes between attempts.