database locked error

Started by Luiz A. Camilo, July 18, 2014, 12:03:23 AM

Previous topic - Next topic

Luiz A. Camilo

Hi there,

I'm running version 1.2.13 on a windows 2008 x64 R2 with a built in database type.
Bellow is a debug session result of the following command : netxmsd.exe -D4 >c:\netxmsd.log
Looking on the log file, there are several events like the one bellow.

[17-Jul-2014 17:50:21.513] SQL query failed (Query = "UPDATE raw_dci_values SET raw_value=?,transformed_value=?,last_poll_time=? WHERE item_id=?"): database is locked
[17-Jul-2014 17:50:21.559] SQL query failed (Query = "INSERT INTO dct_column_names (column_id,column_name) VALUES (?,?)"): database is locked
[17-Jul-2014 17:50:33.915] SQL query failed (Query = "INSERT INTO event_log (event_id,event_code,event_timestamp,event_source,event_severity,event_message,root_event_id,user_tag) VALUES (8896895,29,1405630197,728,0,'Node up',0,'')"): database is locked


I already tried to run a nxdbmgr -f unlock and that returns ok, but the problem persists.

After sometime running, I see that some threads hangs up ... and that's when the mess starts.
Running a nxadm -i and executing show watchdog I can see that both Syncer Thread and Pool Manager gets "Not Responding" after sometime. 

[17-Jul-2014 17:54:04.016] Thread "Syncer Thread" does not respond to watchdog thread


I guess the problem is regarding unlock this database ...
I also noticed a weird behaviour on the netxmsd daemon startup :

netxmsd: Using configuration file "C:\NetXMS\etc\netxmsd.conf"
[17-Jul-2014 17:49:43.823] Listening for client connections on TCP socket 0.0.0.0:4701
[17-Jul-2014 17:49:43.823] Listening for mobile device connections on TCP socket 0.0.0.0:4747
[17-Jul-2014 17:49:48.799] New DB connection opened: handle=0000000004330DC0
[17-Jul-2014 17:49:48.799] New DB connection opened: handle=0000000004330D60
[17-Jul-2014 17:49:48.799] New DB connection opened: handle=0000000002ACB2B0
[17-Jul-2014 17:49:48.799] New DB connection opened: handle=00000000047C5910
[17-Jul-2014 17:49:48.799] New DB connection opened: handle=00000000047C59D0
[17-Jul-2014 17:49:48.799] New DB connection opened: handle=00000000047C5A90
[17-Jul-2014 17:49:48.799] New DB connection opened: handle=00000000047C5B50
[17-Jul-2014 17:49:48.799] New DB connection opened: handle=00000000047C5C10
[17-Jul-2014 17:49:48.799] New DB connection opened: handle=00000000047C5D90
[17-Jul-2014 17:49:48.799] New DB connection opened: handle=00000000047C5E50
[17-Jul-2014 17:49:48.815] New DB connection opened: handle=00000000047C5EB0
[17-Jul-2014 17:49:48.831] New DB connection opened: handle=00000000047C5FD0
[17-Jul-2014 17:49:48.831] New DB connection opened: handle=0000000004CA1C20
[17-Jul-2014 17:49:48.831] New DB connection opened: handle=0000000004CA1DA0
[17-Jul-2014 17:49:48.831] New DB connection opened: handle=0000000004CA1C80
[17-Jul-2014 17:49:48.831] Database Connection Pool exhausted, fallback connection used
[17-Jul-2014 17:49:48.831] Database Connection Pool exhausted, fallback connection used
[17-Jul-2014 17:49:48.831] Database Connection Pool exhausted, fallback connection used
[17-Jul-2014 17:49:48.831] Database Connection Pool exhausted, fallback connection used
[17-Jul-2014 17:49:48.831] Database Connection Pool exhausted, fallback connection used
[17-Jul-2014 17:49:48.831] Database Connection Pool exhausted, fallback connection used
[17-Jul-2014 17:49:48.831] Database Connection Pool exhausted, fallback connection used
[17-Jul-2014 17:49:48.831] Database Connection Pool exhausted, fallback connection used
[17-Jul-2014 17:49:48.831] Database Connection Pool exhausted, fallback connection used
[17-Jul-2014 17:49:48.831] Database Connection Pool exhausted, fallback connection used
[17-Jul-2014 17:49:48.831] Database Connection Pool exhausted, fallback connection used
[17-Jul-2014 17:49:48.831] Database Connection Pool exhausted, fallback connection used
[17-Jul-2014 17:49:48.831] Database Connection Pool exhausted, fallback connection used
[17-Jul-2014 17:49:48.831] Database Connection Pool exhausted, fallback connection used
[17-Jul-2014 17:49:48.831] Database Connection Pool exhausted, fallback connection used
[17-Jul-2014 17:49:48.831] Database Connection Pool exhausted, fallback connection used
[17-Jul-2014 17:49:48.831] Database Connection Pool exhausted, fallback connection used
[17-Jul-2014 17:49:48.831] Database Connection Pool exhausted, fallback connection used
[17-Jul-2014 17:49:48.831] Database Connection Pool exhausted, fallback connection used
[17-Jul-2014 17:49:48.831] Database Connection Pool exhausted, fallback connection used
[17-Jul-2014 17:49:48.831] Database Connection Pool exhausted, fallback connection used
[17-Jul-2014 17:49:48.831] Database Connection Pool exhausted, fallback connection used
[17-Jul-2014 17:49:48.831] Database Connection Pool exhausted, fallback connection used
[17-Jul-2014 17:49:48.831] Database Connection Pool exhausted, fallback connection used
[17-Jul-2014 17:49:48.831] Database Connection Pool exhausted, fallback connection used
[17-Jul-2014 17:49:48.831] Database Connection Pool exhausted, fallback connection used
[17-Jul-2014 17:49:48.831] Database Connection Pool exhausted, fallback connection used
[17-Jul-2014 17:49:48.831] Database Connection Pool exhausted, fallback connection used
[17-Jul-2014 17:49:48.831] Database Connection Pool exhausted, fallback connection used
[17-Jul-2014 17:49:48.831] Database Connection Pool exhausted, fallback connection used
[17-Jul-2014 17:49:48.831] Database Connection Pool exhausted, fallback connection used


