Configuring PostgreSQL on CentOS using Saltstack

Recently I’ve fallen in love with a mass server management system called “Salt” or “Saltstack”.  After playing with Chef and Puppet, this thing stands out as truly amazing…   For the first time possibly ever, I’m actually having *FUN* with a mass management system, however that’s a full writeup for another day. :)In this post I’m going to give a brief overview of how to install PostgreSQL 9.1 on CentOS/RedHat using Salt.

First of all, I’m using the Postgres RPMs from the PGDG repo, directly from  The big problem that you’ll run into is initializing the base pgsql directory/datases so Postgres can start.   When doing this manually, it’s pretty simple, you just run /etc/init.d/postgresql-9.1 initdb, and then start your service, done/done.   Salt, by default, will try to install the RPM and just fire off the service as it’s unaware of this manual necessary step, so here’s how you get around that…

Here’s the init.sls file for postgres that I have working now. This does the following things…

1. Installs the postgresql91-server RPM
2. Runs the equiv of “chkconfig on postgresql91-server”
3. Verifies the service is running everytime salt-master checks in with the salt-minion, if not it starts it.
4. Runs the initdb command, but *ONLY* if the postgresql.conf doesn’t exist, which it doesn’t on a fresh install, pre-initdb.

- name: postgresql91-server
- enabled: True

- cwd: /
- user: root
- names:
- service postgresql-9.1 initdb
- unless: stat /var/lib/pgsql/9.1/data/postgresql.conf
- require:
- pkg: postgresql91-server

There ya go, that should give you a fresh install of postgresql on CentOS/RedHat using the PGDP repo and the *AWESOME* SaltStack utility!

Add Comment

Required fields are marked *. Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.