Browse files

Optionally install contrib module extensions listed in attribute.

  • Loading branch information...
1 parent b9e4e15 commit ecf7a1d33c20e5652263205eddf949c8bc149c3f @davidc-donorschoose davidc-donorschoose committed Feb 24, 2013
Showing with 43 additions and 5 deletions.
  1. +28 −5
  2. +15 −0 recipes/contrib.rb
@@ -294,11 +294,34 @@ contrib
Installs the packages defined in the
-`node['postgresql']['contrib']['packages']` attribute.
-This is the contrib directory of the PostgreSQL distribution, which
-includes porting tools, analysis utilities, and plug-in features that
-database engineers often require. Some (like pgbench) are executable.
-Others (like pg_buffercache) should be installed into the database.
+`node['postgresql']['contrib']['packages']` attribute. The contrib
+directory of the PostgreSQL distribution includes porting tools,
+analysis utilities, and plug-in features that database engineers often
+require. Some (like `pgbench`) are executable. Others (like
+`pg_buffercache`) would need to be installed into the database.
+Also installs any contrib module extensions defined in the
+`node['postgresql']['contrib']['extensions']` attribute. These will be
+available in any subsequently created databases in the cluster, because
+they will be installed into the `template1` database using the
+`CREATE EXTENSION` command. For example, it is often necessary/helpful
+for problem troubleshooting and maintenance planning to install the
+views and functions in these [standard instrumentation extensions]
+ node['postgresql']['contrib']['extensions'] = [
+ "pageinspect",
+ "pg_buffercache",
+ "pg_freespacemap",
+ "pgrowlocks",
+ "pg_stat_statements",
+ "pgstattuple"
+ ]
+Note that the `pg_stat_statements` view only works if `postgresql.conf`
+loads its shared library, which can be done with this node attribute:
+ node['postgresql']['config']['shared_preload_libraries'] = 'pg_stat_statements'
@@ -17,8 +17,23 @@
include_recipe "postgresql::server"
+# Install the PostgreSQL contrib package(s) from the distribution,
+# as specified by the node attributes.
node['postgresql']['contrib']['packages'].each do |pg_pack|
package pg_pack
+# Install PostgreSQL contrib extentions into the template1 database,
+# as specified by the node attributes.
+if (node['postgresql']['contrib'].attribute?('extensions'))
+ node['postgresql']['contrib']['extensions'].each do |pg_ext|
+ execute "#{pg_ext} extension on template1" do
+ command <<-EOC
+ sudo -u postgres psql -d template1 -c "CREATE EXTENSION IF NOT EXISTS #{pg_ext}";
+ action :run
+ end
+ end

0 comments on commit ecf7a1d

Please sign in to comment.