Getting Schema Spy to run on databases with lots of tables

Getting Schema Spy to run on databases with lots of tables

The other day I ran into issues with Schema Spy pointing it to a database with 1.200 tables for the first time.

The problem

The error output was the following:

Writing/diagramming detailsINFO  - Completed summary in 277 seconds

INFO  - Writing/diagramming details

.Exception in thread "main" java.lang.reflect.InvocationTargetException

        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:119)

        at java.base/java.lang.reflect.Method.invoke(Method.java:578)

        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)

        at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)

        at org.springframework.boot.loader.Launcher.launch(Launcher.java:51)

        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:52)

Caused by: org.schemaspy.output.diagram.RenderException: Failed to generate Table diagram

        at org.schemaspy.output.diagram.TableDiagram.generateTableDiagram(TableDiagram.java:24)

        at org.schemaspy.output.html.mustache.diagrams.MustacheTableDiagramFactory.generateRealTableDiagrams(MustacheTableDiagramFactory.java:93)

        at org.schemaspy.output.html.mustache.diagrams.MustacheTableDiagramFactory.generateTableDiagrams(MustacheTableDiagramFactory.java:57)

        at org.schemaspy.SchemaAnalyzer.generateHtmlDoc(SchemaAnalyzer.java:488)

        at org.schemaspy.SchemaAnalyzer.analyze(SchemaAnalyzer.java:289)

        at org.schemaspy.SchemaAnalyzer.analyze(SchemaAnalyzer.java:135)

        at org.schemaspy.cli.SchemaSpyRunner.runAnalyzer(SchemaSpyRunner.java:109)

        at org.schemaspy.cli.SchemaSpyRunner.run(SchemaSpyRunner.java:98)

        at org.schemaspy.Main.main(Main.java:55)

        at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)

        ... 5 more

Caused by: org.schemaspy.output.diagram.RenderException: javax.script.ScriptException: java.lang.StackOverflowError in  at line number 27 at column number 596797

        at org.schemaspy.output.diagram.vizjs.VizJSDot.render(VizJSDot.java:74)

        at org.schemaspy.output.diagram.TableDiagram.generateTableDiagram(TableDiagram.java:21)

        ... 14 more

Maybe you feel like I did: What the heck is going on here? You get all sorts of messages but where to find the clue?

Photo by JESHOOTS.COM on Unsplash

In fact I did you the courtesy of highlighting the issue “StackOverflowError”. Don’t look at the first error “InvocationMethodException”…this is quite common and only the generic source throwing the error at you but can have various reasons.

After some digging I found an existing issue at Github #462. Remembering from my days at University: Java has two types of memory….Heap and Stack (in case you are interested read more about it here). In that case creating the diagram simply consumes more memory than allocated by default.

The solution

The solution is to increase the stack size. You might need to do a bit of fiddling around this and run it multiple times with different sizes until you found the right one.

In my case upping it to 2 megabytes did to the trick. Use the Xss switch to achieve that like -Xss2m (Caution: no space allowed between -Xss and the value). Your command then will look something like this:
java -Xss2m -jar C:\SQL\schemaSpy\installation\schemaspy-6.2.4.jar -o C:\sql\schemaSpy\output\ -vizjs -t mssql17 -dp ‘C:\SQL\schemaSpy\installation\mssql-jdbc-12.4.0.jre11.jar‘ -connprops ‘encrypt\=false’ -db StackOverflowDocumentation -host ‘DESKTOP-RGO4OCI‘ -port 1433 -u ‘sa‘ -p ‘P4$$w0rd!

Happy documenting!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.