Adoptable Cookbooks List

Looking for a cookbook to adopt? You can now see a list of cookbooks available for adoption!
List of Adoptable Cookbooks

Supermarket Belongs to the Community

Supermarket belongs to the community. While Chef has the responsibility to keep it running and be stewards of its functionality, what it does and how it works is driven by the community. The chef/supermarket repository will continue to be where development of the Supermarket application takes place. Come be part of shaping the direction of Supermarket by opening issues and pull requests or by joining us on the Chef Mailing List.

Select Badges

Select Supported Platforms

Select Status


postgresql_lwrp (21) Versions 1.6.3

Installs and configures postgresql for clients or servers

cookbook 'postgresql_lwrp', '~> 1.6.3', :supermarket
cookbook 'postgresql_lwrp', '~> 1.6.3'
knife supermarket install postgresql_lwrp
knife supermarket download postgresql_lwrp
Quality 100%

Chef cookbook
Code Climate
Build Status


This cookbook includes recipes and providers to install and configure postgresql database. This cookbook was tested with Postgresql 9.1, 9.2, 9.3, 9.4, 9.5, 9.6 & 10.

Supported platforms:

  • Debian 8
  • Debian 9
  • Ubuntu 14.04
  • Ubuntu 16.04
  • Ubuntu 18.04

Note: TravisCI tests for Ubuntu 18.04 are omitted now because they somehow hang. Local Vagrant & Docker-based tests are succesfull. This will be investigated further.




The minimal recommended version of chef-client is 13.0.113. It may still work on version 12.5.1 and older, but no tests are made starting from version 1.3.0 of this cookbook as Chef 12 is reaching its EOL in the April, 2018


  • apt
  • cron
  • poise-python


This cookbook have server and client attribute files.

With client attributes(["postgresql"]["client"]) you can set only postgresql client and library version.

Server attributes are starting from ["postgresql"]["defaults"] and used as default attributes for postgresql provider. You should not override this defaults, you can pass your settings to provider instead.


Resource: default


  • :create: creates postgresql cluster

Resource parameters

  • cluster_name: name attribute. Cluster name (e.g. main). Be aware, systemd (in Ubuntu 16.04 and Debian Jessie) not working with cluster names that containing dashes ('-').
  • cluster_version: set cluster version
  • cookbook: cookbook for templates. Skip this for default templates.
  • cluster_create_options: options for pg_createcluster (only locale related options)
  • configuration: Hash with configuration options for postgresql, see examples.
  • hba_configuration: Array with hba configuration, see examples.
  • ident_configuration: Array with ident configuration, see examples.
  • replication: Hash with replication configuration. See replication example.
  • replication_initial_copy: Boolean. If true pg_basebackup will be exec to make initial replication copy. Default is false.
  • replication_start_slave: Boolean. If true slave cluster will be started after creation. Should be used with replication_initial_copy option. Default false.
  • allow_restart_cluster: Can be first, always or none. Specifies when cluster must restart instead of reload. first – only first time after installation. always – always restart, even if changes doesn't require restart. none - never, use reload every time. Default is none.


Cloud backup helper: helper can be found at /opt/wal-e/bin/.

Usage: <cluster_name> <cluster_version> last|count

  • cluster_name – postgresql cluster name (ex. main)
  • cluser_version – postgresql cluser version (ex. 9.3)
  • last – shows last backup time
  • count – shows total number of backups.


Example master database setup:

postgresql 'main' do
  cluster_version '9.3'
  cluster_create_options( locale: 'ru_RU.UTF-8' )
      listen_addresses:           '',
      max_connections:            300,
      ssl_renegotiation_limit:    0,
      shared_buffers:             '512MB',
      maintenance_work_mem:       '64MB',
      work_mem:                   '8MB',
      log_min_duration_statement: 200
      { type: 'host', database: 'all', user: 'all', address: '', method: 'md5' },
      { type: 'host', database: 'replication', user: 'postgres', address: '', method: 'trust' }

Example slave database setup:

postgresql 'main' do
   cluster_version '9.3'
  cluster_create_options( locale: 'ru_RU.UTF-8' )
      listen_addresses:           '',
      max_connections:            300,
      ssl_renegotiation_limit:    0,
      shared_buffers:             '512MB',
      maintenance_work_mem:       '64MB',
      work_mem:                   '8MB',
      log_min_duration_statement: 200
      { type: 'host', database: 'all', user: 'all', address: '', method: 'md5' },
      { type: 'host', database: 'replication', user: 'postgres', address: '', method: 'trust' }
    standby_mode: 'on',
    primary_conninfo: 'host=',
    trigger_file: '/tmp/pgtrigger'
  replication_initial_copy true
  replication_start_slave true

Example slave configuration with replication slots (PostgreSQL >= 9.4)

  standby_mode: 'on',
  primary_conninfo: 'host=',
  trigger_file: '/tmp/pgtrigger'
  primary_slot_name: 'some_slot_on_master'

Don't forget to create slot on master server before:

