{"id":20811297,"url":"https://github.com/express42/postgresql_lwrp","last_synced_at":"2025-05-07T09:26:13.841Z","repository":{"id":4450309,"uuid":"5588797","full_name":"express42/postgresql_lwrp","owner":"express42","description":"Express 42 postgresql cookbook","archived":false,"fork":false,"pushed_at":"2019-08-23T09:31:31.000Z","size":453,"stargazers_count":55,"open_issues_count":3,"forks_count":16,"subscribers_count":24,"default_branch":"master","last_synced_at":"2025-03-31T08:38:59.082Z","etag":null,"topics":["chef","cookbooks","postgres"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/express42.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-08-28T16:39:28.000Z","updated_at":"2024-08-31T01:57:24.000Z","dependencies_parsed_at":"2022-08-25T21:41:41.735Z","dependency_job_id":null,"html_url":"https://github.com/express42/postgresql_lwrp","commit_stats":null,"previous_names":[],"tags_count":35,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/express42%2Fpostgresql_lwrp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/express42%2Fpostgresql_lwrp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/express42%2Fpostgresql_lwrp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/express42%2Fpostgresql_lwrp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/express42","download_url":"https://codeload.github.com/express42/postgresql_lwrp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252849665,"owners_count":21813842,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chef","cookbooks","postgres"],"created_at":"2024-11-17T20:39:57.458Z","updated_at":"2025-05-07T09:26:13.809Z","avatar_url":"https://github.com/express42.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Chef cookbook](https://img.shields.io/cookbook/v/postgresql_lwrp.svg)](https://github.com/express42/postgresql_lwrp)\n[![Code Climate](https://codeclimate.com/github/express42/postgresql_lwrp/badges/gpa.svg)](https://codeclimate.com/github/express42/postgresql_lwrp)\n[![Build Status](https://travis-ci.org/express42/postgresql_lwrp.svg)](https://travis-ci.org/express42/postgresql_lwrp)\n\nDescription\n===========\nThis 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 \u0026 10.\n\nSupported platforms:\n\n* Debian 8\n* Debian 9\n* Ubuntu 14.04\n* Ubuntu 16.04\n* Ubuntu 18.04\n\n*Note: TravisCI tests for Ubuntu 18.04 are omitted now because they somehow hang. Local Vagrant \u0026 Docker-based tests are succesfull. This will be investigated further.*\n\nChangelog\n=========\nSee [CHANGELOG.md](https://github.com/express42/postgresql_lwrp/blob/master/CHANGELOG.md)\n\nRequirements\n============\n\nThe 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\n\nDependencies\n============\n\n* apt\n* cron\n* poise-python\n\nAttributes\n==========\nThis cookbook have server and client attribute files.\n\nWith client attributes([\"postgresql\"][\"client\"]) you can set only postgresql client and library version.\n\nServer 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.\n\nResources/Providers\n===================\n\n### Resource: default\n\n#### Actions\n\n- :create: creates postgresql cluster\n\n#### Resource parameters\n\n- 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 ('-').\n- cluster_version: set cluster version\n- cookbook: cookbook for templates. Skip this for default templates.\n- cluster_create_options: options for pg_createcluster (only locale related options)\n- configuration: Hash with configuration options for postgresql, see examples.\n- hba_configuration: Array with hba configuration, see examples.\n- ident_configuration: Array with ident configuration, see examples.\n- replication: Hash with replication configuration. See replication example.\n- replication_initial_copy: Boolean. If `true` pg_basebackup will be exec to make initial replication copy. Default is `false`.\n- replication_start_slave: Boolean. If `true` slave cluster will be started after creation. Should be used with replication_initial_copy option. Default `false`.\n- 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`.\n\n\nOther\n=====\n### Cloud backup helper:\n\n`postgresql_cloud_backup_helper.sh` helper can be found at `/opt/wal-e/bin/`.\n\n#### Usage:\n\n`postgresql_cloud_backup_helper.sh \u003ccluster_name\u003e \u003ccluster_version\u003e last|count`\n\n- `cluster_name` – postgresql cluster name (ex. *main*)\n- `cluser_version` – postgresql cluser version (ex. 9.3)\n- `last` – shows last backup time\n- `count` – shows total number of backups.\n\nExamples\n========\nExample master database setup:\n\n```ruby\npostgresql 'main' do\n  cluster_version '9.3'\n  cluster_create_options( locale: 'ru_RU.UTF-8' )\n  configuration(\n      listen_addresses:           '192.168.0.2',\n      max_connections:            300,\n      ssl_renegotiation_limit:    0,\n      shared_buffers:             '512MB',\n      maintenance_work_mem:       '64MB',\n      work_mem:                   '8MB',\n      log_min_duration_statement: 200\n  )\n  hba_configuration(\n    [\n      { type: 'host', database: 'all', user: 'all', address: '192.168.0.0/24', method: 'md5' },\n      { type: 'host', database: 'replication', user: 'postgres', address: '192.168.0.3/32', method: 'trust' }\n    ]\n  )\nend\n```\n\nExample slave database setup:\n\n```ruby\npostgresql 'main' do\n   cluster_version '9.3'\n  cluster_create_options( locale: 'ru_RU.UTF-8' )\n  configuration(\n      listen_addresses:           '192.168.0.3',\n      max_connections:            300,\n      ssl_renegotiation_limit:    0,\n      shared_buffers:             '512MB',\n      maintenance_work_mem:       '64MB',\n      work_mem:                   '8MB',\n      log_min_duration_statement: 200\n  )\n  hba_configuration(\n    [\n      { type: 'host', database: 'all', user: 'all', address: '192.168.0.0/24', method: 'md5' },\n      { type: 'host', database: 'replication', user: 'postgres', address: '192.168.0.2/32', method: 'trust' }\n    ]\n  )\n  replication(\n    standby_mode: 'on',\n    primary_conninfo: 'host=192.168.0.1',\n    trigger_file: '/tmp/pgtrigger'\n  )\n  replication_initial_copy true\n  replication_start_slave true\nend\n```\n\nExample slave configuration with replication slots (PostgreSQL \u003e= 9.4)\n\n```ruby\nreplication(\n  standby_mode: 'on',\n  primary_conninfo: 'host=192.168.0.1',\n  trigger_file: '/tmp/pgtrigger'\n  primary_slot_name: 'some_slot_on_master'\n)\n```\nDon't forget to create slot on master server before:\n\n```sql\n# SELECT pg_create_physical_replication_slot('some_slot_on_master');\n```\n\nExample users and databases setup\n\n```ruby\npostgresql_user 'user01' do\n  in_version '9.3'\n  in_cluster 'main'\n  unencrypted_password 'user01password'\nend\n\npostgresql_database 'database01' do\n  in_version '9.3'\n  in_cluster 'main'\n  owner 'user01'\nend\n```\n\nExample full daily database backup\n\n```ruby\npostgresql_cloud_backup 'main' do\n  utility 'wal-g'\n  in_version '9.3'\n  in_cluster 'main'\n  full_backup_time weekday: '*', month: '*', day: '*', hour: '3', minute: '0'\n  # Data bag item should contain following keys for S3 protocol:\n  # aws_access_key_id, aws_secret_access_key, wale_s3_prefix\n  parameters Chef::EncryptedDataBagItem.load('s3', 'secrets').to_hash.select {|i| i != \"id\"}\n  # Or just a hash, if you don't use data bags:\n  parameters { aws_access_key_id: 'access_key', aws_secret_access_key: 'secret_key', walg_s3_prefix: 's3_prefix' }\n  # In case you need to prepend wal-e with, for example, traffic limiter\n  # you can use following method:\n  command_prefix 'trickle -s -u 1024'\n  # It will be prepended to resulting wal-e execution in cron task\nend\n```\n\nExample usage of cloud backup helper usage\n\n```bash\n$ /opt/wal-e/bin/postgresql_cloud_backup_helper.sh main 9.3 last\n1428192159\n$ /opt/wal-e/bin/postgresql_cloud_backup_helper.sh main 9.3 count\n31\n```\n\nExample of how to install extensions from postgresql-contrib\nNOTE: schema and version are optional parameters, but others are required\n\n```ruby\npostgresql_extension 'cube' do\n  in_version '9.4'\n  in_cluster 'main'\n  db 'test01'\n  schema 'public'\nend\n```\nExample of how to install extensions from http://pgxn.org/\nNOTE: schema is an optional parameter, but others are required\n\n```ruby\npgxn_extension 'pg_lambda' do\n  in_version '9.4'\n  in_cluster 'main'\n  db 'test01'\n  version '1.0.2'\n  stage 'stable'\nend\n```\n\n\n# License and Maintainer\n\nMaintainer:: LLC Express 42 (\u003ccookbooks@express42.com\u003e)\nSource:: https://github.com/express42/postgresql_lwrp\nIssues:: https://github.com/express42/postgresql_lwrp/issues\n\nLicense:: MIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexpress42%2Fpostgresql_lwrp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fexpress42%2Fpostgresql_lwrp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexpress42%2Fpostgresql_lwrp/lists"}