Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
C

chef-postgresql

> 编程语言
Open source

Chef cookbook for PostgreSQL components

173 stars0 likes2 views
WebsiteGitHub

About

Chef cookbook for PostgreSQL components

chef-postgresql

Flair

Description

Installs PostgreSQL, The world's most advanced open source database.

This installs postgres 9.x from the PostgreSQL Apt Repository.

Currently supported versions:

  • 9.0
  • 9.1
  • 9.2
  • 9.3
  • 9.4

The default version is 9.4.

Requirements

Supported Platforms

The following platforms are supported by this cookbook, meaning that the recipes run on these platforms without error:

  • Debian 7.8
  • Ubuntu 12.04
  • Ubuntu 14.04

Chef

This cookbook requires Chef >= 11.13 due to the use of the sensitive attribute for some resources.

Cookbooks

  • apt
  • minitest-handler (suggested, not required)

Recipes

  • postgresql - Set up the apt repository and install dependent packages
  • postgresql::apt_repository - Internal recipe to setup the apt repository
  • postgresql::client - Front-end programs for PostgreSQL 9.x
  • postgresql::configuration - Internal recipe to manage configuration files
  • postgresql::contrib - Additional facilities for PostgreSQL
  • postgresql::data_directory - Internal recipe to setup the data directory
  • postgresql::dbg - Debug symbols for the server daemon
  • postgresql::debian_backports - Internal recipe to manage debian backports
  • postgresql::doc - Documentation for the PostgreSQL database management system
  • postgresql::libpq - PostgreSQL C client library and header files for libpq5 (PostgreSQL library)
  • postgresql::postgis - Geographic objects support for PostgreSQL 9.x (currently Ubuntu only)
  • postgresql::server - Object-relational SQL database, version 9.x server
  • postgresql::server_dev - Development files for PostgreSQL server-side programming
  • postgresql::service - Internal recipe to declare the system service
  • postgresql::setup_databases - Internal recipe to manage specified databases
  • postgresql::setup_extensions - Internal recipe to manage specified database extensions
  • postgresql::setup_languages - Internal recipe to manage specified database languages
  • postgresql::setup_users - Internal recipe to manage specified users

Usage

This cookbook installs the postgresql components if not present, and pulls updates if they are installed on the system.

This cookbook provides three definitions to create, alter, and delete users as well as create and drop databases, or setup extensions. Usage is as follows:

Users

ruby
# create a user
postgresql_user "myuser" do
  superuser false
  createdb false
  login true
  replication false
  password "mypassword"
end

# create a user with an MD5-encrypted password
postgresql_user "myuser" do
  superuser false
  createdb false
  login true
  replication false
  encrypted_password "667ff118ef6d196c96313aeaee7da519"
end

# drop a user
postgresql_user "myuser" do
  action :drop
end

Or add users via attributes:

json
"postgresql": {
  "users": [
    {
      "username": "dickeyxxx",
      "password": "password",
      "superuser": true,
      "replication": false,
      "createdb": true,
      "createrole": false,
      "inherit": true,
      "replication": false,
      "login": true
    }
  ]
}

Databases and Extensions

ruby
# create a database
postgresql_database "mydb" do
  owner "myuser"
  encoding "UTF-8"
  template "template0"
  locale "en_US.UTF-8"
end

# install extensions to database
postgresql_extension "hstore" do
  database "mydb"
end

postgresql_language "plpgsql" do
  database "mydb"
end

# drop dblink extension
postgresql_extension "dblink" do
  database "mydb"
  action :drop
end

# drop a database
postgresql_database "mydb" do
  action :drop
end

Or add the database via attributes:

json
"postgresql": {
  "databases": [
    {
      "name": "my_db",
      "owner": "dickeyxxx",
      "template": "template0",
      "encoding": "UTF-8",
      "locale": "en_US.UTF-8",
      "extensions": ["hstore", "dblink"],
      "postgis": true
    }
  ]
}

