Mac OS X Server

Use Postgres On Mountain Lion Server

Mountain Lion Server (OS X 10.8 Server) comes with Postgres baked in. Many of the server services are tied into the Postgres installation and in the future more will be as well. The GUI provides no options for Postgres, but there are plenty of settings that can be accessed using the serveradmin command line. Simply run serveradmin followed by settings and then postgres to see what these are, as follows:

serveradmin settings postgres

Which outputs the following:

postgres:log_connections = "on"
postgres:unix_socket_directory = "/var/pgsql_socket"
postgres:listen_addresses = ""
postgres:unix_socket_group = "_postgres"
postgres:log_statement = "ddl"
postgres:log_line_prefix = "%t "
postgres:unix_socket_permissions = "0770"
postgres:log_lock_waits = "on"
postgres:logging_collector = "on"
postgres:log_filename = "PostgreSQL.log"
postgres:dataDir = "/Library/Server/PostgreSQL/Data"
postgres:log_directory = "/Library/Logs/PostgreSQL"

To allow other computers to communicate with the default Postgres installtion, you’ll need to provide a listening address, which for ease of use, we’ll just call * (denoting all addresses for each interface installed on the system):

serveradmin settings postgres:listen_addresses="*"

We’ll also need to add a user that has access to _postgres, which we can do with dseditgroup. In this example, we’ll add user krypted, who’s already been created in the local users database:

dseditgroup -o edit -a krypted -t user _postgres

Once done, you can connect to port 5432 from another client system using the username and password which was defined in the dseditgroup option.

For more information on managing sql once you’ve gained access: