project pg_boss 1.0dev

Create, configure, and control PostgreSQL clusters in Python

The boss project provides functionality for managing PostgreSQL database clusters. Initialization, configuration, and execution are covered by three seperate modules in the package.

The 'init' module provides a Python interface to database cluster initialization, initdb. It provides the means to do so with many options.

The 'config' module provides a Python interface to a cluster's configuration, postgresql.conf. It provides a basic mechanism to parse setting lines in the files and a relatively intelligent mechanism for applying configuration alterations.

The 'hba' module provides a Python interface to a cluster's HBA file, pg_hba.conf. It provides basic methods for parsing, and altering of HBA lines.

The 'control' module provides a Python interface to controlling the Postgres process, via pg_ctl.


package postgresql.backend.boss

Backend management interfaces

module postgresql.backend.boss.control

imports
import os
import signal
import sys
import warnings
classes
class ControlError(Exception):
class ControlWarning(UserWarning):
class Controller(object):
Abstract Controller
class pg_ctl(Controller):
Python interface to a pg_ctl command relative to a data directory
methods
def __init__(self, location, pg_ctl_path =
'pg_ctl'
):
Takes the data directory path and the pg_ctl command's path,
def __repr__(self):
def reload(self):
Reload the cluster--graceful restart.
def restart(
self,
postmaster =
None
,
options =
None
,
mode =
'smart'
,
nowait =
False
,
logfile =
None

):
Restart the cluster
def running(self):
Check whether the cluster is running.
def start(
self,
postmaster =
None
,
options =
None
,
nowait =
False
,
logfile =
None

):
Start the cluster with the given parameters.
def stop(self, mode =
'smart'
, nowait =
False
):
Stop the running cluster

module postgresql.backend.boss.cluster

PostgreSQL cluster management interfaces
classes
class Cluster(object):
Cluster management class
class methods
def create(subtype, cluster_path, pg_config_dict):
Create a cluster at the given cluster path with the given pg_config
methods
def __init__(self, cluster_path, pg_config_dict):
def __repr__(self):
def drop(self):
Stop the cluster and delete it from the filesystem
def get_parameters(self, keys):
Get all the settings requested in the list of keys

Returns a dictionary of those keys with the values stored in the
configuration file.
def select_parameters(self, selector):
Get all the settings that the given selector chooses.

Returns a dictionary of those keys
def set_parameters(self, keyvals):
Given a dictionary of settings, apply them to the cluster's
postgresql.conf.
data
DEFAULT_CONFIG_FILENAME =
'postgresql.conf'
DEFAULT_HBA_FILENAME =
'pg_hba.conf'

module postgresql.backend.boss.init

PostgreSQL catalog cluster initialization interfaces
imports
import os
import signal
import sys
classes
class InitializorError(Exception):
class Initializor(object):
Base initializor
methods
def __init__(self, path =
'initdb'
):
def __repr__(self):

module postgresql.backend.boss.config

PostgreSQL configuration file parser and editor functions.
imports
import os
import sys
functions
def parse_line(line, equality =
'='
, comment =
u'#'
, quote =
u"'"
):
def write_config(map, writer, keys =
None
):
A configuration writer that will trample & merely write the settings
def alter_config(map, fo, keys =
None
):
Alters a configuration file without trampling on the existing structure
def read_config(iter, d =
None
, selector =
None
):
data
comment =
u'#'
quote =
u"'"

module postgresql.backend.boss.hba

PostgreSQL Host Based Authentication manipulation utilities.
imports
import os
import sys
classes
class Sequence(object):
A sequence manipulation interface for managing PostgreSQL's HBA
methods
def __init__(self, iterable):
Take a HBA line producing iterable to manipulate
def __delitem__(self, index):
def __getitem__(self, index):
def __len__(self):
def __setitem__(self, index, val):
def _correct_indexes_past(self, index, correction):
Correct the line numbers in the laws
def _format_like(self, fields, line, pl):
def append(self, entry):
def find(self, fields):
def index(self, fields):
def insert(self, index, entry, position =
0
):
Insert a new entry at the given index using the specified position
def insert_after(self, fields, entry):
def insert_before(self, fields, entry):
def pop(self, index =
0
):
def writeto(self, writer):
functions
def parse_line(line, separator =
u' \t'
, comment =
u'#'
):
parse a line from a pg_hba.conf file
def write_config(seq, writer):
A configuration writer that will trample & merely write the settings
def read_config(iter, s =
None
, selector =
None
):
Read and split all uncommented entries in the given iterator
def main(args):
data
comment =
u'#'
separator =
u' \t'