Dev Corner

Saturday, July 29, 2006

Postgresql part 1

There are two pieces of free software that I really love. Erlang and Postgresql. So, a while back I decided to marry the two to allow me to issue queries from Erlang via a pure erlang library for Postgresql. At the time, there were no postgresql libraries in jungerl.
There is now, but I had created my own and I think it would be worthwhile posting anyway.

Originally, I had opted for a port program. It worked, but I didn't want to have to deal with SIGSEGVs coming from the port program, or memory leaks since the port program was written in C++. Its not to say that I couldn't periodically restart the port process or use another language with a garbage collector and established postgresql bindings. I just didn't feel right to have it in a 24/7 system that could have those types of potential dangers.

Also, I saw that implementing a pure erlang postgresql library wasn't terribly difficult, so I went ahead.

Here are some of the main features that I really think make it stand out:
  • Connection pooling built in
    • Pool connections can auto-regenerate after a certain amount of queries
  • Easy query issuing
    • Convenience functions to execute common queries like ones that return a single row or result
  • gen_server and gen_fsm implementation for each connection
  • pool statistics for server monitoring
  • convenience functions to execute queries that return single results
  • Sql statement logging and timing code built in
  • Rock solid from what I've seen so far
What's missing:
  • Ability to execute prepared statements
This library will soon be posted to jungerl as a postgresql alternative.

But before I do that, I wanted to create a set of blog entries that detail the design of the library , from start to finish, that will hopefully give people new to erlang something to learn from with a real world purpose.

I absolutely advise anyone starting out in Erlang to read Joe Armstrongs thesis. Required reading before we start, ok?

There are really good tutorials for beginners on his page as well.

One more thing I wish to note, there is an odbc port interface which works nicely. I just didn't want to have 20 or 50 processes going in a postgresql connection pool. That is another reason I wanted to go the pure erlang route.

I'll try to make a new series post every week until done.
The next installment in this series will be posted soon...

2 Comments:

  • This comment has been removed by the author.

    By Blogger Fudge, at 12:56 PM  

  • Did you ever release this, or keep it working with newer postgresql versions?

    By Blogger Fudge, at 12:57 PM  

Post a Comment

<< Home