Configuration

The postgresql.conf configuration may be set one of two ways:

  • set individual node attributes to be interpolated into the default template
  • create a custom configuration hash to write a custom file

To create a custom configuration, set the node["postgresql"]["conf"] hash with your custom settings:

json
"postgresql": {
  "conf": {
    "data_directory": "/dev/null",
    // ... all options explicitly set here
  }
}

You may also set the contents of pg_hba.conf via attributes:

…

Change APT distribution

Currently the APT distributions are sourced from http://apt.postgresql.org/pub/repos/apt/. In some cases this source might not immediately contain a package for the distribution of your target system.

The node["postgresql"]["apt_distribution"] attribute can be used to install PostgreSQL from a different compatible distribution:

json
"postgresql": {
  "apt_distribution": "precise"
}

Attributes

…

TODO

  • Add support for replication setup
  • Add installation and configuration for the following packages:
postgresql-{version}-ip4r
postgresql-{version}-pgq3
postgresql-{version}-pgmp
postgresql-{version}-plproxy
postgresql-{version}-repmgr
postgresql-{version}-debversion
postgresql-{version}-pgpool2
postgresql-{version}-slony1-2

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Contributors

Many thanks go to the following who have contributed to making this cookbook even better:

  • @flashingpumpkin
    • recipe bugfixes
    • add pg_user and pg_database definitions
  • @cmer
    • add encrypted_password param for pg_user definition
  • @dickeyxxx
    • speed up recipe loading and execution
    • add support for specifying database locale
    • add support for adding users and databases via attributes
  • @alno
    • add support to install additional languages/extensions/postgis to existing databases
    • add pg_database_extensions definition
  • @ermolaev
    • improve platform check for source repo
    • support debian 7 (wheezy)
  • @escobera
    • fix for missing ssl directives in postgresql.conf
  • @cdoughty77
    • allow finer tuning inside pg_hba.conf file
  • @NOX73
    • fix postgresql.conf ssl parameter failure on 9.1
  • @navinpeiris
    • add ability to configure apt distribution
  • @michihuber
    • create data/config dirs recursively
  • @sethcall
    • allow 'lazy' evaluation of configs in the custom template
  • @jherdman
    • update README to include updated apt repository link
    • add support for version 9.3
  • @stianselland
    • fix idempotence for pg_user definition
  • @alenia
    • conditionally override attributes in postgresql.conf
    • support for customizable apt sources
    • add ability to use an apt keyserver
  • @Randommood
    • conditionally override attributes in postgresql.conf
    • support for customizable apt sources
    • add ability to use an apt keyserver
  • @vrischmann
    • uncomment wal_writer_delay attribute
  • @brainopia
    • support encrypted_password in the pg_user recipe
  • @tpitale
    • update example encoding/locales in README to fix error
  • @seamusabshere
    • uncomment various configuration settings
    • uncomment more configuration settings
    • uncomment commit_delay and temp_buffers settings
    • uncomment random_page_cost and seq_page_cost settings
  • @RichardWigley
    • fix empty password causes exception
  • @phumpal
    • update default["postgresql"]["apt_key"] to new location
  • @mjallday
    • allow controlling how to restart postgres
  • @cgunther
    • uncomment log_filename attribute
  • @rosenfeld
    • ensure proper database is selected in pg_database definition
  • @j-martin
    • ensure proper quoting of role name in pg_user definition
  • @helgi
    • add replication mode to pg_user definition
  • @vesln
    • add missing ssl_ca_file and ssl_crl_file attributes to the configuration template
  • @vivid-inc
    • add service_actions attribute
  • @rmoriz
    • remove redundant postgis attribute

License

chef-postgresql

  • Freely distributable and licensed under the MIT license.
  • Copyright (c) 2012-2015 Phil Cohen ([email protected])
  • http://phlippers.net/

Issues· 12 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Ruby

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言