DB2 log (2) use C Language extension to implement DB2 log management and master-slave Synchronization

Source: Internet
Author: User
Tags db2 installation
Fortunately, DB2 provides the related USEREXIT Program (also known as the user exit Program), which allows us to manage log files and has the possibility of extended functions. At this point, DB2 is obviously better than Orac.

Fortunately, DB2 provides the related USEREXIT Program (also known as the user exit Program), which allows us to manage log files and has the possibility of extended functions. At this point, DB2 is obviously better than Orac.

Fortunately, DB2 provides the related USEREXIT Program (also known as the user exit program) to enable us to manage log files and extend the function. DB2 is obviously more open than Oracle at this point.


Implementation
1. First open the USEREXIT interface to allow the database to support the USEREXIT program.
-- View the current status (in Windows)
Db2 get db cfg for XCLDB2 | find/I "userexit"
-- Enable userexit
Db2 update db cfg for XCLDB2 using userexit on
-- View the current status (in Windows)
Db2 get db cfg for XCLDB2 | find/I "userexit"

2. Go to the DB2 installation directory and find the example program.
In Unix: sqllib/samples/c
Windows: C: \ Program Files \ IBM \ SQLLIB \ samples \ c

Example file:
Db2uext2. cadsm-Support for Tivoli Storage Manager, also known as ADSM
Db2uext2. cdisk-disk support
Db2uext2. ctape-support for local tapes, only available for UNIX systems
Db2uext2. cxbsa-Support for XBSA Draft 0.8 clients
Each of these sample programs only needs to be slightly modified (such as buffer_size, audit_log_activation, audit_log_path, error_log_activation, and error_log_path)
In addition to the above, you can also use db2uext2. ctsm to implement it. It is a new alternative version.

3. Take Windows as an example to demonstrate how to compile the extension.
3.1 create a console application project with empty properties in Visual Studio. Note that the project name is "Db2uext2 ",
The project directory is "c: \ DB2C"
3.2 copy Db2uext2. cdisk to the C: \ DB2C \ db2uext2 directory and rename it Db2uext2. c.
Then import the file in the Visual Studio project.
After the import is successful, open the file. Find and replace "c: \ mylogs \" with the desired directory, for example, "c :\\ xcllogs \\"

In fact, these parameters are mainly changed. The specific meaning is detailed in the C program code comment:
# Define ARCHIVE_PATH "c :\\ xcllogs \\"
# Define RETRIEVE_PATH "c :\\ xcllogs \\"
# Define AUDIT_ACTIVE 1/* enable audit trail logging */
# Define ERROR_ACTIVE 1/* enable error trail logging */
# Define AUDIT_ERROR_PATH "c :\\ xcllogs \"/* path must end with a slash */
# Define AUDIT_ERROR_ATTR "a"/* append to text file */
# Define BUFFER_SIZE 32/* # of 4 K pages for output buffer */

3.3put the compiled db2uext2.exe file in the directory that can be found by the DB2 administrative program.
Directory for storing the compiled db2uext2.exe file:
Windows:
C: \ Program Files \ IBM \ SQLLIB \ BIN
In Unix:
/Sqllib/adm
3.4 test whether the extension takes effect
3.4.1 manually archiving a log under DB2 CLP

Db2 archive log for db XCLDB2

3.4.2 The newly generated logs should be available in the "C: \ xcllogs \ XCLDB2 \ NODE0000" directory.
C: \> tree C: \ xcllogs
List of WINXP folder paths
The serial number of the volume is 88F1-6579.
C: \ XCLLOGS
─ ── XCLDB2
─ ── NODE0000
C: \> dir C: \ xcllogs \ XCLDB2 \ NODE0000

The above example is in Windows. In Unix, you must note that you must first mkdir the Directory and authorize (such as 777 ),
And chown-R directory to DB2 users.

Extended:
The above is just a simple example, But if you extend this example, you can even use log file synchronization.
Or asynchronously replicated to a different machine or remote storage to achieve database disaster tolerance.
To put it simply, the implementation of a master-slave Database Synchronization Method is as follows:
1. First, on the backup database server, use the backup of the master database to restore a complete DB2 database.
The backup server hardware may be inconsistent, that is, when the file system is divided differently, you need to use redirection recovery to generate a backup database.
2. Set the active log directory of the backup server as the master database server with read and write permissions.
3. refer to the example above to implement an extension. It is used to upload logs to the active log directory of the backup server.
4. Get a scheduled job on the backup server and roll forward regularly "db2 rollforward to end of logs"
Haha, so that the two sides will be synchronized.
This extension can also be added with the automatic regular log sorting function. You can also use Db2uext2. ctape to scale the tape library.
In short, it's time to look at personal ideas.

,

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.