title: Setup ejabberd with PostgreSQL
body: <p>I am having trouble setting up ejabberd to use PostgreSQL. My environment is OSX for development and a Debian server for production.</p>
  
  <p>The OSX story goes as follows:
  ejabberd is compiled from source with odbc support. erlang is installed through macports.
  First problem I encountered was the psql modules for erlang. In the docs it's mentioned to compile them from a non-existing svn location. I copied from the binary installation the relevant <code>.beam</code> to my ejabberd lib which seems to work fine.</p>
  
  <p>My ejabberd configuration is deliberately minimal and at the moment only does authentication through odbc with the native pgsql driver. However, while ejabberd starts cleanly it never actually creates the table structure. In <a href="https://github.com/processone/ejabberd/blob/master/src/odbc/pg.sql" rel="nofollow">processone's repo</a> there is pg.sql but with a big warning about it being obsolete and mentioning that the tables will be created automatically. How and when does that happen? I can verify that for instance trying to authenticate does send queries to postgresql, but since there are no tables there, it errors out...</p>
  
  <p>ejabberd config follows:</p>
  
  <pre><code>{loglevel, 4}.
  
  {hosts, ["localhost"]}.
  
  {listen,
    [
  
    {{5222, {127, 0, 0, 1}}, ejabberd_c2s, [
        {access, c2s},
        {shaper, c2s_shaper},
        {max_stanza_size, 65536}
             ]},
  
    {{5269, {127, 0, 0, 1}}, ejabberd_s2s_in, [
           {shaper, s2s_shaper},
           {max_stanza_size, 131072}
          ]},
  
    {{5280, {127, 0, 0, 1}}, ejabberd_http, [
         http_bind,
         web_admin
        ]}
  
   ]}.
  
  {odbc_server, {pgsql, "localhost", "ejabberd", "ejabberd", "ejabberd"}}.
  
  {auth_method, [odbc]}.
  
  {shaper, normal, {maxrate, 1000}}.
  {shaper, fast, {maxrate, 50000}}.
  
  {host_config, "localhost", [{acl, admin, {user, "admin", "localhost"}}]}.
  
  {acl, local, {user_regexp, ""}}.
  
  {access, max_user_sessions, [{10, all}]}.
  
  {access, local, [{allow, local}]}.
  
  {access, c2s, [{deny, blocked},
           {allow, all}]}.
  
  {access, c2s_shaper, [{none, admin},
            {normal, all}]}.
  
  {access, s2s_shaper, [{fast, all}]}.
  
  {access, announce, [{allow, admin}]}.
  
  {access, configure, [{allow, admin}]}.
  
  {access, muc_admin, [{allow, admin}]}.
  
  {access, muc, [{allow, all}]}.
  {access, muc_create, [{allow, local}]}.
  
  {access, register, [{allow, all}]}.
  
  {access, pubsub_createnode, [{allow, local}]}.
  
  
  {language, "en"}.
  
  {modules,
   [
    {mod_adhoc,    []},
    {mod_announce, [{access, announce}]},
    {mod_caps,     []},
    {mod_configure,[]},
    {mod_disco,    []},
    {mod_http_bind,[]},
    {mod_last,     []},
    {mod_offline,  []},
    {mod_privacy,  []},
    {mod_private,  []},
    {mod_pubsub,   [
        {access_createnode, pubsub_createnode},
        {ignore_pep_from_offline, false},
        {last_item_cache, false},
        {nodetree, "dag"},
        {plugins, ["dag", "flat", "hometree", "pep"]},
        {max_items_node, 1000}
       ]},
    {mod_register, [
        {welcome_message, {"Welcome!",
               "Welcome to localhost Jabber server."}},
        {access, register}
       ]},
    {mod_roster,   []},
    {mod_shared_roster,[]},
    {mod_time,     []},
    {mod_vcard,    []},
    {mod_version,  []}
   ]}.
  </code></pre>