Do you compile to shared library? Things to check: You do call NimMain or setupForeignThreadGC.
Another thing I recommend trying is to compile with \--gc:arc -d:useMalloc this gives you garbage collection free environment that will ease integration with postgres.