Giter Club home page Giter Club logo

puppetlabs-postgresql's Introduction

postgresql

Table of Contents

  1. Module Description - What does the module do?
  2. Setup - The basics of getting started with postgresql module
  3. Usage - Configuration options and additional functionality
  4. Reference - An under-the-hood peek at what the module is doing and how
  5. Limitations - OS compatibility, etc.
  6. License
  7. Development - Guide for contributing to the module
  8. Tests
  9. Contributors - List of module contributors

Module description

The postgresql module allows you to manage PostgreSQL databases with Puppet.

PostgreSQL is a high-performance, free, open-source relational database server. The postgresql module allows you to manage packages, services, databases, users, and common security settings in PostgreSQL.

Setup

What postgresql affects

  • Package, service, and configuration files for PostgreSQL
  • Listened-to ports
  • IP and mask (optional)

Getting started with postgresql

To configure a basic default PostgreSQL server, declare the postgresql::server class.

class { 'postgresql::server':
}

Usage

Configure a server

For default settings, declare the postgresql::server class as above. To customize PostgreSQL server settings, specify the parameters you want to change:

class { 'postgresql::server':
  ip_mask_deny_postgres_user => '0.0.0.0/32',
  ip_mask_allow_all_users    => '0.0.0.0/0',
  ipv4acls                   => ['hostssl all johndoe 192.168.0.0/24 cert'],
  postgres_password          => 'TPSrep0rt!',
}

After configuration, test your settings from the command line:

psql -h localhost -U postgres
psql -h my.postgres.server -U

If you get an error message from these commands, your permission settings restrict access from the location you're trying to connect from. Depending on whether you want to allow connections from that location, you might need to adjust your permissions.

For more details about server configuration parameters, consult the PostgreSQL Runtime Configuration documentation.

Configure an instance

This module supports managing multiple instances (the default instance is referred to as 'main' and managed via including the server.pp class)

NOTE: This feature is currently tested on Centos 8 Streams/RHEL8 with DNF Modules enabled. Different Linux plattforms and/or the Postgresql.org packages distribute different Systemd service files or use wrapper scripts with Systemd to start Postgres. Additional adjustmentments are needed to get this working on these plattforms.

Working Plattforms

  • Centos 8 Streams
  • RHEL 8

Background and example

creating a new instance has the following advantages:

  • files are owned by the postgres user
  • instance is running under a different user, if the instance is hacked, the hacker has no access to the file system
  • the instance user can be an LDAP user, higher security because of central login monitoring, password policies, password rotation policies
  • main instance can be disabled

Here is a profile which can be used to create instaces

class profiles::postgres (
  Hash $instances = {},
  String $postgresql_version = '13',
) {
  class { 'postgresql::globals':
    encoding            => 'UTF-8',
    locale              => 'en_US.UTF-8',
    manage_package_repo => false,
    manage_dnf_module   => true,
    needs_initdb        => true,
    version             => $postgresql_version,
  }
  include postgresql::server

  $instances.each |String $instance, Hash $instance_settings| {
    postgresql::server_instance { $instance:
      *               => $instance_settings,
    }
  }
}

And here is data to create an instance called test1:

# stop default main instance
postgresql::server::service_ensure: "stopped"
postgresql::server::service_enable: false

#define an instance
profiles::postgres::instances:
  test1:
    instance_user: "ins_test1"
    instance_group: "ins_test1"
    instance_directories:
      "/opt/pgsql":
        ensure: directory
      "/opt/pgsql/backup":
        ensure: directory
      "/opt/pgsql/data":
        ensure: directory
      "/opt/pgsql/data/13":
        ensure: directory
      "/opt/pgsql/data/home":
        ensure: directory
      "/opt/pgsql/wal":
        ensure: directory
      "/opt/pgsql/log":
        ensure: directory
      "/opt/pgsql/log/13":
        ensure: directory
      "/opt/pgsql/log/13/test1":
        ensure: directory
    config_settings:
      pg_hba_conf_path: "/opt/pgsql/data/13/test1/pg_hba.conf"
      postgresql_conf_path: "/opt/pgsql/data/13/test1/postgresql.conf"
      pg_ident_conf_path: "/opt/pgsql/data/13/test1/pg_ident.conf"
      datadir: "/opt/pgsql/data/13/test1"
      service_name: "postgresql@13-test1"
      port: 5433
      pg_hba_conf_defaults: false
    service_settings:
      service_name: "postgresql@13-test1"
      service_status: "systemctl status [email protected]"
      service_ensure: "running"
      service_enable: true
    initdb_settings:
      auth_local: "peer"
      auth_host: "md5"
      needs_initdb: true
      datadir: "/opt/pgsql/data/13/test1"
      encoding: "UTF-8"
      lc_messages: "en_US.UTF8"
      locale: "en_US.UTF8"
      data_checksums: false
      group: "postgres"
      user: "postgres"
      username: "ins_test1"
    config_entries:
      authentication_timeout:
        value: "1min"
        comment: "a test"
      log_statement_stats:
        value: "off"
      autovacuum_vacuum_scale_factor:
        value: 0.3
    databases:
      testdb1:
        encoding: "UTF8"
        locale: "en_US.UTF8"
        owner: "dba_test1"
      testdb2:
        encoding: "UTF8"
        locale: "en_US.UTF8"
        owner: "dba_test1"
    roles:
      "ins_test1":
        superuser: true
        login: true
      "dba_test1":
        createdb: true
        login: true
      "app_test1":
        login: true
      "rep_test1":
        replication: true
        login: true
      "rou_test1":
        login: true
    pg_hba_rules:
      "local all INSTANCE user":
        type: "local"
        database: "all"
        user: "ins_test1"
        auth_method: "peer"
        order: 1
      "local all DB user":
        type: "local"
        database: "all"
        user: "dba_test1"
        auth_method: "peer"
        order: 2
      "local all APP user":
        type: "local"
        database: "all"
        user: "app_test1"
        auth_method: "peer"
        order: 3
      "local all READONLY user":
        type: "local"
        database: "all"
        user: "rou_test1"
        auth_method: "peer"
        order: 4
      "remote all INSTANCE user PGADMIN server":
        type: "host"
        database: "all"
        user: "ins_test1"
        address: "192.168.22.131/32"
        auth_method: "md5"
        order: 5
      "local replication INSTANCE user":
        type: "local"
        database: "replication"
        user: "ins_test1"
        auth_method: "peer"
        order: 6
      "local replication REPLICATION user":
        type: "local"
        database: "replication"
        user: "rep_test1"
        auth_method: "peer"
        order: 7

