2ndQuadrant is now part of EDB

Bringing together some of the world's top PostgreSQL experts.

2ndQuadrant | PostgreSQL
Mission Critical Databases
  • Contact us
  • EN
    • FR
    • IT
    • ES
    • DE
    • PT
  • Support & Services
  • Products
  • Downloads
    • Installers
      • Postgres Installer
      • 2UDA – Unified Data Analytics
    • Whitepapers
      • Business Case for PostgreSQL Support
      • Security Best Practices for PostgreSQL
    • Case Studies
      • Performance Tuning
        • BenchPrep
        • tastyworks
      • Distributed Clusters
        • ClickUp
        • European Space Agency (ESA)
        • Telefónica del Sur
        • Animal Logic
      • Database Administration
        • Agilis Systems
      • Professional Training
        • Met Office
        • London & Partners
      • Database Upgrades
        • Alfred Wegener Institute (AWI)
      • Database Migration
        • International Game Technology (IGT)
        • Healthcare Software Solutions (HSS)
        • Navionics
  • Postgres Learning Center
    • Webinars
      • Upcoming Webinars
      • Webinar Library
    • Whitepapers
      • Business Case for PostgreSQL Support
      • Security Best Practices for PostgreSQL
    • Blog
    • Training
      • Course Catalogue
    • Case Studies
      • Performance Tuning
        • BenchPrep
        • tastyworks
      • Distributed Clusters
        • ClickUp
        • European Space Agency (ESA)
        • Telefónica del Sur
        • Animal Logic
      • Database Administration
        • Agilis Systems
      • Professional Training
        • Met Office
        • London & Partners
      • Database Upgrades
        • Alfred Wegener Institute (AWI)
      • Database Migration
        • International Game Technology (IGT)
        • Healthcare Software Solutions (HSS)
        • Navionics
    • Books
      • PostgreSQL 11 Administration Cookbook
      • PostgreSQL 10 Administration Cookbook
      • PostgreSQL High Availability Cookbook – 2nd Edition
      • PostgreSQL 9 Administration Cookbook – 3rd Edition
      • PostgreSQL Server Programming Cookbook – 2nd Edition
      • PostgreSQL 9 Cookbook – Chinese Edition
    • Videos
    • Events
    • PostgreSQL
      • PostgreSQL – History
      • Who uses PostgreSQL?
      • PostgreSQL FAQ
      • PostgreSQL vs MySQL
      • The Business Case for PostgreSQL
      • Security Information
      • Documentation
  • About Us
    • About 2ndQuadrant
    • 2ndQuadrant’s Passion for PostgreSQL
    • News
    • Careers
    • Team Profile
  • Blog
  • Menu Menu
You are here: Home1 / Blog2 / Gabriele's PlanetPostgreSQL3 / Postgres and devops: testing 9.3 with Vagrant and Puppet – part ...
Gabriele Bartolini

Postgres and devops: testing 9.3 with Vagrant and Puppet – part two

November 4, 2013/2 Comments/in Gabriele's PlanetPostgreSQL /by Gabriele Bartolini

In a previous blog post, I have gone through the steps of setting up a basic CentOS 6.4 64bit Linux distribution using Vagrant on your Ubuntu 12.04 LTS Linux. We will continue digging in the devops culture/movement and finally setup PostgreSQL 9.3 using Puppet in a local virtual machine.

This is what we are going to do now, together:

  1. install some “cool tools” for Ruby
  2. install the puppetlabs/postgresql module for Puppet
  3. instruct Vagrant to use Puppet as provisioner
  4. create a very simple Puppet manifest
  5. start up our machine
  6. test PostgreSQL 9.3

Installing the required tools

Ruby Programming LanguageThe most complicated part is the installation of the requirements for our Puppet modules. You can do without them, but I strongly encourage you to use them (or at least evaluate them and if you have enough Ruby experience, you might come with a ponderate decision).
The main reason is that, for example, if you want to use Puppet 3, you need at least Ruby 1.9.3 – which is not yet diffused.

We will use two tools for this purpose:

  • rbenv by Sam Stephenson, which allows you to install several Ruby versions and environments in your user space (without messing around with system installations);
  • librarian-puppet by Tim Sharpe, which helps us managing dependencies among Puppet modules.

I strongly suggest you read the documentation of both projects. I have been also suggested by Marco Nenciarini to look at rbenv-installer too for installing rbenv, but I have not tried it yet. Otherwise, just follow my instructions for a quick solution.