# SELECT pg_create_physical_replication_slot('some_slot_on_master');

Example users and databases setup

postgresql_user 'user01' do
  in_version '9.3'
  in_cluster 'main'
  unencrypted_password 'user01password'

postgresql_database 'database01' do
  in_version '9.3'
  in_cluster 'main'
  owner 'user01'

Example full daily database backup

postgresql_cloud_backup 'main' do
  utility 'wal-g'
  in_version '9.3'
  in_cluster 'main'
  full_backup_time weekday: '*', month: '*', day: '*', hour: '3', minute: '0'
  # Data bag item should contain following keys for S3 protocol:
  # aws_access_key_id, aws_secret_access_key, wale_s3_prefix
  parameters Chef::EncryptedDataBagItem.load('s3', 'secrets') {|i| i != "id"}
  # Or just a hash, if you don't use data bags:
  parameters { aws_access_key_id: 'access_key', aws_secret_access_key: 'secret_key', walg_s3_prefix: 's3_prefix' }
  # In case you need to prepend wal-e with, for example, traffic limiter
  # you can use following method:
  command_prefix 'trickle -s -u 1024'
  # It will be prepended to resulting wal-e execution in cron task

Example usage of cloud backup helper usage

$ /opt/wal-e/bin/ main 9.3 last
$ /opt/wal-e/bin/ main 9.3 count

Example of how to install extensions from postgresql-contrib
NOTE: schema and version are optional parameters, but others are required

postgresql_extension 'cube' do
  in_version '9.4'
  in_cluster 'main'
  db 'test01'
  schema 'public'

Example of how to install extensions from
NOTE: schema is an optional parameter, but others are required

pgxn_extension 'pg_lambda' do
  in_version '9.4'
  in_cluster 'main'
  db 'test01'
  version '1.0.2'
  stage 'stable'

License and Maintainer

