GORM provides the method DB which returns a generic database interface *sql.DB from the current *gorm.DB

1. // Get generic database object sql.DB to use its functions
2. sqlDB, err := db.DB()

4. // Ping
5. sqlDB.Ping()

7. // Close
8. sqlDB.Close()

10. // Returns database statistics
11. sqlDB.Stats()

NOTE If the underlying database connection is not a *sql.DB, like in a transaction, it will returns error

Connection Pool

1. // Get generic database object sql.DB to use its functions
2. sqlDB, err := db.DB()

4. // SetMaxIdleConns sets the maximum number of connections in the idle connection pool.
5. sqlDB.SetMaxIdleConns(10)

7. // SetMaxOpenConns sets the maximum number of open connections to the database.
8. sqlDB.SetMaxOpenConns(100)

10. // SetConnMaxLifetime sets the maximum amount of time a connection may be reused.
11. sqlDB.SetConnMaxLifetime(time.Hour)