saltstack-formulas/postgres-formula(opens in a new tab)
Language: SaltStack
- stars
- 74
- watchers
- 36
- forks
- 290
- open issues
- 37
- Last updated
- 05/11/2026
Language: SaltStack
A formula to install and configure PostgreSQL server.
Table of Contents
See the full SaltStack Formulas installation and usage instructions.
If you are interested in writing or contributing to formulas, please pay attention to the Writing Formula Section.
If you want to use this formula, please pay attention to the FORMULA file and/or git tag,
which contains the currently released version. This formula is versioned according to Semantic Versioning.
See Formula Versioning Section for more details.
Commit message formatting is significant!!
Please see How to contribute for more details.
postgresInstalls and configures both PostgreSQL server and client with creation of various DB objects in the cluster. This state applies to both Linux and MacOS.
postgres.clientInstalls the PostgreSQL client binaries and libraries on Linux.
postgres.manageCreates such DB objects as: users, tablespaces, databases, schemas and extensions.
See pillar.example file for details.
postgres.pythonInstalls the PostgreSQL adapter for Python on Linux.
postgres.serverInstalls the PostgreSQL server package on Linux, prepares the DB cluster and starts the server using packaged init script, job or unit.
Note
For PostgreSQL server before version 10 to work inside a FreeBSD Jail
set sysvshm=new and sysvsem=new.
DO NOT SET allow.sysvipc=1. It defeats the purpose of using Jails.
Further information: https://blog.tyk.nu/blog/freebsd-jails-and-sysv-ipc/
Running inside a container (using Packer, Docker or similar tools), when OS init process
is not available to start the service and enable it on "boot", set pillar value:
postgres: bake_image: True
This toggles starting PostgreSQL daemon by issuing raw pg_ctl or pg_ctlcluster command.
postgres.upstreamConfigures the PostgreSQL Official (upstream) repository on target system if applicable.
The state relies on the postgres:use_upstream_repo Pillar value which could be set as following:
True (default): adds the upstream repository to install packages fromFalse: makes sure that the repository configuration is absent'postgresapp' (MacOS) uses upstream PostgresApp package repository.'homebrew' (MacOS) uses Homebrew postgresThe postgres:version Pillar controls which version of the PostgreSQL packages should be
installed from the upstream Linux repository. Defaults to 9.5.
postgres.droppedMeta state to remove Postgres software. By default the release installed by formula is targeted only. To target multiple releases, set pillar postgres.remove.multiple_releases: True.
postgres.server.removeRemove server, lib, and contrib packages. The postgres.server.remove will retain data by default (no data loss) - set pillar postgres.remove.data: True to remove data and configuration directories also.
postgres.client.removeRemove client package.
postgres.dev.removeRemove development and python packages.
Linux testing is done with kitchen-salt.
kitchen convergeCreates the docker instance and runs the postgres main state, ready for testing.
kitchen verifyRuns the inspec tests on the actual instance.
kitchen destroyRemoves the docker instance.
kitchen testRuns all of the stages above in one go: i.e. destroy + converge + verify + destroy.
kitchen loginGives you SSH access to the instance for manual testing.
Windows/FreeBSD/OpenBSD testing is done with kitchen-salt.
$ gem install bundler
$ bundle install --with=vagrant
$ bin/kitchen test [platform]Where [platform] is the platform name defined in kitchen.vagrant.yml,
e.g. windows-81-latest-py3.
When testing using Vagrant you must set the environment variable KITCHEN_LOCAL_YAML to kitchen.vagrant.yml. For example:
$ KITCHEN_LOCAL_YAML=kitchen.vagrant.yml bin/kitchen test # Alternatively, $ export KITCHEN_LOCAL_YAML=kitchen.vagrant.yml $ bin/kitchen test
Then run the following commands as needed.
bin/kitchen convergeCreates the Vagrant instance and runs the postgres main state, ready for testing.
bin/kitchen verifyRuns the inspec tests on the actual instance.
bin/kitchen destroyRemoves the Vagrant instance.
bin/kitchen testRuns all of the stages above in one go: i.e. destroy + converge + verify + destroy.