Example #1
0
 def version(self):
     try:
         ver = __postgresql__[OPT_PG_VERSION]
     except KeyError:
         pg_info = software.postgresql_software_info()
         ver = '%s.%s' % (pg_info.version[0], pg_info.version[1]) or '9.0'
         __postgresql__[OPT_PG_VERSION] = ver
     return ver
Example #2
0
 def version(self):
     try:
         ver = __postgresql__[OPT_PG_VERSION]
     except KeyError:
         pg_info = software.postgresql_software_info()
         ver = "%s.%s" % (pg_info.version[0], pg_info.version[1]) or "9.0"
         __postgresql__[OPT_PG_VERSION] = ver
     return ver
Example #3
0
class ClusterDir(object):
    #TODO: Rethink ClusterDir and ConfigDir
    try:
        if 'Amazon' == linux.os['name'] and software.postgresql_software_info(
        ).version[:2] == (9, 2):
            base_path = '/var/lib/pgsql9/'
        else:
            base_path = glob.glob('/var/lib/p*sql/9.*/')[0]
        default_path = os.path.join(
            base_path, 'main' if linux.os.debian_family else 'data')
    except (IndexError, software.SoftwareError):
        base_path = None
        default_path = None

    def __init__(self, path=None):
        self.path = path
        self.user = DEFAULT_USER

    @classmethod
    def find(cls, postgresql_conf):
        return cls(postgresql_conf.data_directory or cls.default_path)

    def move_to(self, dst, move_files=True):
        new_cluster_dir = os.path.join(dst, STORAGE_DATA_DIR)

        if not os.path.exists(dst):
            LOG.debug(
                'Creating directory structure for postgresql cluster: %s' %
                dst)
            os.makedirs(dst)

        if move_files:
            source = self.path
            if not os.path.exists(self.path):
                source = self.default_path
                LOG.debug(
                    'data_directory in postgresql.conf points to non-existing location, using %s instead'
                    % source)
            if source != new_cluster_dir:
                LOG.debug("copying cluster files from %s into %s" %
                          (source, new_cluster_dir))
                shutil.copytree(source, new_cluster_dir)
        LOG.debug("changing directory owner to %s" % self.user)
        chown_r(dst, self.user)

        LOG.debug("Changing postgres user`s home directory")
        if linux.os.redhat_family:
            #looks like ubuntu doesn`t need this
            system2([USERMOD, '-d', new_cluster_dir, self.user])

        self.path = new_cluster_dir

        return new_cluster_dir

    def clean(self):
        fnames = ('recovery.conf', 'recovery.done', 'postmaster.pid')
        for fname in fnames:
            exclude = os.path.join(self.path, fname)
            if os.path.exists(exclude):
                LOG.debug('Deleting file: %s' % exclude)
                os.remove(exclude)

    def is_initialized(self, path):
        # are the pgsql files already in place?
        return os.path.exists(path) and STORAGE_DATA_DIR in os.listdir(path)
Example #4
0
PG_DUMP = '/usr/bin/pg_dump'

ROOT_USER = "******"
MASTER_USER = "******"
DEFAULT_USER = "******"

STORAGE_DATA_DIR = "data"
TRIGGER_NAME = "trigger"
PRESET_FNAME = 'postgresql.conf'
OPT_PG_VERSION = 'pg_version'
OPT_REPLICATION_MASTER = "replication_master"

LOG = logging.getLogger(__name__)
__postgresql__ = __node__[SERVICE_NAME]

if 'Amazon' == linux.os['name'] and software.postgresql_software_info(
).version[:2] == (9, 2):
    pg_pathname_pattern = '/var/lib/pgsql9/'
else:
    pg_pathname_pattern = '/var/lib/p*sql/9.*/'


class PgSQLInitScript(initdv2.ParametrizedInitScript):
    socket_file = None

    @lazy
    def __new__(cls, *args, **kws):
        obj = super(PgSQLInitScript, cls).__new__(cls, *args, **kws)
        cls.__init__(obj)
        return obj

    def __init__(self):
Example #5
0
PG_DUMP = "/usr/bin/pg_dump"

ROOT_USER = "******"
MASTER_USER = "******"
DEFAULT_USER = "******"

STORAGE_DATA_DIR = "data"
TRIGGER_NAME = "trigger"
PRESET_FNAME = "postgresql.conf"
OPT_PG_VERSION = "pg_version"
OPT_REPLICATION_MASTER = "replication_master"

LOG = logging.getLogger(__name__)
__postgresql__ = __node__[SERVICE_NAME]

if "Amazon" == linux.os["name"] and software.postgresql_software_info().version[:2] == (9, 2):
    pg_pathname_pattern = "/var/lib/pgsql9/"
else:
    pg_pathname_pattern = "/var/lib/p*sql/9.*/"


class PgSQLInitScript(initdv2.ParametrizedInitScript):
    socket_file = None

    @lazy
    def __new__(cls, *args, **kws):
        obj = super(PgSQLInitScript, cls).__new__(cls, *args, **kws)
        cls.__init__(obj)
        return obj

    def __init__(self):
Example #6
0
PG_DUMP = '/usr/bin/pg_dump'

ROOT_USER = "******"
MASTER_USER = "******"
DEFAULT_USER = "******"

STORAGE_DATA_DIR = "data"
TRIGGER_NAME = "trigger"
PRESET_FNAME = 'postgresql.conf'
OPT_PG_VERSION = 'pg_version'
OPT_REPLICATION_MASTER = "replication_master"

LOG = logging.getLogger(__name__)
__postgresql__ = __node__[SERVICE_NAME]

if 'Amazon' == linux.os['name'] and software.postgresql_software_info().version[:2] == (9,2):
    pg_pathname_pattern = '/var/lib/pgsql9/'
else:
    pg_pathname_pattern = '/var/lib/p*sql/9.*/'


class PgSQLInitScript(initdv2.ParametrizedInitScript):
    socket_file = None
    
    @lazy
    def __new__(cls, *args, **kws):
        obj = super(PgSQLInitScript, cls).__new__(cls, *args, **kws)
        cls.__init__(obj)
        return obj
            
    def __init__(self):