title: Symbol not found: _PQclear (caldav server tools broken after Mavericks update on OSX Server)
body: <p>After upgrading my server to Mavericks and Server.app version 3, those tools stopped to work properly : </p>
  
  <p>
  <b>calendarserver_export</b><br/>
  <b>calendarserver_manage_principals</b><br/>
  ...
  </p>
  
  <p>
  When I enter this command, for example : 
  </p>
  
  <pre><code>sudo calendarserver_export -u &lt;account_name&gt;
  </code></pre>
  
  <p>
  then this error is displayed : 
  </p>
  
  <pre><code>    Traceback (most recent call last):
    File "/Applications/Server.app/Contents/ServerRoot/usr/sbin/calendarserver_export", line 32, in &lt;module&gt;
      from calendarserver.tools.export import main
    File "/Applications/Server.app/Contents/ServerRoot/usr/share/caldavd/lib/python/calendarserver/tools/export.py", line 50, in &lt;module&gt;
      from calendarserver.tools.cmdline import utilityMain, WorkerService
    File "/Applications/Server.app/Contents/ServerRoot/usr/share/caldavd/lib/python/calendarserver/tools/cmdline.py", line 21, in &lt;module&gt;
      from calendarserver.tap.caldav import CalDAVServiceMaker, CalDAVOptions
    File "/Applications/Server.app/Contents/ServerRoot/usr/share/caldavd/lib/python/calendarserver/tap/caldav.py", line 87, in &lt;module&gt;
      from twistedcaldav.upgrade import UpgradeFileSystemFormatStep, PostDBImportStep
    File "/Applications/Server.app/Contents/ServerRoot/usr/share/caldavd/lib/python/twistedcaldav/upgrade.py", line 63, in &lt;module&gt;
      from calendarserver.tap.util import getRootResource, FakeRequest, directoryFromConfig
    File "/Applications/Server.app/Contents/ServerRoot/usr/share/caldavd/lib/python/calendarserver/tap/util.py", line 87, in &lt;module&gt;
      from txdav.base.datastore.subpostgres import PostgresService
    File "/Applications/Server.app/Contents/ServerRoot/usr/share/caldavd/lib/python/txdav/base/datastore/subpostgres.py", line 35, in &lt;module&gt;
      import pgdb
    File "/Applications/Server.app/Contents/ServerRoot/usr/share/caldavd/lib/python/pgdb.py", line 66, in &lt;module&gt;
      from _pg import *
  ImportError: dlopen(/Applications/Server.app/Contents/ServerRoot/usr/share/caldavd/lib/python/_pg.so, 2): Symbol not found: _PQclear
    Referenced from: /Applications/Server.app/Contents/ServerRoot/usr/share/caldavd/lib/python/_pg.so
    Expected in: flat namespace
   in /Applications/Server.app/Contents/ServerRoot/usr/share/caldavd/lib/python/_pg.so
  </code></pre>
  
  <p>
  All these tools have in common to access the caldav data via python, through PyGreSQL (caldav data is hosted in a postgres database).
  I managed to reproduce very simply this problem by : 
  </p>
  
  <pre><code>#login with root
  bob $ sudo -i
  #launch python and import pg (postgres module for python)
  root $ python
  Python 2.7.5 (default, Mar  9 2014, 22:15:05) 
  [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
  Type "help", "copyright", "credits" or "license" for more information.
  &gt;&gt;&gt; import pg
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
    File "/Library/Python/2.7/site-packages/PyGreSQL-4.1.1-py2.7-macosx-10.9-intel.egg/pg.py", line 31, in &lt;module&gt;
      from _pg import *
  ImportError: dlopen(/Library/Python/2.7/site-packages/PyGreSQL-4.1.1-py2.7-macosx-10.9-intel.egg/_pg.so, 2): Symbol not found: _PQclear
    Referenced from: /Library/Python/2.7/site-packages/PyGreSQL-4.1.1-py2.7-macosx-10.9-intel.egg/_pg.so
    Expected in: flat namespace
   in /Library/Python/2.7/site-packages/PyGreSQL-4.1.1-py2.7-macosx-10.9-intel.egg/_pg.so
  </code></pre>
  
  <p>
  <b>BUT</b>, if I launch python from my user account (not root), <b>I don't get the error</b>.<br/>
  I assume there is something wrong with the path, or something similar, but I can't find what...<br/>
  I need to have root credentials to be able to use **calendarserver_export** 
  </p>
  
  <p>Any clues ??</p>