In your user’s home directory, type:

git clone http://github.com/sstephenson/rbenv.git ~/.rbenv

Then, make sure you add ~/.rbenv/bin to your PATH variable, by editing your ~/.profile file as follows:

# rbenv
if [ -d "$HOME/.rbenv" ] ; then
PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
fi

For the sake of simplicity, log again with your user and type:

git clone http://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build

In order to install Ruby 2.0 in your user space, you can now type:

rbenv install 2.0.0-p247

This will take a while. Then, all you need to do is set this version as default version for your user:

rbenv global 2.0.0-p247

This is how I very that version 2.0.0-p247 is that one I will use from now on:

$ rbenv version
2.0.0-p247 (set by /home/gabriele/.rbenv/version)

The next step is to install librarian-puppet and puppet. This can be easily done as follows:

gem install librarian-puppet puppet
rbenv rehash

Installing the Puppet module for PostgreSQL

Puppet LogoThe previous section terminates all the preparatory steps you need to take when working with Vagrant and Puppet in a very reusable and gentle (as in “not invasive”) way.

It is now time to start your new project, which will get you to successfully install a basic CentOS system with PostgreSQL 9.3 in it.

You can decide to reuse the project directory you have created in my previous blog post about setting up a basic CentOS 6.4 64bit Linux distribution using Vagrant.

However, for the sake of simplicity, in this article we will start from scratch again, with a new directory.
We will call it vagrant-pg93, but you can choose a different name.

Create the directory and then enter it:

mkdir vagrant-pg93
cd vagrant-pg93

After that, create a file called Puppetfile, containing:

forge "http://forge.puppetlabs.com"

mod 'puppetlabs/postgresql'

librarian-puppet will use the repository of modules provided by Puppetlabs (defined by the forge command) and will install the ‘puppetlabs/postgresql’ module.

In order to do that, you need to type the following command:

librarian-puppet install --verbose

This command will create a modules directory and install the postgresql module as well as its dependencies, like for example apt. This is the content of the modules directory:

$ ls modules/
apt		concat		firewall	postgresql	stdlib

Use Puppet as Provisioner for Vagrant

VagrantIt is now time to create your configuration file for Vagrant (the so called Vagrantfile). As outlined in the first part of the article, Vagrant gives you the possibility to generate a basic configuration file which you can then modify. Just issue:

vagrant init

We encourage you once again to take some time to read the configuration file content, as well as the documentation of Vagrant. The changes below allow you to:

  • instantiate a minimal CentOS 64 bit Linux system
  • create a private network and assign the 192.168.33.10 IP address to your new created server (your hosting machine will act as a gateway for that network)
  • select Puppet as provisioner tool, by specifying the modules directory (the one we just generated through librarian-puppet).

This is the content of the file – after having stripped empty lines and comments from it:

VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = 'centos6-64'
  config.vm.box_url = 'http://puppet-vagrant-boxes.puppetlabs.com/centos-64-x64-vbox4210.box'
  config.vm.network :private_network, ip: "192.168.33.10"
  config.vm.provision :puppet do |puppet|
    puppet.module_path = "modules"
    puppet.manifests_path = "manifests"
    puppet.manifest_file  = "init.pp"
  end
end

A more detailed look at the Puppet section suggests that the manifest file for the server is called init.pp and resides in the manifests directory.

Create your simple Puppet manifest for PostgreSQL 9.3

We have selected the PostgreSQL manifest published by Puppetlabs, as it is very simple to setup a basic database server with version 9.3 of our most loved DBMS. However, one day, you will be able to create your own Puppet module.

For now, just create the manifests directory and, most importantly, the manifests/init.pp file, containing the following lines:

# Install PostgreSQL 9.3 server from the PGDG repository
class {'postgresql::globals':
  version => '9.3',
  manage_package_repo => true,
  encoding => 'UTF8',
  locale  => 'it_IT.utf8',
}->
class { 'postgresql::server':
  ensure => 'present',
  listen_addresses => '*',
  manage_firewall => true,
}

# Install contrib modules
class { 'postgresql::server::contrib':
  package_ensure => 'present',
}

That should be all in terms of configuration. The manifest is responsible, among other things, for instructing Puppet to:

  • use version 9.3
  • use the Community repository for packages (manage_package_repo)
  • define default encoding and locale (you can change the latter to en_AU.utf8 if you live in Australia, for example)
  • make sure that the PostgreSQL server is always up and running, even at startup, and opens TCP/IP traffic to every network interface (which means you can connect to PostgreSQL using pgAdmin or psql from the hosting machine)
  • install the contrib modules package (containing PostgreSQL extensions such as hstore or pg_stat_statements).

