Go database/sql package SQL. Open is not a long connection

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Sql. Open does not create a connection, it creates only one db instance, and it creates a go to manage a connection pool for that DB instance (it is a long connection, but it is not created at open). The call to begin () takes a connection, rolls back, or returns when it is submitted. If EXEC () executes directly when you use it, a connection is taken out of the connection pool each time, and returned when exec finishes execution. The size of the connection pool can be adjusted by parameters.

The Golang SQL package has been processed concurrently and has maintained a pool of connections through channel, so there is no need to lock-share in go.

about each SQL. Open, I think it should be an inappropriate approach, which will lead to the connection is not reused, and generate too much short time to close the connection, to the database caused unnecessary pressure.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.