This seems fairly simple in hindsight, but I had a difficult time finding an answer to it, so I putting it down here for posterity’s sake.


SET FOREIGN_KEY_CHECKS=0

I put this as the first changeset in a liquibase xml file. This disables the foreign key and constraint checking in mysql. This would work for other db’s as well, but I haven’t looked up their syntax just yet.

This is in the babble category tagged as ,

Add a comment »

We have well over 50 million rows in our obs table. Using the simple “update obs set uuid = uuid() where uuid is null” would bomb out with a “The total number of locks exceeds the lock table size” error.

I ran this for a few hours to get through all rows. (Note that it overwrites any uuids that are currently there)

Copy this into a sql script and run it with “source” in mysql at command line.

drop procedure update_uuids;
delimiter //
create procedure update_uuids() begin
set @max = (select max(obs_id) from obs);
set @x = 1;
repeat
set @y = @x + 100000;
update obs set uuid = uuid() where obs_id >=@x and obs_id <@y; set @x = @y; until @x > @max
end repeat;
end
//
delimiter ;
call update_uuids();

This is in the openmrs category tagged as , , ,

2 comments »

A programmer here at AMPATH (Gilbert Tuwei) had some issues installing mysql. The error message was very unhelpful and the solution was equally puzzling, so I want to put here to for the mighty google to find.

Tuwei was running v5.0.17 of MySQL. Upgrading to version 5.1.31 made the problem disappear.

WARN – InitializationFilter$InitializationCompletion$1.run(823) |2009-10-02 15:24:21,000| Error while trying to update to the latest database version
org.openmrs.util.DatabaseUpdateException: There was an error while updating the database to the latest. file: liquibase-update-to-latest.xml. Error: Migration failed for change set liquibase-update-to-latest.xml::2::upul:
Reason:
java.sql.SQLException: Can’t create/write to file ‘C:\WINDOWS\TEMP\#sql_fe4_0.MYI’ (Errcode: 17):
Caused By: Precondition Error
at org.openmrs.util.DatabaseUpdater.executeChangelog(DatabaseUpdater.java:145)
at org.openmrs.web.filter.initialization.InitializationFilter$InitializationCompletion$1.run(InitializationFilter.java:817)
at java.lang.Thread.run(Unknown Source)
Caused by: liquibase.exception.MigrationFailedException: Migration failed for change set liquibase-update-to-latest.xml::2::upul:
Reason:
java.sql.SQLException: Can’t create/write to file ‘C:\WINDOWS\TEMP\#sql_fe4_0.MYI’ (Errcode: 17):
Caused By: Precondition Error
at liquibase.ChangeSet.execute(ChangeSet.java:204)
at liquibase.parser.visitor.UpdateVisitor.visit(UpdateVisitor.java:26)
at org.openmrs.util.DatabaseUpdater$1OpenmrsUpdateVisitor.visit(DatabaseUpdater.java:177)
at liquibase.parser.ChangeLogIterator.run(ChangeLogIterator.java:41)
at org.openmrs.util.DatabaseUpdater.executeChangelog(DatabaseUpdater.java:201)
at org.openmrs.util.DatabaseUpdater.executeChangelog(DatabaseUpdater.java:142)
… 2 more
Caused by: liquibase.exception.PreconditionErrorException: Precondition Error
at liquibase.preconditions.ForeignKeyExistsPrecondition.check(ForeignKeyExistsPrecondition.java:36)
at liquibase.preconditions.NotPrecondition.check(NotPrecondition.java:18)
at liquibase.preconditions.AndPrecondition.check(AndPrecondition.java:21)
at liquibase.ChangeSet.execute(ChangeSet.java:169)
… 7 more

This is in the babble category tagged as , , ,

Add a comment »

One of MySQL’s biggest annoyances is the lack of descriptive error messages. Often when dropping a table, index, foreign key you get a cryptic “errno 150 or errno152” error message.

Well, now when you come across those simply go to the command line and type:

show engine innodb status;

Scroll up a ways and see a very helpful message about exactly which other foreign key or index is causing the blockage! Why can’t MySQL put this information into error message to begin with??

This is in the openmrs category tagged as

Add a comment »

Currently tables created in MySQL default to MyISam. This is unacceptable for us at Openmrs. You can set a property in your my.cnf file called “default-storage-engine”, but I needed a solution that didn’t involve implementers having to modify their system config files.

I changed the jdbc connection url string to set a session property that sets InnoDB as the default engine:

jdbc:mysql://localhost:3306/databasename?autoReconnect=true&sessionVariables=storage_engine=InnoDB

NOTE! Requires mysql jdbc connecter version 3.1.18 or greater. See http://dev.mysql.com/doc/refman/5.0/en/connector-j.html for documentation and then http://dev.mysql.com/downloads/connector/j/ to download.

The error message I was getting before upgrading the mysql jdbc connector was:

java.sql.SQLException: Server connection failure during transaction. Due to underlying exception: ‘java.sql.SQLException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ” at line 1’.

** BEGIN NESTED EXCEPTION **

java.sql.SQLException
MESSAGE: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ” at line 1

STACKTRACE:

java.sql.SQLException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ” at line 1
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2921)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1570)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1665)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2972)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2902)
at com.mysql.jdbc.Statement.executeUpdate(Statement.java:929)
at com.mysql.jdbc.Connection.setSessionVariables(Connection.java:5077)
at com.mysql.jdbc.Connection.initializePropsFromServer(Connection.java:3680)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2684)
at com.mysql.jdbc.Connection.<init>(Connection.java:1474)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:264)
at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:135)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)
at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)
at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)
at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)

This is in the babble category tagged as ,

Add a comment »

« Previous Entries