Start up your local PostgreSQL 9.3 server and test it

Now, cross your fingers and type:

vagrant up

It will take a few minutes for Vagrant to generate your virtual server through VirtualBox, then provision the resources requested by the manifest file we wrote.

Once finished, you can finally test that PostgreSQL is running, by typing:

vagrant ssh

Then, become the postgres system user with:

sudo -i -u postgres

And finally connect to the database:

psql

This way, you verified that the internal connection (within the virtual server) works correctly.

Final notes

Loving the ElephantSo far so good. We have been able to install PostgreSQL 9.3 and you can try it locally. In a future blog post, we will go through some more advanced configurations of your development Postgres box using Puppet.

But for now, I hope you are satisfied with this outcome.

If you want to shutdown your virtual server, you just need to type:

vagrant halt

If you want to remove the server, just type:

vagrant destroy

You can at any time regenerate it through:

vagrant up

These commands allow you to automate the generation of virtual machines, one of the key technical aspects of the devops movement.

Tags: automation, CentOS, development, devops, operations, postgres, PostgreSQL, postgresql 9.3, puppet, testing, Ubuntu, vagrant, virtualbox
Share this entry
  • Share on Facebook
  • Share on Twitter
  • Share on WhatsApp
  • Share on LinkedIn
2 replies
  1. devops online training
    devops online training says:
    July 11, 2016 at 7:30 am

    Nice Article. How it help to developer in terms of balance the day to day life. Agile itself make life worse due to misuse by Scrum Masters especially in India.

    Reply
  2. Kelly Technologies
    Kelly Technologies says:
    May 10, 2017 at 1:22 pm

    Wow. That is so elegant and logical and clearly explained on DevOps article.

    Reply

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Search

Get in touch with us!

Recent Posts

  • Random Data December 3, 2020
  • Webinar: COMMIT Without Fear – The Beauty of CAMO [Follow Up] November 13, 2020
  • Full-text search since PostgreSQL 8.3 November 5, 2020
  • Random numbers November 3, 2020
  • Webinar: Best Practices for Bulk Data Loading in PostgreSQL [Follow Up] November 2, 2020

Featured External Blogs

Tomas Vondra's Blog

Our Bloggers

  • Simon Riggs
  • Alvaro Herrera
  • Andrew Dunstan
  • Craig Ringer
  • Francesco Canovai
  • Gabriele Bartolini
  • Giulio Calacoci
  • Ian Barwick
  • Marco Nenciarini
  • Mark Wong
  • Pavan Deolasee
  • Petr Jelinek
  • Shaun Thomas
  • Tomas Vondra
  • Umair Shahid

PostgreSQL Cloud

2QLovesPG 2UDA 9.6 backup Barman BDR Business Continuity community conference database DBA development devops disaster recovery greenplum Hot Standby JSON JSONB logical replication monitoring OmniDB open source Orange performance PG12 pgbarman pglogical PG Phriday postgres Postgres-BDR postgres-xl PostgreSQL PostgreSQL 9.6 PostgreSQL10 PostgreSQL11 PostgreSQL 11 PostgreSQL 11 New Features postgresql repmgr Recovery replication security sql wal webinar webinars

Support & Services

24/7 Production Support

Developer Support

Remote DBA for PostgreSQL

PostgreSQL Database Monitoring

PostgreSQL Health Check

PostgreSQL Performance Tuning

Database Security Audit

Upgrade PostgreSQL

PostgreSQL Migration Assessment

Migrate from Oracle to PostgreSQL

Products

HA Postgres Clusters

Postgres-BDR®

2ndQPostgres

pglogical

repmgr

Barman

Postgres Cloud Manager

SQL Firewall

Postgres-XL

OmniDB

Postgres Installer

2UDA

Postgres Learning Center

Introducing Postgres

Blog

Webinars

Books

Videos

Training

Case Studies

Events

About Us

About 2ndQuadrant

What does 2ndQuadrant Mean?

News

Careers 

Team Profile

© 2ndQuadrant Ltd. All rights reserved. | Privacy Policy
  • Twitter
  • LinkedIn
  • Facebook
  • Youtube
  • Mail
Tracing PostgreSQL with perf How do PostgreSQL security_barrier views work?
Scroll to top
×