Create a database

You can set up a variety of PostgreSQL databases with the postgresql::server::db defined type. For instance, to set up a database for PuppetDB:

class { 'postgresql::server':
}

postgresql::server::db { 'mydatabasename':
  user     => 'mydatabaseuser',
  password => postgresql::postgresql_password('mydatabaseuser', 'mypassword'),
}

Manage users, roles, and permissions

To manage users, roles, and permissions:

class { 'postgresql::server':
}

postgresql::server::role { 'marmot':
  password_hash => postgresql::postgresql_password('marmot', 'mypasswd'),
}

postgresql::server::database_grant { 'test1':
  privilege => 'ALL',
  db        => 'test1',
  role      => 'marmot',
}

postgresql::server::table_grant { 'my_table of test2':
  privilege => 'ALL',
  table     => 'my_table',
  db        => 'test2',
  role      => 'marmot',
}

This example grants all privileges on the test1 database and on the my_table table of the test2 database to the specified user or group. After the values are added into the PuppetDB config file, this database would be ready for use.

Manage ownership of DB objects

To change the ownership of all objects within a database using REASSIGN OWNED:

postgresql::server::reassign_owned_by { 'new owner is meerkat':
  db       => 'test_db',
  old_role => 'marmot',
  new_role => 'meerkat',
}

This would run the PostgreSQL statement 'REASSIGN OWNED' to update to ownership of all tables, sequences, functions and views currently owned by the role 'marmot' to be owned by the role 'meerkat' instead.

This applies to objects within the nominated database, 'test_db' only.

For Postgresql >= 9.3, the ownership of the database is also updated.

Manage default permissions (PostgreSQL >= 9.6)

To change default permissions for newly created objects using ALTER DEFAULT PRIVILEGES:

postgresql::server::default_privileges { 'marmot access to new tables on test_db':
  db          => 'test_db',
  role        => 'marmot',
  privilege   => 'ALL',
  object_type => 'TABLES',
}

Override defaults

The postgresql::globals class allows you to configure the main settings for this module globally, so that other classes and defined resources can use them. By itself, it does nothing.

For example, to overwrite the default locale and encoding for all classes, use the following:

class { 'postgresql::globals':
  encoding => 'UTF-8',
  locale   => 'en_US.UTF-8',
}

class { 'postgresql::server':
}

To use a specific version of the PostgreSQL package:

class { 'postgresql::globals':
  manage_package_repo => true,
  version             => '9.2',
}

class { 'postgresql::server':
}

Manage remote users, roles, and permissions

Remote SQL objects are managed using the same Puppet resources as local SQL objects, along with a $connect_settings hash. This provides control over how Puppet connects to the remote Postgres instances and which version is used for generating SQL commands.

The connect_settings hash can contain environment variables to control Postgres client connections, such as 'PGHOST', 'PGPORT', 'PGPASSWORD', 'PGUSER' and 'PGSSLKEY'. See the PostgreSQL Environment Variables documentation for a complete list of variables.

Additionally, you can specify the target database version with the special value of 'DBVERSION'. If the $connect_settings hash is omitted or empty, then Puppet connects to the local PostgreSQL instance.

The $connect_settings hash has priority over the explicit variables like $port and $user

When a user provides only the $port parameter to a resource and no $connect_settings, $port will be used. When $connect_settings contains PGPORT and $port is set, $connect_settings['PGPORT'] will be used.

You can provide a connect_settings hash for each of the Puppet resources, or you can set a default connect_settings hash in postgresql::globals. Configuring connect_settings per resource allows SQL objects to be created on multiple databases by multiple users.

$connection_settings_super2 = {
  'PGUSER'     => 'super2',
  'PGPASSWORD' => 'foobar2',
  'PGHOST'     => '127.0.0.1',
  'PGPORT'     => '5432',
  'PGDATABASE' => 'postgres',
}

include postgresql::server

# Connect with no special settings, i.e domain sockets, user postgres
postgresql::server::role { 'super2':
  password_hash    => 'foobar2',
  superuser        => true,

  connect_settings => {},
}

# Now using this new user connect via TCP
postgresql::server::database { 'db1':
  connect_settings => $connection_settings_super2,
  require          => Postgresql::Server::Role['super2'],
}

Create an access rule for pg_hba.conf

To create an access rule for pg_hba.conf:

postgresql::server::pg_hba_rule { 'allow application network to access app database':
  description => 'Open up PostgreSQL for access from 200.1.2.0/24',
  type        => 'host',
  database    => 'app',
  user        => 'app',
  address     => '200.1.2.0/24',
  auth_method => 'md5',
}

