Today I came across pgcli. It is a database console for postgres with syntax highlighting and more importantly autocompletion!

On OSX you can install it via brew, more instructions here.

Fire up pgcli -d DATABASE_NAME -U USER_NAME -W:

alt text

Rails provides a command dbconsole (aliased to db) which just opens up the default database console psql/mysql or something else based on adapter specified in config/database.yml.

I wrote up a dead simple rake task to openup pgcli using rails’ database config.

# lib/tasks/pgcli.rake
desc "Open up postgres with pgcli"
task :pgcli, [:environment] do |args|
  config = Rails.application.config.database_configuration[Rails.env]
  exec "PGPASSWORD=#{config['password']} pgcli -d #{config['database']} -U #{config['username']}"
end

Now you can use rake pgcli to open pgcli. Use this instead of rails dbconsole.

BONUS: They have similar clients for mysql and vertica databases as well.