PostgreSQL on OpenShift

The postgresql cartridge(s) provides PostgreSQL on OpenShift. PostgreSQL is an open-source object-relational database system. With OpenShift you can easily deploy and run applications backed by PostgreSQL using your favorite servers and frameworks. OpenShift Online currently supports PostgreSQL 8.4 and 9.2.

The PostgreSQL Cartridge

Environment Variables

The postgresql cartridge provides several environment variables to reference for ease of use:

Variable Description

OPENSHIFT_POSTGRESQL_DB_HOST

Numeric host address

OPENSHIFT_POSTGRESQL_DB_PORT

Port

OPENSHIFT_POSTGRESQL_DB_USERNAME

DB Username

OPENSHIFT_POSTGRESQL_DB_PASSWORD

DB Password

OPENSHIFT_POSTGRESQL_DB_LOG_DIR

Directory for log files

OPENSHIFT_POSTGRESQL_DB_PID

PID of current Postgres server

OPENSHIFT_POSTGRESQL_DB_SOCKET_DIR

Postgres socket location

OPENSHIFT_POSTGRESQL_DB_URL

Full server URL of the form "postgresql://user:password@host:port"

OPENSHIFT_POSTGRESQL_VERSION

PostgreSQL version in the form X.Y

You can fine-tune the PostgreSQL server performance by using the rhc tool and changing the default values for these variables:

Variable Description

OPENSHIFT_POSTGRESQL_SHARED_BUFFERS

The shared_buffers configuration parameter determines how much memory is dedicated to PostgreSQL to use for caching data.

OPENSHIFT_POSTGRESQL_MAX_CONNECTIONS

max_connections sets exactly that: the maximum number of client connections allowed.

For more details, please refer to the PostgreSQL wiki page.

Example Use

Getting a Python app with a PostgreSQL backend deployed onto OpenShift is as easy as executing two commands:

$ rhc app create MyApp python-3.3
$ rhc cartridge add postgresql-9.2 -a MyApp

These two commands create your "server" and install and configure Python, PostgreSQL, and a git repository on the server. You can now visit your application on the web at:

http://MyApp-MyDomain.rhcloud.com/