CN102902779A - Connection method and connection device of multiple databases - Google Patents
Connection method and connection device of multiple databases Download PDFInfo
- Publication number
- CN102902779A CN102902779A CN2012103713891A CN201210371389A CN102902779A CN 102902779 A CN102902779 A CN 102902779A CN 2012103713891 A CN2012103713891 A CN 2012103713891A CN 201210371389 A CN201210371389 A CN 201210371389A CN 102902779 A CN102902779 A CN 102902779A
- Authority
- CN
- China
- Prior art keywords
- database
- connection
- connect
- health parameters
- primary
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Granted
Links
Images
Landscapes
- Mobile Radio Communication Systems (AREA)
- Telephonic Communication Services (AREA)
Abstract
The invention discloses a connection method and a connection device of multiple databases. The connection method includes loading all database connection pools in the configuration in the starting process, setting a connection pool that a main database corresponds to in all the database connection pools to be a currently used connection pool, setting the connection pools that surplus standby databases correspond to be standby connection pools, judging whether the main database can be connected or not when receiving a database resource request transmitted by a caller, conducting connection on yes judgment, conducting database switching and selecting one database in the standby databases for connection on no judgment, and enabling the caller to obtain the connection. The method and the device can automatically select other effective databases to serve as a connection provider for the database when one database in a database group cannot response normally, improve application system reliability, improve system stability and avoid database outage.
Description
Technical field
The present invention relates to the Connectivity Technical of Database field, particularly relate to a kind of method of attachment and device of multiple database.
Background technology
In the situation that use multiple database as data set provider, general data storehouse connection pool can only use a database as connecting the supplier simultaneously, and is unusual if current database occurs, and need to stop to use until database recovery.In the existing solution, the scheme that solves the problems referred to above by primary database and standby database are set is arranged, the Main Function of standby database is for data backup, although can guarantee not losing of data, but when primary database goes wrong, but be difficult to the assurance system and continue normal operation.If system will recover access in a short time, need the manual modification database configuration, call standby database, and restart service.After primary database recovery is normal, also to again revise configuration restore to the access of primary database, whole process can cause the unstable even inactive of whole system.
Summary of the invention
The technical problem to be solved in the present invention provides a kind of method of attachment and device of multiple database, in order to solve the unstable even inactive problem of system that causes when database goes wrong in the prior art.
For solving the problems of the technologies described above, on the one hand, the invention provides a kind of method of attachment of multiple database, comprising:
During startup, load all database connection pool in the configuration, and in all database connection pools, it is current use connection pool that connection pool corresponding to primary database is set, it is connection pool for subsequent use that connection pool corresponding to remaining standby database is set;
When receiving the database resource request of caller initiation, judge whether primary database can connect, and if so, then connects, if not, then carry out database and switch, in standby database, select a database to connect; Make caller obtain to connect.
Further, during startup, also the log-on data Status Monitor is used for the health parameters of primary database is monitored, and obtains the health parameters of primary database.
Further, judge that whether database can connect, and specifically may further comprise the steps:
Judge at first whether primary database stops, if so, judge that then primary database can't connect; If not, it is full that next judges whether current use connection pool corresponding to primary database has connected, and if so, judges that then primary database can't connect; If not, judge at last whether the health parameters of primary database reaches predefined health parameters threshold value, if so, judge that then primary database can't connect; If not, judge that then primary database can connect.
Further, after caller is initiated the database resource request, count entering the thread that obtains connection, when counter reaches predefined count threshold, when caller does not also obtain to connect, judge that primary database can't connect.
Further, after caller obtains to connect, also comprise:
The data mode monitor is monitored the health parameters of the database of current connection, obtain the health parameters in current connection data storehouse, and judge whether to reach predefined health parameters threshold value, if, then revise the database positioning of current connection for connecting, carry out database and switch; If not, then keep connecting.
Further, the data mode monitor is monitored the health parameters of the database of current connection, specifically comprises:
Whether the database of judging current connection is carried out read-write operation and is occurred unusually, if so, then the health parameters of the database of current connection is subtracted 1; If not, then the health parameters of the database of current connection is added 2;
The bad connection appears in the database of current connection, then the health parameters of the database of current connection added 4.
On the other hand, the present invention also provides a kind of coupling arrangement of multiple database, comprising:
Start configuration module, when being used for starting, load all database connection pool in the configuration, and, in all database connection pools, it is current use connection pool that connection pool corresponding to primary database is set, and it is connection pool for subsequent use that connection pool corresponding to remaining standby database is set;
Connect handover module, when being used for receiving the database resource request of caller initiation, judge whether primary database can connect, and if so, then connects, if not, then carry out database and switch, in standby database, select a database to connect; Make caller obtain to connect.
Further, described device also comprises:
The data mode monitor is monitored the health parameters of primary database after being used for starting, and obtains the health parameters of primary database;
Described connection handover module judges at first whether primary database stops, and if so, judges that then primary database can't connect; If not, it is full that next judges whether current use connection pool corresponding to primary database has connected, and if so, judges that then primary database can't connect; If not, judge at last whether the health parameters of primary database reaches predefined health parameters threshold value, if so, judge that then primary database can't connect; If not, judge that then primary database can connect;
Described connection handover module is counted entering the thread that obtains connection after caller is initiated the database resource request, when counter reaches predefined count threshold, when caller does not also obtain to connect, judges that primary database can't connect.
Further, described data mode monitor also is used for the health parameters of the database of current connection is monitored, obtain the health parameters in current connection data storehouse, and judge whether to reach predefined health parameters threshold value, if, then revise the database positioning of current connection for connecting, carry out database and switch; If not, then keep connecting.
Further, described data mode monitor judges that the database of current connection carries out read-write operation and whether occur unusually, if so, then the health parameters of the database of current connection is subtracted 1; If not, then the health parameters of the database of current connection is added 2; The bad connection appears in the database of current connection, then the health parameters of the database of current connection added 4.
Beneficial effect of the present invention is as follows:
The present invention can realize automatically selecting other efficient database as the connection supplier of database when certain database in the database cluster can't normal response, to improve the reliability of application system, has improved Systems balanth, has avoided database to stop using.
Description of drawings
Fig. 1 is the process flow diagram of a kind of method of attachment of multiple database in the embodiment of the invention;
Fig. 2 is the structural representation of a kind of coupling arrangement of multiple database in the embodiment of the invention.
Embodiment
Below in conjunction with accompanying drawing and embodiment, the present invention is further elaborated.Should be appreciated that specific embodiment described herein only in order to explain the present invention, does not limit the present invention.
As shown in Figure 1, the embodiment of the invention relates to a kind of method of attachment of multiple database, comprising:
Step S101 when system starts, loads all database connection pool in the configuration, that is, all databases in the system are all loaded into when starting.In addition, also need to be in all database connection pools, it is current use connection pool that connection pool corresponding to primary database is set, it is connection pool for subsequent use that connection pool corresponding to remaining standby database is set.
In this step, when starting in system, also the log-on data Status Monitor is used for the health parameters of primary database is monitored, and obtains the health parameters of primary database.
When step S102, system receive the database resource request of caller initiation, judge whether primary database can connect, and if so, then connects, if not, then carry out database and switch, in standby database, select a database to connect; Caller obtains to connect.
In this step, judge that whether database can connect, and specifically may further comprise the steps:
Judge at first whether primary database stops, if so, judge that then primary database can't connect; If not, it is full that next judges whether current use connection pool corresponding to primary database has connected, and if so, judges that then primary database can't connect; If not, judge at last whether the health parameters of primary database reaches predefined health parameters threshold value, if so, judge that then primary database can't connect; If not, judge that then primary database can connect.
In standby database, select a database to connect, can in standby database, select at random a database to connect, also can or choose order and select according to predefined priority.
In addition, after caller is initiated the database resource request, count entering the thread that obtains connection, when counter reaches predefined count threshold, when caller does not still obtain to connect, then directly return null value, represent that primary database can't normally provide connection.The benefit of doing like this is: when having n database, the impact that causes only is 1/n, has reduced because the adverse effect that database failure causes.
When being standby database for the database of current connection, caller can only carry out read-only operation to the database of current connection, if the current operation of carrying out is not read-only operation, then can't connect standby database.
When primary database went wrong, other standby databases can normally provide service, do not affect normal access, raced against time for recovering primary database.When the load of primary database is excessive, can provide inquiry service by other standby databases, can reduce like this load pressure of primary database, when primary database pressure drop, the database of current connection reverts to primary database automatically.
Step S103, after caller obtains to connect, the data mode monitor is monitored the health parameters of the database of current connection, obtain the health parameters in current connection data storehouse, and judge whether to reach predefined health parameters threshold value, if so, then revise the database positioning of current connection for connecting, carry out database and switch; If not, then keep connecting.
The data mode monitor is monitored the health parameters of the database of current connection, specifically comprises:
Whether the database of judging current connection is carried out read-write operation and is occurred unusually, if so, then the health parameters of the database of current connection is subtracted 1; If not, then the health parameters of the database of current connection is added 2.
The bad connection appears in the database of current connection, then the health parameters of the database of current connection added 4; Wherein, the bad connection refers to invalid connection, and caller can't accessing database.
Step S104, the caller release connection.
In this step, after the caller release connection, but judge whether the database positioning of current connection is connection status, if so, then this database is put back in its corresponding connection pool; If not, being connected of destruction database and connection pool then.
In addition, the invention still further relates to a kind of coupling arrangement of realizing the multiple database of said method, it comprises:
Start configuration module 201, when being used for starting, load all database connection pool in the configuration, and, in all database connection pools, it is current use connection pool that connection pool corresponding to primary database is set, and it is connection pool for subsequent use that connection pool corresponding to remaining standby database is set;
Connect handover module 202, when being used for receiving the database resource request of caller initiation, judge whether primary database can connect, if so, then connect, if not, then carry out database and switch, in standby database, select a database to connect; Make caller obtain to connect.
This device also comprises:
Connect handover module 202 and judge at first whether primary database stops, if so, judge that then primary database can't connect; If not, it is full that next judges whether current use connection pool corresponding to primary database has connected, and if so, judges that then primary database can't connect; If not, judge at last whether the health parameters of primary database reaches predefined health parameters threshold value, if so, judge that then primary database can't connect; If not, judge that then primary database can connect;
Connect handover module 202 after caller is initiated the database resource request, count entering the thread that obtains connection, when counter reaches predefined count threshold, when caller does not also obtain to connect, judge that primary database can't connect.
The present invention can realize automatically selecting other efficient database as the connection supplier of database when certain database in the database cluster can't normal response, to improve the reliability of application system, has improved Systems balanth, has avoided stopping using.
Although be the example purpose, the preferred embodiments of the present invention are disclosed, it also is possible those skilled in the art will recognize various improvement, increase and replacement, therefore, scope of the present invention should be not limited to above-described embodiment.
Claims (10)
1. the method for attachment of a multiple database is characterized in that, comprising:
During startup, load all database connection pool in the configuration, and in all database connection pools, it is current use connection pool that connection pool corresponding to primary database is set, it is connection pool for subsequent use that connection pool corresponding to remaining standby database is set;
When receiving the database resource request of caller initiation, judge whether primary database can connect, and if so, then connects, if not, then carry out database and switch, in standby database, select a database to connect; Make caller obtain to connect.
2. the method for attachment of multiple database as claimed in claim 1 is characterized in that, during startup, also the log-on data Status Monitor is used for the health parameters of primary database is monitored, and obtains the health parameters of primary database.
3. the method for attachment of multiple database as claimed in claim 2 is characterized in that, judges that whether database can connect, and specifically may further comprise the steps:
Judge at first whether primary database stops, if so, judge that then primary database can't connect; If not, it is full that next judges whether current use connection pool corresponding to primary database has connected, and if so, judges that then primary database can't connect; If not, judge at last whether the health parameters of primary database reaches predefined health parameters threshold value, if so, judge that then primary database can't connect; If not, judge that then primary database can connect.
4. such as the method for attachment of claim 1 or 3 described multiple databases, it is characterized in that, after caller is initiated the database resource request, count entering the thread that obtains connection, when counter reaches predefined count threshold, when caller does not also obtain to connect, judge that primary database can't connect.
5. the method for attachment of multiple database as claimed in claim 3 is characterized in that, after caller obtains to connect, also comprises:
The data mode monitor is monitored the health parameters of the database of current connection, obtain the health parameters in current connection data storehouse, and judge whether to reach predefined health parameters threshold value, if, then revise the database positioning of current connection for connecting, carry out database and switch; If not, then keep connecting.
6. the method for attachment of multiple database as claimed in claim 5 is characterized in that, the data mode monitor is monitored the health parameters of the database of current connection, specifically comprises:
Whether the database of judging current connection is carried out read-write operation and is occurred unusually, if so, then the health parameters of the database of current connection is subtracted 1; If not, then the health parameters of the database of current connection is added 2;
The bad connection appears in the database of current connection, then the health parameters of the database of current connection added 4.
7. the coupling arrangement of a multiple database is characterized in that, comprising:
Start configuration module, when being used for starting, load all database connection pool in the configuration, and, in all database connection pools, it is current use connection pool that connection pool corresponding to primary database is set, and it is connection pool for subsequent use that connection pool corresponding to remaining standby database is set;
Connect handover module, when being used for receiving the database resource request of caller initiation, judge whether primary database can connect, and if so, then connects, if not, then carry out database and switch, in standby database, select a database to connect; Make caller obtain to connect.
8. the coupling arrangement of multiple database as claimed in claim 7 is characterized in that, described device also comprises:
The data mode monitor is monitored the health parameters of primary database after being used for starting, and obtains the health parameters of primary database;
Described connection handover module judges at first whether primary database stops, and if so, judges that then primary database can't connect; If not, it is full that next judges whether current use connection pool corresponding to primary database has connected, and if so, judges that then primary database can't connect; If not, judge at last whether the health parameters of primary database reaches predefined health parameters threshold value, if so, judge that then primary database can't connect; If not, judge that then primary database can connect;
Described connection handover module is counted entering the thread that obtains connection after caller is initiated the database resource request, when counter reaches predefined count threshold, when caller does not also obtain to connect, judges that primary database can't connect.
9. the coupling arrangement of multiple database as claimed in claim 8, it is characterized in that, described data mode monitor also is used for the health parameters of the database of current connection is monitored, obtain the health parameters in current connection data storehouse, and judge whether to reach predefined health parameters threshold value, if so, then revise the database positioning of current connection for connecting, carry out database and switch; If not, then keep connecting.
10. the coupling arrangement of multiple database as claimed in claim 9 is characterized in that,
Described data mode monitor judges that the database of current connection carries out read-write operation and whether occur unusually, if so, then the health parameters of the database of current connection is subtracted 1; If not, then the health parameters of the database of current connection is added 2; The bad connection appears in the database of current connection, then the health parameters of the database of current connection added 4.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201210371389.1A CN102902779B (en) | 2012-09-28 | 2012-09-28 | A kind of method of attachment of multiple database and device |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201210371389.1A CN102902779B (en) | 2012-09-28 | 2012-09-28 | A kind of method of attachment of multiple database and device |
Publications (2)
Publication Number | Publication Date |
---|---|
CN102902779A true CN102902779A (en) | 2013-01-30 |
CN102902779B CN102902779B (en) | 2016-03-02 |
Family
ID=47575011
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201210371389.1A Active CN102902779B (en) | 2012-09-28 | 2012-09-28 | A kind of method of attachment of multiple database and device |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN102902779B (en) |
Cited By (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN104462200A (en) * | 2014-10-31 | 2015-03-25 | 北京思特奇信息技术股份有限公司 | Method and system for controlling switching between systems through third-party database |
CN105138693A (en) * | 2015-09-18 | 2015-12-09 | 联动优势科技有限公司 | Method and device for having access to databases |
CN107509192A (en) * | 2016-06-14 | 2017-12-22 | 中国移动通信集团公司 | A kind of authentication method and system |
CN109800261A (en) * | 2018-12-15 | 2019-05-24 | 平安科技(深圳)有限公司 | Dynamic control method, device and the relevant device of double data library connection pool |
CN113849508A (en) * | 2021-09-22 | 2021-12-28 | 广东电网有限责任公司 | Data storage method, device, equipment and medium |
Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN1848989A (en) * | 2005-04-04 | 2006-10-18 | 中兴通讯股份有限公司 | System for automatic switching database in imputation position register and method thereof |
CN101095109A (en) * | 2004-12-31 | 2007-12-26 | Bea系统公司 | Multipool manager |
-
2012
- 2012-09-28 CN CN201210371389.1A patent/CN102902779B/en active Active
Patent Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101095109A (en) * | 2004-12-31 | 2007-12-26 | Bea系统公司 | Multipool manager |
CN1848989A (en) * | 2005-04-04 | 2006-10-18 | 中兴通讯股份有限公司 | System for automatic switching database in imputation position register and method thereof |
Cited By (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN104462200A (en) * | 2014-10-31 | 2015-03-25 | 北京思特奇信息技术股份有限公司 | Method and system for controlling switching between systems through third-party database |
CN105138693A (en) * | 2015-09-18 | 2015-12-09 | 联动优势科技有限公司 | Method and device for having access to databases |
CN107509192A (en) * | 2016-06-14 | 2017-12-22 | 中国移动通信集团公司 | A kind of authentication method and system |
CN107509192B (en) * | 2016-06-14 | 2021-03-16 | 中移动信息技术有限公司 | Authentication method and system |
CN109800261A (en) * | 2018-12-15 | 2019-05-24 | 平安科技(深圳)有限公司 | Dynamic control method, device and the relevant device of double data library connection pool |
CN109800261B (en) * | 2018-12-15 | 2024-04-05 | 平安科技(深圳)有限公司 | Dynamic control method and device for double-database connection pool and related equipment |
CN113849508A (en) * | 2021-09-22 | 2021-12-28 | 广东电网有限责任公司 | Data storage method, device, equipment and medium |
Also Published As
Publication number | Publication date |
---|---|
CN102902779B (en) | 2016-03-02 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN102902779A (en) | Connection method and connection device of multiple databases | |
US20080141283A1 (en) | Application Controlling Apparatus And Storage Medium Which Stores Software For The Apparatus | |
CN103019889A (en) | Distributed file system and failure processing method thereof | |
CN111209110B (en) | Task scheduling management method, system and storage medium for realizing load balancing | |
CN101996106A (en) | Method for monitoring software running state | |
CN100492305C (en) | Fast restoration method of computer system and apparatus | |
CN101977124A (en) | Service clustering method and system based on ZooKeeper technology | |
CN102243594A (en) | Method for safely and remotely upgrading embedded Linux system software | |
CN107025152B (en) | Data synchronization method of double-redundancy hot backup equipment based on task level | |
CN101883003A (en) | Mandatory running method of computer operating system | |
CN102195796A (en) | Method and equipment for updating software version of distributed dual master control equipment | |
CN101917263A (en) | Multi-machine hot standby method and system | |
CN103713925A (en) | Method and device for avoiding service interruption of storage array in upgrading process | |
CN103092724A (en) | System self-recovery method for embedded electric power terminal | |
CN101217401B (en) | Base station controller upgrade, backup method and device | |
WO2014089990A1 (en) | High availability method and system for improving the utility of physical servers in cloud computing resource pool | |
CN105847285A (en) | Push service configuration method and device | |
CN103246579A (en) | Substrate management controller system | |
CN101110609A (en) | Method and system for implementing communication of main and standby module | |
CN101686261A (en) | RAC-based redundant server system | |
CN111221683A (en) | Double-flash hot backup method, system, terminal and storage medium for data center switch | |
CN101237355B (en) | Service monitoring method, and network monitoring device | |
CN103840956A (en) | Backup method for gateway device of Internet of Things | |
CN101834748A (en) | Method and device for main and standby competition | |
CN103780433A (en) | Self-healing type virtual resource configuration management data architecture |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
C14 | Grant of patent or utility model | ||
GR01 | Patent grant |