Maintainer:: LLC Express 42 (

License:: MIT

1.6.3 (Aug 19, 2019)

  • (New) wal-g version 0.2.11
  • (New) bundle update

1.6.2 (Aug 05, 2019)

  • (Fix) more typos in attributes

1.6.1 (Jul 30, 2019)

  • (Fix) typos in attributes.

1.6.0 (Jul 03, 2019)

  • (Deprecation) postgresql_cloud_backup attribute protocol was removed. It was used only for a partial env vars validation.

1.5.4 (Jun 28, 2019)

  • Travis config: tests for Ubuntu 18.04 were removed again. Run local ones.

1.5.3 (Jun 27, 2019)

  • (New) WAL-G version 0.2.9
  • (New) wal-g wal-push fix by injecting the PATH variable into the envdir
  • (New) ruby 2.6.3 for TravisCI
  • (New) Test Kitchen suites for Chef 15

1.5.2 (Feb 25, 2019)

  • (New) tests for PostgreSQL 9.1 & 9.2 were dropped from TravisCI configuration
  • (New) WAL-G version 0.2.6 which has new GPG support implementation

1.5.1 (Feb 17, 2019)

  • (Fix) envdir's files should be marked as sensitive.
  • (Fix) Set PGHOST environment variable to /var/run/postgresql for wal-g if unset.

1.5.0 (Feb 16, 2019)

  • (New) PostgreSQL 11 tests
  • (New) wal-g support for cloud backup
  • (New) Ruby 2.6.0 for TravisCI tests
  • (New) Inspec configuration to test running PostgreSQL configuration
  • (Fix) pip version 18.0 was pinned as the newer fails to install to sandbox
  • (Fix) Some minor ruby style fixes
  • (Fix) Other pg extension should be installed during integration tests

1.4.2 (May 22, 2018)

  • (New) Ubuntu 18.04 tests
  • (New) Test Kitchen configuration for AWS cloud was removed
  • (Fix) cookbook poise-python version was restricted again >= 1.7.0
  • (Fix) Some minor Test Kitchen configuration improvements

1.4.1 (May 15, 2018)

  • (Fix) Unpin poise-python cookbook version

1.4.0 (Apr 10, 2018)

  • (New) Chef 14 support & tests
  • (New) LWRP-defined resources were rewritten using the new custom resource style
  • (Fix) TravisCI: all Chef 13 test were enabled

1.3.1 (Apr 03, 2018)

  • (Fix) TravisCI build method. Now using sethvargo/stove gem instead of dpl

1.3.0 (Apr 03, 2018)

  • (New) Chef 12 test were dropped. (Chef 12 reaches EOL at the and of April 2018)
  • (New) Chef 13 full support;
  • (New) WAL-E version 1.1.0;
  • (New) poise-python cookbook is used instead of outdated python;
  • (Fix) TravisCI configuration was updated to test against more OSes and to use Chef 13;
  • (Fix) Berksfile version pins were removed;

1.2.4 (Mar 12, 2018)

  • (Fix) Rename params method in postgresql_cloud_backup for compatibility with Chef 13

1.2.3 (Jan 31, 2018)

  • (Fix) Resource postgresql PostgreSQL version validation.
  • (Fix) Use resource attributes to set PostgreSQL version for test purposes.

1.2.2 (Jan 16, 2018)

  • (New) PostgreSQL 10 support.
  • (New) Integration tests were migrated to InSpec.
  • (New) InSpec resources: postgres_database
  • (Fix) InSpec resources: postgres_cluster, postgres_extension & postgres_user were refactored.
  • (Fix) Test Kitchen: use one test recipe instead of one-recipe-per-pg-version.
  • (Fix) Test Kitchen: use only official images.
  • (Fix) Test Kitchen: tests for Chef 11 support were removed, as outdated.
  • (Fix) Test Kitchen: Test for Postgresql 9.0 were removed; there is PostgreSQL 9.0 package on modern systems.
  • (Fix) [postgresql] fix ruby_block notifications.
  • (Fix) [pgtest] user creation should be invoked using encrypted_password attribute for better compatibility.

1.2.1 (Dec 15, 2016)

  • (New) Autoremove checkpoint_segments from configuration if pg > 9.4

1.2.0 (Jul 22, 2016)

  • (New) Add extension lwrp to install extensions from postgresql-contrib subpackage, which comes installed
  • (New) Add pgxn extension lwrp to install extensions from website, using pgxn client
  • (New) Add test recipes for installing extensions with newly introduced resources

1.1.15 (Sep 24, 2015)

  • (Fix) [postgresql] Fix initial slave creation on 9.1

1.1.14 (Aug 11, 2015)

  • (Fix) [postgresql_database] Fix database existence

1.1.13 (Jul 17, 2015)

  • (Fix) [common] Fix run under Chef 11

1.1.12 (Jun 27, 2015)

  • (Fix) [common] Fix compatibility with Chef 12.4.0
  • (New) [postgresql_user] Use inline resources in user provider

1.1.11 (Apr 7, 2015)

  • (New) [common] Return to LR for all resources

1.1.10 (Apr 5, 2015)

  • (New) [cloud_backup] Add backup retention
  • (New) [cloud_backup] Add (See README)
  • (Fix) [cloud_backup] install libffi-dev package for cffi
  • (Fix) [common] Fix reload on Chef 12

1.1.9 (Mar 5, 2015)

  • (Fix) [metadata] Fix recipes name

1.1.8 (Mar 3, 2015)

  • (New) [Replication] Add primary_slot_name param support in recovery.conf
  • (New) [cloud_backup] Add add prefix to crontab command
  • (Fix) [packages] Install dev package only for actual cluster version

1.1.7 (Jan 22, 2015)

  • (Fix) Remove wal-e pip attribute
  • (New) Add serverspec tests for cloud backup

1.1.6 (Jan 21, 2015)

  • (New) Use virtualenv for wal-e
  • (New) Add test recipe for cloud backup

1.1.5 (Dec 28, 2014)

  • (Fix) Fix cloud_backup cron script name

1.1.4 (Dec 22, 2014)

  • (Fix) Fix pg version checks

1.1.3 (Dec 22, 2014)

  • (New) ssl key and cert linkage for pg < 9.2

1.1.2 (Dec 22, 2014)

  • (Fix) Fix full_backup_time param

1.1.1 (Dec 18, 2014)

  • (Fix) Fix Test Kitchen boxes
  • (Fix) Fix postgresql start after reboot

1.1.0 (Dec 10, 2014)

  • (New) Add cloud backup lwrp, using wal-e for cloud backup

1.0.1 (Oct 31, 2014)

  • (Fix) Fix broken allow_restart_cluster option

1.0.0 (Aug 25, 2014)

  • (New) Flat configuration file
  • (New) Initial replicaton can be started automatically
  • (New) Option allow_restart_cluster allows do restart instead reload (Only first time or always)
  • (New) Resources/providers for database and user creation
  • (New) Recipe apt_official_repository with official postgresql repository
  • (New) Severspec tests added
  • (Removed) Removed databags for users and databases. You should use appropriate providers
  • (Fix) pg_ident template fixed

0.2.3 (Jun 18, 2013)

Minor fixes

  • Cluster create options were defined as Hash and accessed as Mash.
  • pg_hba.conf became faulty on long db/user names or other line fields.
  • Examples in readme was badly formatted and contained small syntax issues.
  • ssl was hardcoded to postgresql.conf.

0.2.2 (May 8, 2013)

Minor fixes

  • Check cluster_create_options hash for key before accessing it.

0.2.1 (Apr 14, 2013)

Minor fixes

  • Style fixes to satisfy foodcritic wishes

0.2.0 (Apr 14, 2013)


  • Set LANG from cluster_create for postgresql package install(used in pg_clustercreate in debian scripts)

Collaborator Number Metric

1.6.3 passed this metric

Contributing File Metric

1.6.3 passed this metric

Foodcritic Metric

1.6.3 passed this metric

No Binaries Metric

1.6.3 passed this metric

Testing File Metric

1.6.3 passed this metric

Version Tag Metric

1.6.3 passed this metric