This would create a ruleset in pg_hba.conf similar to:

# Rule Name: allow application network to access app database
# Description: Open up PostgreSQL for access from 200.1.2.0/24
# Order: 150
host  app  app  200.1.2.0/24  md5

By default, pg_hba_rule requires that you include postgresql::server. However, you can override that behavior by setting target and postgresql_version when declaring your rule. That might look like the following:

postgresql::server::pg_hba_rule { 'allow application network to access app database':
  description        => 'Open up postgresql for access from 200.1.2.0/24',
  type               => 'host',
  database           => 'app',
  user               => 'app',
  address            => '200.1.2.0/24',
  auth_method        => 'md5',
  target             => '/path/to/pg_hba.conf',
  postgresql_version => '9.4',
}

Create user name maps for pg_ident.conf

To create a user name map for the pg_ident.conf:

postgresql::server::pg_ident_rule { 'Map the SSL certificate of the backup server as a replication user':
  map_name          => 'sslrepli',
  system_username   => 'repli1.example.com',
  database_username => 'replication',
}

This would create a user name map in pg_ident.conf similar to:

#Rule Name: Map the SSL certificate of the backup server as a replication user
#Description: none
#Order: 150
sslrepli  repli1.example.com  replication

Create recovery configuration

To create the recovery configuration file (recovery.conf):

postgresql::server::recovery { 'Create a recovery.conf file with the following defined parameters':
  restore_command           => 'cp /mnt/server/archivedir/%f %p',
  archive_cleanup_command   => undef,
  recovery_end_command      => undef,
  recovery_target_name      => 'daily backup 2015-01-26',
  recovery_target_time      => '2015-02-08 22:39:00 EST',
  recovery_target_xid       => undef,
  recovery_target_inclusive => true,
  recovery_target           => 'immediate',
  recovery_target_timeline  => 'latest',
  pause_at_recovery_target  => true,
  standby_mode              => 'on',
  primary_conninfo          => 'host=localhost port=5432',
  primary_slot_name         => undef,
  trigger_file              => undef,
  recovery_min_apply_delay  => 0,
}

The above creates this recovery.conf config file:

restore_command = 'cp /mnt/server/archivedir/%f %p'
recovery_target_name = 'daily backup 2015-01-26'
recovery_target_time = '2015-02-08 22:39:00 EST'
recovery_target_inclusive = true
recovery_target = 'immediate'
recovery_target_timeline = 'latest'
pause_at_recovery_target = true
standby_mode = 'on'
primary_conninfo = 'host=localhost port=5432'
recovery_min_apply_delay = 0

Only the specified parameters are recognized in the template. The recovery.conf is only created if at least one parameter is set and manage_recovery_conf is set to true.

Validate connectivity

To validate client connections to a remote PostgreSQL database before starting dependent tasks, use the postgresql_conn_validator resource. You can use this on any node where the PostgreSQL client software is installed. It is often chained to other tasks such as starting an application server or performing a database migration.

Example usage:

postgresql_conn_validator { 'validate my postgres connection':
  host              => 'my.postgres.host',
  db_username       => 'mydbuser',
  db_password       => 'mydbpassword',
  db_name           => 'mydbname',
  psql_path         => '/usr/bin/psql',
}
-> exec { 'rake db:migrate':
  cwd => '/opt/myrubyapp',
}

Backups

This example demonstrates how to configure PostgreSQL backups with "pg_dump". This sets up a daily cron job to perform a full backup. Each backup will create a new directory. A cleanup job will automatically remove backups that are older than 15 days.

class { 'postgresql::server':
  backup_enable   => true,
  backup_provider => 'pg_dump',
  backup_options  => {
    db_user     => 'backupuser',
    db_password => 'secret',
    manage_user => true,
    rotate      => 15,
  },
  ...
}

It is possible to set parameter $ensure to absent in order to remove the backup job, user/role, backup script and password file. However, the actual backup files and directories will remain untouched.

Reference

For information on the classes and types, see the REFERENCE.md

Limitations

Works with versions of PostgreSQL on supported OSes.

For an extensive list of supported operating systems, see metadata.json

Apt module support

While this module supports both 1.x and 2.x versions of the 'puppetlabs-apt' module, it does not support 'puppetlabs-apt' 2.0.0 or 2.0.1.

PostGIS support

PostGIS is currently considered an unsupported feature, as it doesn't work on all platforms correctly.

All versions of RHEL/CentOS with manage_selinux => false

If you have SELinux enabled and you are not using the selinux module to manage SELinux (this is the default configuration) you will need to label any custom ports you use with the postgresql_port_t context. The postgresql service will not start until this is done. To label a port use the semanage command as follows:

semanage port -a -t postgresql_port_t -p tcp $customport

License

This codebase is licensed under the Apache2.0 licensing, however due to the nature of the codebase the open source dependencies may also use a combination of AGPL, BSD-2, BSD-3, GPL2.0, LGPL, MIT and MPL Licensing.

Development

Puppet Labs modules on the Puppet Forge are open projects, and community contributions are essential for keeping them great. We can’t access the huge number of platforms and myriad hardware, software, and deployment configurations that Puppet is intended to serve. We want to keep it as easy as possible to contribute changes so that our modules work in your environment. There are a few guidelines that we need contributors to follow so that we can have a chance of keeping on top of things. For more information, see our module contribution guide.

Tests

There are two types of tests distributed with this module. Unit tests with rspec-puppet and system tests using rspec-system.

For unit testing, make sure you have:

  • rake
  • bundler

Install the necessary gems:

bundle install --path=vendor

And then run the unit tests:

bundle exec rake spec

To run the system tests, make sure you also have:

  • Vagrant > 1.2.x
  • VirtualBox > 4.2.10

Then run the tests using:

bundle exec rspec spec/acceptance

To run the tests on different operating systems, see the sets available in .nodeset.yml and run the specific set with the following syntax:

RSPEC_SET=debian-607-x64 bundle exec rspec spec/acceptance

Contributors

View the full list of contributors on Github.

puppetlabs-postgresql's People

Contributors

bastelfreak avatar blackknight36 avatar bmjen avatar chelnak avatar cmurphy avatar cprice404 avatar daianamezdrea avatar david22swan avatar davids avatar eimlav avatar ekohl avatar eputnam avatar hasegeli avatar hunner avatar jonnytdevops avatar jordanbreen28 avatar kamilszymanski avatar kbarber avatar kennknowles avatar lionce avatar lukasaud avatar malikparvez avatar mcanevet avatar pmcmaw avatar ramesh7 avatar sanfrancrisko avatar sheenaajay avatar simonhoenscheid avatar smortex avatar tphoney avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

puppetlabs-postgresql's Issues

Simple support for switching to a different postgres version

I believe that at the time being, if you'd like to switch to a different version of postgres (e.g. from 8.4 to 9.1), you probably need to override a bunch of different path variables in your manifest. It would be nice to have a simple catch-all version-number setting, which would automatically handle the logic of switching all of the path variables.

A few typos

Opened the module in the Geppetto editor and a few errors popped up right away.

In config.pp on lines 33 and 34. The referenced variables from ::params do not exist. Line 33 seems to be missing "deny" and 34 seems to be missing "allow".
$ip_mask_deny_postgres_user = $postgresql::params::ip_mask_postgres_user
$ip_mask_allow_all_users = $postgresql::params::ip_mask_all_users

In psql.pp on line 45, $quoted_$unless has an extra dollar sign. It should be $quoted_unless.

"CONNECT" privilege doesn't exist in pg 8.1

When creating a database on postgres 8.1 using the module, you will get this error:

Error: /Stage[main]/Puppetdb::Database::Postgresql/Postgresql::Db[puppetdb]/Postgresql::Database[puppetdb]/Postgresql_psql[REVOKE CONNECT ON DATABASE puppetdb FROM public]: Failed to call refresh: Error executing SQL; psql returned 256: 'ERROR:  unrecognized privilege type "connect"                                                                                     

'

Since this doesn't actually prevent the database from being created, subsequent runs will succeed even though this run failed... but we need to put an if statement around this such that it either does 'REVOKE ALL' or it doesn't revoke anything.

How to set user created in postgresql::db as superuser?

I made databases named matt_dev and matt_test and I want to set up a postgresql user named matt, and I want matt to be a superuser.

Not sure how to do this! Here's what I tried:

postgresql::db { ['matt_dev', 'matt_test']:
user => 'matt',
password => 'PASSWORD',
before => Postgresql::Role['matt'],
}

postgresql::role { 'matt':
password_hash => postgresql_password('matt', 'PASSWORD'),
superuser => true,
}

I get a Duplicate Resource error because the postgresql::db resource seems to set up a matt role already.

I need to set up the matt user as a superuser!

What's the solution?

Proper quoting of database names in various psql calls

Database names should be properly quoted when using psql calls for granting, revoking or creating databases, so that database names starting with, for example, a digit, don't trip up the underlying psql command.

I've submitted a PR about this in three months ago, and it got merged (c4147a4), but my changes were overwritten by a subsequent commit.

If no one beats me to it I'll submit a new PR regarding this, but probably not today.

Must pass an array to execute()

This is one of two errors I've received on current master. Commit 8bb71e4

The first is a simple syntax error see. #55

The other is the following error message which I'm not sure how to interpret.

err: /Stage[main]/Redmine::Db/Postgresql::Db[redmine]/Postgresql::Database[redmine]/Postgresql_psql[Check for existence of db 'redmine']: Could not evaluate: Must pass an array to execute()

This is in part of a redmine module I am working on but the source that causes this is.

postgresql::db { "${db_name}":
  user     => "${db_user}",
  password => "${db_password}",
}

Everything works fine in commit 32b65b8

RPM GPG Key is not imported

the RPM GPG Key is only placed in /etc/pki/rpm-gpg/.. but not imported leading to problems with Spacewalk for instance which expects it to be imported already.

Needs to be addressed differently for RHEL/debian. I only have a working patch for RHEL

Support reloading the postgresql service after changes to pg_hba.conf

When changes are made to pg_hba.conf by means of config_hash the postgresql service gets restarted. This is potentially dangerous since clients get disconnected, possibly while currently reading or writing to the database, which can cause errors in the applications accessing the database.

PostgreSQL supports reloading the cluster for this very reason (pg_ctl reload). Very few changes to the configuration actually require a full restart. For most a reload is perfectly fine.

This module should support a way to reload the cluster for configuration changes, instead of restarting it.

The camptocamp postgres module uses a defined type and Augeas for managing the pg_hba.conf file and execs something like /etc/init.d/postgresql reload. Perhaps this is a viable alternative to the config_hash method of this module.

Does this module have a dependency on the concat module?

I kept getting this error:

