How to install pgcrypto module for postgresql?

I've been having a look at postgresql for OS X Lion Server and was planning to use it for setting up virtual mailboxes, rather than adding a real new user to the machine every time I need a new mail user. However, it appears that the pgcrypto module is not installed my default, so hashing passwords appropriately within postgresql is not possible.


Does anyone know if it's possible to install the pgcrypto module without starting from source code and completely reinstalling postgresql?


Or alternatively, I'd be happy if anyone could recommend a best-practice for virtual mail users without creating local user accounts on the server.


Cheers,


Andrew.

Posted on Aug 6, 2011 10:29 AM

Reply
1 reply

Aug 6, 2011 9:55 PM in response to jarvisad

Despite not finding much in Google or elsewhere, I managed to find the solution to this problem. Seems logical in hindsight, but it took me a lot of running around before I got there.


  1. Download the source code for postgresql from Apple: PostgreSQL-23
  2. Open Terminal
  3. cd ~/Downloads
  4. tar xvf PostgreSQL-23.tar
  5. Edit the Makefile and add pgcrypto to the ContribTools parameter. It should then read "ContribTools = hstore intarray pg_upgrade pg_upgrade_support pgcrypto"
  6. make
  7. sudo make install-contrib
  8. sudo cp /tmp/PostgreSQL/Release/usr/lib/postgresql/pgcrypto.so /usr/lib/postgresql/
  9. sudo cp /tmp/PostgreSQL/Release/usr/share/postgresql/contrib/pgcrypto.sql /usr/share/postgresql/contrib/
  10. sudp cp /tmp/PostgreSQL/Release/usr/share/postgresql/contrib/uninstall_pgcrypto.sql /usr/share/postgresql/contrib/
  11. Don't know whether it was necessary, but I stopped and started postgres with serveradmin at this point. sudo serveradmin stop postgres; sudo serveradmin start postgres
  12. Then just update the databases where you need the crypt functionality. e.g. sudo -u _postgres psql -d template1 -f /usr/share/postgresql/contrib/pgcrypto.sql


That's it. Now when I go into the appropriate database I get the expected return on:


select crypt('thisisyourpassword', gen_salt('bf'));

crypt

--------------------------------------------------------------

$2a$06$5gTpj2O6qyCvLs4iCcnBxuB/uxEdTMBI96fbHyyGOiP.A6t7nfKzC

(1 row)


Hope that helps anyone who is looking to store passwords in their postgresql database that is installed by default with Lion Server. I just didn't want to install postgresql from source (or any other precompiled package) and end up with two independent instances of postgresql running on the same server. Seems a bit messy (and unnecessary) to me.


Cheers,


Andrew.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

How to install pgcrypto module for postgresql?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.