Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I configure HikariCP for postgresql?

I'm trying to use HikariCP in postgresql and I can't find anywhere the configuration for postgresql.

Please point me to any example for postgresql with HikariCP or any configurations tutorial for the same.

I tried to use it like below but it didn't work and then I realized it was meant for MySQL

public static DataSource getDataSource()

    {

            if(datasource == null)

            {

                    HikariConfig config = new HikariConfig();


            config.setJdbcUrl("jdbc:mysql://localhost/test");

            config.setUsername("root");

            config.setPassword("password");



            config.setMaximumPoolSize(10);

            config.setAutoCommit(false);

            config.addDataSourceProperty("cachePrepStmts", "true");

            config.addDataSourceProperty("prepStmtCacheSize", "250");
            config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");



            datasource = new HikariDataSource(config);

            }

           return datasource;

    }
like image 912
MbaiMburu Avatar asked May 07 '18 11:05

MbaiMburu


People also ask

How do I configure HikariCP?

Configuring Hikari With Spring Boot 1. x uses the Tomcat JDBC Connection Pool by default. As soon as we include spring-boot-starter-data-jpa into our pom. xml, we'll transitively include a dependency to the Tomcat JDBC implementation. During runtime, Spring Boot will then create a Tomcat DataSource for us to use.

What is HikariCP connection pool?

Summary. "HikariCP is solid high-performance JDBC connection pool. A connection pool is a cache of database connections maintained so that the connections can be reused when future requests to the database are required. Connection pools may significantly reduce the overall resource usage." - You can find out more here.

How do I check Hikari connection pool?

You can open MYSQL console and query by typing this query. as an example, I have added 10 connections for the pool. the username of the connection is mafei_connection_test . then you can see the all connection that the MySQL server created and currently opening.

What is Hikari leak detection threshold?

From Hikari documentation: "This property controls the amount of time that a connection can be out of the pool before a message is logged indicating a possible connection leak. A value of 0 means leak detection is disabled. Lowest acceptable value for enabling leak detection is 2000 (2 seconds).


Video Answer


1 Answers

You have example in HikariCP configuration wiki page

 Properties props = new Properties();

props.setProperty("dataSourceClassName", "org.postgresql.ds.PGSimpleDataSource");
props.setProperty("dataSource.user", "test");
props.setProperty("dataSource.password", "test");
props.setProperty("dataSource.databaseName", "mydb");
props.put("dataSource.logWriter", new PrintWriter(System.out));

HikariConfig config = new HikariConfig(props);
HikariDataSource ds = new HikariDataSource(config);
like image 150
user7294900 Avatar answered Oct 16 '22 06:10

user7294900