Friday, November 21, 2014

Database Lock File - .lk file


Database Lock file is text file which will create when database having one or more connection. This file will be existing in the database directory where .db file reside.
When DB is having single user mode connection it will not allow more than one user to connect at a time. It will throw error if you connect using “mpro”, or if it already user connect via “pro” command.
mpro /path/to/dbase/dbname
            ** The database <file-name> is in use in single-user mode. (263)

When DB is having multiuser open connection it will allow you to connect to DB using “pro” command. You can able to connect DB only using “mpro” command.
pro /path/to/dbase/dbname
            ** The database <file-name> is in use in multi-user mode. (276)

It is very curious now what is the containing element in the small text file which controlling the Database connections. Let me clear you on this
           1.      The mode of DB started (single or multi)
           2.      Pid of the process which started DB.
           3.      Hostname of the process that started DB.
When the process asks DB to start progress will check the .lk file in the .db file location and if .lk file is not exist it will create one and enters the .lk file necessary entry and starts the database.
If .lk file is already exist and if it valid it will throw error either 276 or 263 according to the mode of connection.
Validation is as below
                 a.       It will check the hostname which is present in .lk file and the process which is connected if both matches then it valid. If it does not matches directly it threw error.
                 b.      It then check for pid which is active or not, if it is active then .lk is valid, if not you can remove .lk file and start DB.
                 c.       If .lk file is valid we cannot start the DB as we get appropriate error in the console.

.lk file is crucial file which having the connection control details it should not deleted ascommon file. Deleting the .lk file may lead to database to be corrupted.

In some situation like abnormal shutdown/unclean shutdown which will unable to remove the entry of .lk file we can remove it only if no progress process is not running on the server but the risky factor should be taken. 

2 comments:

  1. I believe the lock file appears when the database is made active, not when it is connected to. Observe starting a database for multiple users - though these is no connections, the lk file still appears. It is one of many ways to determine if the database engine is running or not.

    ReplyDelete
    Replies
    1. Scott, Yes .lk will be appear when we start DB using proserve, aswell it will be created when u connected to DB using pro , .lk file will be containing the info about your db engine status. (whether it is multi user mode or single user mode.)

      Delete