PG Open Cloud

Portable PG applications

presented by

ryan jarvinen / @ryanj
Open Platforms Engineer
Red Hat


  1. Open Cloud Overview
  2. Learn how to write for the Open Cloud

the Cloud

"what is it made of?"

The cloud is:

  • hot air?
  • a series of tubes?
  • mostly cat photos


  • Communications: fiber, switches, wireless
  • Storage and Compute: chips, servers, disks, databases
  • DevOps (and friction)
  • Software as a Service: Dropbox, Gmail


  • Amazon EC2
  • RackSpace
  • Linode
  • BlueHost

* Many are VM / VPS-based services

Building with Postgres normally looks like:

  1. Install Apache with Mod_WSGI
  2. Make sure we have all the Python extensions set so Apache can see them
  3. Configure firewall so that only http, https, and ssh are available to outside world
  4. Install Postgresql, and plugins
  5. update PG_hba.conf, create db user, create db user password, set up access privs, and a test account
  6. Create DB, give user permissions to the DB
  7. Set up a git repository and then figure out how to structure and deploy
  8. Now I can write code - hello world, then database connection, then real app
  9. Get it working with a public DNS
  10. Now you are stuck maintaining the machine

OR - if your Ops team offers pre-built VMs:

  1. Fill out a mile high stack of request forms for a VM from Ops and wait
  2. Then realize it's not configured properly, submit ticket and wait
  3. Repeat same information, and wait
  4. Your ops person moves to a different group, GOTO Line 1....

As a sysadmin:

  1. We're busy keeping the site up, we'll need to provision your VM later
  2. Developers always want to try a new language or datastore that they don't know how to install, let alone manage
  3. There is whole bunch of account creation and lockdown for each VM. I'll need to give them Sudo or they'll annoy me all the time
  4. Each machine ends up with a wildly different config
  5. Developers never give up the resources from their VMs - spreadsheets and emails
  6. If there is a security fix I need to go into each VM and update it
  7. I don't want to spend my time updating DNS tables

Platforms provide a peaceful environment for Devs AND SysAdmins

  • Operations can ensure stability and performance
  • Developers can self-provision environments without waiting
  • The discussion shifts toward establishing policies for scaling

Public / Hosted PaaS

  • Heroku
  • EngineYard
  • Google App Engine
  • Amazon BeanStalk

* usually VM-based or proprietary application container technologies

the public cloud

This all sounds great, but what about…


the Open Cloud


  • OpenStack
  • Eucalptus
  • CloudStack
  • Or, roll your own

Open PaaS

  • OpenShift
  • Cloud Foundry

Built around Containers

Triumph of the Open Cloud

When "Big Cloud" fails you, you can always decide to host your own


Reusable, Redeployable code - host it anywhere

rhc app create rss php-5 postgresql-9 cron-1.4 --from-code=

Adding Postgres to existing applications:

rhc cartridge add postgres-8.4
rhc cartridge add postgres-9.2


blog post: PostgreSQL 9.2 Comes to OpenShift

rhc app show rss

Or, while connected over ssh:

env | grep DB

Terminology (Red Hat)

  • Broker – Management host, orchestration of Nodes
  • Node – Compute host containing Gears
  • Gear – Allocation of fixed memory, compute, and storage resources for running applications
  • Cartridge – A technology/framework (Python, Ruby, Javascript, PHP, Perl, Java/JEE, PG, MySQL, Jenkins, PHPMyAdmin, etc.) for application service dependencies

Gears: Secure and Efficient

An Open Cartridge format

OpenShift Cartridge

cart developer's guide

Open, and working in the Upstream

Writing Apps for the Open Cloud

ToDo App

(flask and SQLAlchemy)

blog post: Build Your App on OpenShift Using Flask, SQLAlchemy, and PostgreSQL 9.2

rhc app create -s task python-2.7 postgresql-9.2 --from-code=

OpenShift Scaling Hooks

Setting a min and max scale from the command line

rhc cartridge-scale python-2.7 -a task --min 3 --max 5

Scaling Web UI

Application scaling settings

HAProxy Scaling Hooks

Adding and removing instances / scaling up and down

haproxy_ctld --up

haproxy_ctld --down

HAProxy on / off switches

haproxy_ctld_daemon start
haproxy_ctld_daemon stop
haproxy_ctld_daemon restart

These hooks are available on the command line within your gear, and via a REST API

HAProxy Web UI


HAProxy raw data


Living in the clouds

Code for America

Adopt a Cause

This app should be using PostGIS for spatial queries:

blog post: More Spatial in Your Database with PostGIS 2.0

Persist configuration details,
while keeping your source clean:

rhc app create hydrant ruby-1.9 postgresql-8.4 --from=code= --env SECRET_TOKEN="YOUR_SECRET_TOKEN"

Environment Variables

Listing your custom env vars:

cd hydrant
rhc env list

Setting a variable:

rhc env set SECRET_TOKEN="a1fdacc3b1d14d6a92ed1219ed304d02529f535085262a90c39f072ef6de0ee9fe3a3d0194f02a2a8eb3"

Help with configuration:

rhc help env


Automatic support for dependency resolution using standard packaging, native to each language:

gems (ruby), eggs (python), and npm modules (node.js)

Mapping National Parks

with PostGIS

Action Hooks

  1. enable postgis
  2. create your table schema
  3. add a geospatial index
  4. bootstrap your db

Open Source Banners!

Join the Community

Check out the upstream source:
OpenShift Origin

Try our hosted solution (3 apps free):
OpenShift Online

Request an evaluation for:
OpenShift Enterprise

Thanks for following along!   --ryanj