Database and Connections

I am interested to know how databases handle connections that are not explicitly closed by the entity that initiated the connection.

  • Let's say I have a database that can only accept 2 simultaneous connections at a time. I have a piece of code that opens a connection and never closes it. This piece of code works forever, but it uses the connection only once in it, but the connection object never goes beyond the scope, so it does not collect garbage. Let's say I run 2 instances of this code. Does this mean that until the program is completed or the connection time expires (due to inactivity), the database will not be able to accept more connections?

  • In the above scenario, if the connection object is garbage collection, does the connection automatically end or depends on the database driver used, or the connection is not completed at all until I close it explicitly?

  • If I open a connection in a piece of code and I do not close it explicitly, but the program terminates, how does the database restore this connection?

+5
source share
2 answers

The basic protocol for connecting to a database is typically based on TCP / IP. A connection can be completed in one of several ways:

  • The server closes it gracefully and receives confirmation from the client;
  • The client closes gracefully and receives confirmation from the server;
  • . , ;
  • .

(3) TCP- , , . , ( , ).

, , , . ( ).

( "" ) , ( UNIX, - ), - , ( ).

:

  • ;
  • , ( -);
  • () .

TCP (, , MySQL UNIX), .

, , , , - - - . hsa . , (, , ). , , .

( , ), .

+4

:

  • , . " " " ". , .

  • . . ( , , TCP-.)

  • , , . TCP .. . , , .

+4

All Articles