err: Could not retrieve catalog from remote server: Error 400 on SERVER: Puppet::Parser::AST::Resource failed with error ArgumentError: Invalid resource type concat at /etc/puppet/modules/postgresql/manifests/pg_hba.pp:16 on node example.com

I resolved it by installing ripienaar/concat (since the line in question called the concat resource instead of the Concat::Fragement resource in the official puppet docs).

If there is a dependency, could it be documented somewhere?

Using Augeas

Hi,

I thought I'd open an issue here to discuss whether and how to use Augeas for managing postgresql.conf and pg_hba.conf.

Augeas 1.0.0 has been released recently and I know that packages are available at least for Ubuntu from @raphink's PPA (https://launchpad.net/~raphink/+archive/augeas). Ubuntu 13.04 will have official Augeas 1.0.0 packages. I don't know how support looks on RHEL or other systems.

Augeas 1.0.0 now has extended lenses for both postgresql.conf and pg_hba.conf which look pretty good to me, but I have yet to test them thoroughly with Puppet. So I wonder: is it worthwhile to pursue using Augeas to manage these important files, or are people happier with the current template-based approach and the ideas for postgresql.conf discussed in issue #26 (I wanted to take a crack at this, but haven't had the time yet, unfortunately)?

The advantages or Augeas are, in my opinion, clear: no need for complex template constructs, we get syntax checks and support for all settings in postgresql.conf and also for all kinds of ACLs in pg_hba.conf without having to expose specific ACL types to the user and hiding or not supporting others (ipv4acls/ipv6acls vs unixacls, see PR #72). Using Augeas from within Puppet is easy enough, although in the end there might again be need for some kind of template/eruby hackery.

One thing to consider is that Augeas 1.0.0 will probably not be available on most systems for quite some time so Augeas support in this module should only be used if facter augeasversion >= 1.0.0. For earlier versions the template approach for pg_hba.conf and file_line for postgresql.conf (issue #26) will remain the only option.

Another thing to consider is that Augeas can significantly slow down a Puppet run if it manages many configuration settings.

And of course, as @jhoblitt has pointed out in PR #72 Augeas only manages specified settings, so manual edits to the configuration are, by design, still possible and not caught by Puppet.

So it might be necessary for the module user to be able to decide whether he wants to use Augeas or not.

One or two new types will probably have to be defined, such as postgresql::server::conf (manages a setting in postgresql.conf) and postgresql::server::hba (manages an ACL in pg_hba.conf).

This could lead to something like this:

postgresql::server::conf { 
  'listen_addresses': value => '*';
  'port':             value => '5432';
  'max_connections':  value => '500';
}

And for pg_hba.conf the @camptocamp guys have already defined an IMHO reasonable type for ACLs, which would look somewhat like this:

postgresl::server::hba { 'access to some database for alice':
  ensure => present,
  type => 'host',
  database => 'some',
  user => 'alice',
  address => '10.0.0.0/16',
  method => 'md5',
}

But there would probably have to be a way to abstract and hide these declarations, or they would clutter up the user's manifests since they are a bit more verbose (and thus ugly) than the current config_hash approach.

Sorry for this lengthy braindump. Maybe someone has some comments or ideas, I'd love to hear them. I hope I find the time to test and experiment with this myself in the coming weeks.

pg_hba local access problem

Can't add local access to pg_hba, like:
local all postgres trust

with:

class { 'postgresql::server':
config_hash => {
'listen_addresses' => '*',
'ipv4acls' => ['local all postgres trust'],
},
}

The problem is comming from missing CIDR parameter, which isn't needed with local type.

Database Checks Don't Work In /root

I have the following statements:

    include postgresql::server
    postgresql::db { "weight":
        user     => "weight",
        password => "foobar",
    }

    postgresql::pg_hba_rule { "Turn password authentication on for local inet users.":
        type        => "host",
        database    => "all",
        user        => "all",
        address     => "127.0.0.0/8",
        auth_method => "md5",
    }

    postgresql::pg_hba_rule { "Turn password authentication on for local socket users.":
        type        => "local",
        database    => "all",
        user        => "all",
        auth_method => "md5",
    }

When in /root, I get the following the second time I run it:

Info: Applying configuration version '1362334951'
Notice: /Stage[main]/Weightgrapher::Dev/Postgresql::Db[weight]/Postgresql::Database[weight]/Postgresql_psql[Check for existence of db 'weight']/command: command changed '' to 'SELECT 1'
Info: /Stage[main]/Weightgrapher::Dev/Postgresql::Db[weight]/Postgresql::Database[weight]/Postgresql_psql[Check for existence of db 'weight']: Scheduling refresh of Exec[/usr/lib/postgresql/8.4/bin/createdb --template=template0 --encoding 'UTF8'  'weight']
Notice: /Stage[main]/Weightgrapher::Dev/Postgresql::Db[weight]/Postgresql::Database[weight]/Exec[/usr/lib/postgresql/8.4/bin/createdb --template=template0 --encoding 'UTF8'  'weight']/returns: could not change directory to "/root"
Notice: /Stage[main]/Weightgrapher::Dev/Postgresql::Db[weight]/Postgresql::Database[weight]/Exec[/usr/lib/postgresql/8.4/bin/createdb --template=template0 --encoding 'UTF8'  'weight']/returns: createdb: database creation failed: ERROR:  database "weight" already exists
Error: /Stage[main]/Weightgrapher::Dev/Postgresql::Db[weight]/Postgresql::Database[weight]/Exec[/usr/lib/postgresql/8.4/bin/createdb --template=template0 --encoding 'UTF8'  'weight']: Failed to call refresh: /usr/lib/postgresql/8.4/bin/createdb --template=template0 --encoding 'UTF8'  'weight' returned 1 instead of one of [0]
Error: /Stage[main]/Weightgrapher::Dev/Postgresql::Db[weight]/Postgresql::Database[weight]/Exec[/usr/lib/postgresql/8.4/bin/createdb --template=template0 --encoding 'UTF8'  'weight']: /usr/lib/postgresql/8.4/bin/createdb --template=template0 --encoding 'UTF8'  'weight' returned 1 instead of one of [0]
Error: Error executing SQL; psql returned 256: 'could not change directory to "/root"
ERROR:  role "weight" already exists
'
Error: /Stage[main]/Weightgrapher::Dev/Postgresql::Db[weight]/Postgresql::Database_user[weight]/Postgresql::Role[weight]/Postgresql_psql[CREATE ROLE "weight" ENCRYPTED PASSWORD '1YpTq^Bg25JKrIa$' LOGIN NOCREATEROLE NOCREATEDB NOSUPERUSER  CONNECTION LIMIT -1]/command: change from  to CREATE ROLE "weight" ENCRYPTED PASSWORD 'foobar' LOGIN NOCREATEROLE NOCREATEDB NOSUPERUSER  CONNECTION LIMIT -1 failed: Error executing SQL; psql returned 256: 'could not change directory to "/root"
ERROR:  role "weight" already exists
'
Notice: /Stage[main]/Weightgrapher::Dev/Postgresql::Db[weight]/Postgresql::Database_grant[GRANT weight - ALL - weight]/Postgresql_psql[GRANT ALL ON database "weight" TO "weight"]: Dependency Postgresql_psql[CREATE ROLE "weight" ENCRYPTED PASSWORD 'foobar' LOGIN NOCREATEROLE NOCREATEDB NOSUPERUSER  CONNECTION LIMIT -1] has failures: true
Warning: /Stage[main]/Weightgrapher::Dev/Postgresql::Db[weight]/Postgresql::Database_grant[GRANT weight - ALL - weight]/Postgresql_psql[GRANT ALL ON database "weight" TO "weight"]: Skipping because of failed dependencies
Notice: Finished catalog run in 1.05 seconds

When running in any other directory, no errors are encountered. This may be related to switching to the postgres user without resetting the environment as outlined here: http://www.postgresql.org/message-id/[email protected]

afterservice::set_postgres_postgrespw runs every time

I am not sure why but the unless call fails and at every puppet run the password is set again:

Debug: Exec[set_postgres_postgrespw](provider=posix): Executing check 'env PGPASSWORD="xxx" psql -h localhost
-c 'select 1' > /dev/null'
Debug: Executing 'env PGPASSWORD="xxx" psql -h localhost -c 'select 1' > /dev/null'
Debug: /Stage[main]/Postgresql::Config::Afterservice/Exec[set_postgres_postgrespw]/unless: psql: FATAL:  pg_hba.conf rejects connection for host "127.0.0.1", user "postgres", database "postgres", SSL on
Debug: /Stage[main]/Postgresql::Config::Afterservice/Exec[set_postgres_postgrespw]/unless: FATAL:  pg_hba.conf rejects connection for host "127.0.0.1", user "postgres", database "postgres", SSL off
Debug: Exec[set_postgres_postgrespw](provider=posix): Executing 'psql -c "ALTER ROLE postgres PASSWORD 'xxx'"'
Debug: Executing 'psql -c "ALTER ROLE postgres PASSWORD 'xxx'"'
Notice: /Stage[main]/Postgresql::Config::Afterservice/Exec[set_postgres_postgrespw]/returns: ALTER ROLE
Notice: /Stage[main]/Postgresql::Config::Afterservice/Exec[set_postgres_postgrespw]/returns: executed successfully

It does hint at pg_hba.conf not being configured properly, but I did not provide any configuration for this in my postgresql::server entry, since I expected the defaults to work out of the box.

Provide more custom parameters for custom packaging

(This ticket tracks the intentions of #106, but finishes the job.)

We want to add more parameters to the module to allow the overriding of the options:

  • client package name
  • server package name
  • development package name
  • data directory
  • binary directory
  • service name
  • postgresql user
  • postgresql group
  • force initdb
  • service status check (subsumes #76)

This will allow those who use non-standard postgresql packaging to override the defaults.

Weird error with postgresql::db

I get this since I updated to latest master (from 2.0.something)

Error: /Stage[main]//Node[server]/Postgresql_psql[GRANT CONNECT ON DATABASE foo TO user]: Could not evaluate: Error evaluating 'unless' clause: 'ERROR:  server "foo" does not exist

It seems that this is triggering it:

    postgresql::db { ['foo', 'bar']:
        user => 'user',
        password => postgresql_password('user', 'pwd'),
    }

This worked fine before, but now my puppet config just won't run through anymore. Looking at the error, it seems to be trying to connect to a server that has the name of the database, it's kinda weird.

"-e" at the start of pg_hba.conf

Hi,

Just started testing this postgres module, with a simple config:
class { 'postgresql::server': }

However postgres cannot start and starting it manually give:
/etc/init.d/postgresql start

  • Starting PostgreSQL 9.1 database server * The PostgreSQL server failed to start. Please check the log output:
    2013-03-13 15:25:22 CET LOG: invalid connection type "-e"
    2013-03-13 15:25:22 CET CONTEXT: line 1 of configuration file "/etc/postgresql/9.1/main/pg_hba.conf"
    2013-03-13 15:25:22 CET FATAL: could not load pg_hba.conf

Looking at /etc/postgresql/9.1/main/pg_hba.conf, the first line is:
-e # This file is managed by Puppet. DO NOT EDIT.

Note the "-e".
Removing that "-e" allows the startup files to work correctly.

I did go looking in the source and manifests/pg_hba_rule.pp calls concat, but the proble is not obvious to me.

Environment: Ubuntu 12.04 with puppet master 3.0.2, client 2.7.11. postgres and concat packages pulled from puppetlabs github.

postgresql::database doesn't require postgresql-server

Ends up that postgresql::database might run before the package is installed. This quick patch seems to fix it:

diff --git a/puppet/modules/postgresql/manifests/database.pp b/puppet/modules/postgresql/manifests/database.pp
index 560dc9d..a36fffd 100644
--- a/puppet/modules/postgresql/manifests/database.pp
+++ b/puppet/modules/postgresql/manifests/database.pp
@@ -35,6 +35,7 @@ define postgresql::database(
     command => "SELECT 1",
     unless  => "SELECT datname FROM pg_database WHERE datname='$dbname'",
     cwd     => $postgresql::params::datadir,
+    require => Package['postgresql-server'],
   } ~>

   exec { $createdb_command :

Port psql type from Exec to ruby

Right now, the psql resource type is implemented using Puppet Exec instances. This works fine, but it limits our control over logging, handling system exit codes, etc. It would be extremely valuable to port at least this one resource type over to Ruby to give us more fine-grained control over things.

Definition tries to inherit params class

The postgresql::validate_db_connection definition (in validate_db_connection.pp) tries to inherit postgresql::params but, if I'm not mistaken, definitions cannot inherit.

Failure with puppet 3.0.2

I get an error when loading the postgresql::server class:

Info: Retrieving plugin
Debug: file_metadata supports formats: b64_zlib_yaml pson raw yaml; using pson
Debug: Finishing transaction 11992540
Info: Loading facts in /var/lib/puppet/lib/facter/iptables.rb
Info: Loading facts in /var/lib/puppet/lib/facter/facter_dot_d.rb
Info: Loading facts in /var/lib/puppet/lib/facter/puppet_vardir.rb
Info: Loading facts in /var/lib/puppet/lib/facter/root_home.rb
Info: Loading facts in /var/lib/puppet/lib/facter/pe_version.rb
Info: Loading facts in /var/lib/puppet/lib/facter/postgres_default_version.rb
Debug: catalog supports formats: b64_zlib_yaml dot pson raw yaml; using pson
Error: Could not retrieve catalog from remote server: Could not intern from pson: Invalid tag "[\"postgresql::config\"]"

ALL postgresql.conf options should be puppeted

In postgresql.conf, there's a number of settings (ssl, max_connections, data_directory,...) that need to be changed in our environment, but the only one that can be puppeted is listen_addresses, which is done through the (non-scalable) file_line in beforeservice.pp.

How should adding on to the changeable options for postgresql.conf be handled?

postgres_default_version fact fails if no repos are enabled.

The postgres_default_version fact scrapes the output of yum info to determine the default version of postgres on the system such as Centos. This code assumes that this command will return output and will fail if no repos are enabled.

This can cause issues for modules such as puppetdb. The puppetdb module for instance will return:

err: Could not retrieve catalog from remote server: Error 400 on SERVER:
 No value for postgres_default_version facter fact;
it's possible that you don't have pluginsync enabled. at /etc/puppetlabs/puppet/modules/postgresql/manifests/params.pp:29 on node classroom.puppetlabs.vm

When using a class such as puppetd that depends on this module.

Further as pluginsync copies this fact out, you will receive an error during every run on systems that would not not ever need postgresql-server installed on them , such as those that would be using puppetdb::master::config.

info: Loading facts in /var/opt/lib/pe-puppet/lib/facter/puppet_vardir.rb
info: Loading facts in /var/opt/lib/pe-puppet/lib/facter/virtual.rb
info: Loading facts in /var/opt/lib/pe-puppet/lib/facter/root_home.rb
info: Loading facts in /var/opt/lib/pe-puppet/lib/facter/concat_basedir.rb
info: Loading facts in /var/opt/lib/pe-puppet/lib/facter/iptables.rb
info: Loading facts in /var/opt/lib/pe-puppet/lib/facter/postgres_default_version.rb
Error: No matching Packages to list
Error: No matching Packages to list
Error: No matching Packages to list

Require postgresql service to run initdb.

The initdb exec does not require the postgresql-server package. Therefore, a installation may fail when the initdb is attempted before the install of the postgresql-server package.

Using database::grant doesn't grant permissions on tables

Using database::grant doesn't seem to grant the specified role permissions to the database's tables, even when using privilege => 'ALL'. Using this:

postgresql::database_grant { 'foo_all_bar':
  privilege => 'ALL',
  db        => 'bar',
  role      => 'foo',
}

I still had to do the following manually in the "bar" database:

GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO foo;

This is on Postgres 9.1 in Ubuntu 12.04.

Set owner of database

It would be great if there's a way to create a DB and directly set the owner. Currently it seems the user assigned to the DB isn't the owner.

Support advanced tuning settings

Patrick Carlisle suggested that it would be valuable for the module to expose parameters for some of the more potent and commonly used performance tuning settings for postgres. Notes below...


It would be good for the module to help you configure the system for some reasonable settings. Default postgres config is for a machine from around 1992. It would be cool if it were easy to scale these based on a machine's total memory.

shared_buffers => maybe 1/4 ram

To be able to turn this up you have to modify SHMMAX with sysctl, so you have to manage sysctl.conf on most systems. This is a painful surprise to every new postgres user so even though it's a pain it would be really good to have in the module.

work_mem => hard to say a default for this because it's dependent on how many concurrent users you expect

effective_cache_size => 1/2 to 2/3 of available ram

other common settings to weak include:
wal_buffers (8mb?)
checkpoint_segments (probably 16)
maintenance_work_mem (256mb)

Some of these suggested defaults i took from experience, the rest from http://www.pgexperts.com/document.html?id=36

The standard postgres docs also have useful discussion and suggestions for all of these settings.

bindir is incorrect for RHEL5 postgresql84 package

We got a report from @timdenike on issue #95 that we're not determining the correct bindir for the postgresql84 package on RHEL5. Users will be able to work around this by overriding parameters once the issues around #95 are resolved, but my opinion is that we should also fix the case statements in params.pp to automatically support the RHEL5/postgresql84 combination without requiring users to override the params at all.

@timdenike is the package you're using coming from the default RHEL5 package repo? or EPEL? Or yum.postgresql.org?

Installation on amazon linux ami puppet agent fails

(I am not sure the linux ami actually has anything to do with this problem) When I update my puppet agents from the puppetmaster, I get the following error:

err: /Stage[main]/Postgresql::Config::Beforeservice/Postgresql::Pg_hba[main]/Concat[/var/lib/pgsql/data/pg_hba.conf]/File[/var/lib/pgsql/data/pg_hba.conf]: Could not evaluate: Could not retrieve information from environment production source(s) file:/var/lib/puppet/concat/_var_lib_pgsql_data_pg_hba.conf/fragments.concat.out at /etc/puppet/modules/concat/manifests/init.pp:228

Any ideas what this means?

Thanks!

(full output gist of `puppet agent -t --noop --verbose --trace here: https://gist.github.com/geetotes/c58bc3afee958d29aa70 )

Fix authentication method for unix socket

Authentication should be performed via md5 instead of ident, in order to fix some login trouble:

vagrant@precise32:~$ psql -U postgres
psql: FATAL:  Peer authentication failed for user "postgres"
vagrant@precise32:~$ grep ^local /etc/postgresql/9.1/main/pg_hba.conf
local   all         postgres                          ident
local   all         all                               ident
vagrant@precise32:~$ sudo vim /etc/postgresql/9.1/main/pg_hba.conf
# ...
vagrant@precise32:~$ grep ^local /etc/postgresql/9.1/main/pg_hba.conf
local   all         postgres                          md5
local   all         all                               md5
vagrant@precise32:~$ sudo killall -HUP postgres
vagrant@precise32:~$ psql -U postgres
Password for user postgres:

Installation downgraded stdlib

Looks like postgresql requires stdlib 2.x. I had 3.x installed, so it was downgraded. Is there a specific feature of 2.x that broke in 3.x? If so, could that be documented in the Modulefile as to why?

Latest version (2.0.1) on the Forge doesn't have the Debian-7.0 patch in it

Commit 5e47aff made this module work on Debian 7.0 (Wheezy) boxes that were updated after 2012-12-12. However, installing the module from the forge doesn't get that update, leading to a ~30 line error message when trying to use it. Any chance I can get a version bump on the forge to make this module work? If I read it correctly, that fix was before the 2.0.1 release, but somehow hasn't made it onto my machine where I've installed it (using 'puppet module install').

postgresql::grant doesn't exist

Contrary to what the README states.

Why not just interpolate the type from the docs into the string that checks if the permission exists in what I can only assume was renamed to database_grant?

Unsupported 'include' directive gets added to Postgresql 8.1

Hi all,
I’m quite new here and I hope i’m on the right place… I’m trying to install a puppet platform with puppetdb and I had some succes until today to install it correctly. Issue is that from today the puppetdb installation via module no longer functions :
Error: Could not start Service[postgresqld]: Execution of ‘/sbin/service postgresql start’ returned 1:
Within the postgres log => FATAL: unrecognized configuration parameter “include”
I removed the include line within postgres.conf and I am able to start postgres process. But if I apply puppet catalog again (to install puppetdb via module) it does reinsert the include…
Regards

Run system tests in CI

The spec (really more like acceptance or integration) tests need to be automated... not sure if we should do that with Travis or elsewhere, but it definitely needs to happen. This is the stuff under:

rake spec:system

Examples of how to use a non-default version of postgres

It would be nice to have some example manifests in the "tests" directory which demonstrated how to use a non-default version of postgres. So, e.g., on CentOS6, the default is postgres 8.4. However, if you add the postgres RPM package repos, you can install postgres 9.1. The module supports this but we don't illustrate how you'd go about configuring your setup to take advantage of it.

Invalid parameter psql_path

Just installed version from git (572f090a1d) and I'm getting this error:

Invalid parameter psql_path at /etc/puppet/modules/postgresql/manifests/database.pp:63 

Module only includes GPG key for postgres 9.2 in yum.postgresql.org

In pull req #43 we added initial support for using non-system-default versions of postgres. Part of that changeset included support for managing the yumrepo resource for yum.postgresql.org.

However, the class that manages that also needs to deploy the GPG key, and the module currently only provides a GPG key for postgres 9.2. Therefore if you try to use this feature with other versions of postgres, it will fail due to the missing GPG key.

It's possible that yum.postgresql.org uses the same GPG key for all of the versions, which would make it very easy to fix this. If there are different GPG keys for the different versions, though, then we will need to add a copy of each of them to the module.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.