I need some help please ...



Victor Kirhenshtein

Hi!

I would suggest a reboot for whole system if possible. Error message is from DB itself, not from NetXMS - so it's not that lock.

Best regards,
Victor

Luiz A. Camilo

Hi Victor,
Thanks for the always fast answer.

I'm using no 3rd party DB engine, on this install I selected builtin database ...
On the NetXms folder /database there's a file called netxms_db.
I already rebooted this server several times ..

Is there any way to read this file ? is it mysql ? maybe edit it.

Thanks !!!

Alex Kirhenshtein

Hello.

Bundled DB engine is SQLite. You can try to export/reimport db into a new file (run in cmd.exe): echo ".dump" | sqlite3 c:\netxms\ database\netxms_db | sqlite3 c:\netxms\ database\netxms_db.new

sqlite3.exe can be downloaded here: http://www.sqlite.org/2014/sqlite-shell-win32-x86-3080500.zip

This should produce a clean copy of the database in file netxms_db.new. Move original netxms_db tor backup and rename netxms_db.new to netxms_db.

I also highly recommend you to migrate to any other database engines, PostgreSQL is common and quite good choice - it's powerful, free and require just a little of the system resources in default configuration.

nxdbmgr can be used for migration (so you don't have to dump data and reimport it manually).

Luiz A. Camilo

Hi Alex,

Thank you very much, that helped me a lot and it seems that the problem is solved, but in a different way.
I could not run the command you gave me, it returns me incomplete or args missing. So I started exploring SQLite commands and I found an SQLite Explorer on this link : http://sourceforge.net/projects/sqlitebrowser/
The main problem I believe that's the Event Monitor rows bellow :

23.07.2014 10:40:22 W2K8-NETXMS Critical SYS_DB_QUERY_FAILED Database query failed (Query: INSERT INTO event_log (event_id,event_code,event_timestamp,event_source,event_severity,event_message,root_event_id,user_tag) VALUES (8918460,100002,1406122787,1425,1,'Memory Utilization is too high',0,''); Error: database is locked)
23.07.2014 10:40:31 W2K8-NETXMS Critical SYS_DB_QUERY_FAILED Database query failed (Query: UPDATE raw_dci_values SET raw_value=?,transformed_value=?,last_poll_time=? WHERE item_id=?; Error: database is locked)
23.07.2014 10:40:31 W2K8-NETXMS Critical SYS_DB_QUERY_FAILED Database query failed (Query: INSERT INTO dct_column_names (column_id,column_name) VALUES (?,?); Error: database is locked)


So I decided to clean the event_log database running the following command : "delete from event_log" and after that, it's working back to normal. So far no "database locked errors."

I also found this link very useful, where they talk about the only way to recover from a database lock events, is copying the database to another location. Which means that the lock is directly related to a process accessing the disk database file.
Maybe the problem was related to the ammount of data stored on a single table as explained on the link bellow.
http://sqlite.org/limits.html

I hope all this information that will remain on this forum can help someone else in the future, that's why I tried to put as much details as possible.

Also thank you very much again Alex. I'll work now in migrating this DB to PostgreSQL. I'll apreciate if you can share more information on how to migrate the database. I tried to run "nxdbmgr migrate c:\file" and it starts and crashes when the new file gets around 9Mb...

Alex Kirhenshtein

To use "nxdbmgr migrate", you need to do a few preparation steps:

1) Create a copy of existing netxmsd.conf, I'll name it "netxmsd_old.conf" in this example
2) Create new database
3) Init with initial schema: nxdbmgr init /opt/netxms/share/netxms/sql/dbinit_pgsql.sql
Please note, that there are different files for different database types, in this example - "dbinit_pgsql.sql" is for PostgreSQL.
4) Adjust "netxmsd.conf" - change DBDriver, DBName, etc. to match new database
5) (optional) run "nxdbmgr check" to verify connectivity to new database
6) run "nxdbmgr migrate netxmsd_old.conf". This will load data from old database (using credentials in netxmsd_old.conf) and migrate it into new one (as configured in netxmsd.conf)

Luiz A. Camilo

Awesome Alex.
Thank you very much. I'll migrate and post back. But seems easy and I guess there won't be problems.

Also Just an update, The problem is solved following the steps from this post. http://techblog.dorogin.com/2011/05/sqliteexception-database-disk-image-is.html
After re-creating my database that was 3.5GB, now it has 1.0Gb and pretty fast.
I'll proceed with the database migration.

Thanks again.