def promote(): assert is_secondary(), 'Cannot promote primary' assert is_running(), 'Attempting to promote a stopped server' wal_e_enabled = reactive.is_state('postgresql.wal_e.enabled') if wal_e_enabled or has_version('9.3'): # If we have PostgreSQL 9.3 or WAL archiving enabled, promote # and do a timeline switch. We have to assume WAL-E is configured # properly and is working. rc = subprocess.call(['sudo', '-u', 'postgres', '-H', pg_ctl_path(), 'promote', '-D', data_dir()], universal_newlines=True) if rc != 0: helpers.status_set('blocked', 'Failed to promote to primary') raise SystemExit(0) else: # Removing recovery.conf will promote the unit to master without # a timeline switch when PostgreSQL is restarted. os.unlink(recovery_conf_path()) # Restart now. No need to request permission, as this unit was # previously a secondary and not being used by anything. This # also ensures the unit is a functioning primary before returning, # like the newer 'promote' code path above. stop() start()
def promote(): assert is_secondary(), "Cannot promote primary" assert is_running(), "Attempting to promote a stopped server" rc = subprocess.call( ["sudo", "-u", "postgres", "-H", pg_ctl_path(), "promote", "-D", data_dir()], universal_newlines=True, ) if rc != 0: helpers.status_set("blocked", "Failed to promote to primary") raise SystemExit(0)
def handle_storage_relation(dead_chicken): # Remove this once Juju storage is no longer experiemental and # everyone has had a chance to upgrade. data_rels = context.Relations()['data'] if len(data_rels) > 1: helpers.status_set('blocked', 'Too many relations to the storage subordinate') return elif data_rels: relid, rel = list(data_rels.items())[0] rel.local['mountpoint'] = external_volume_mount if needs_remount(): reactive.set_state('postgresql.storage.needs_remount') apt.queue_install(['rsync']) # Migrate any data when we can restart. coordinator.acquire('restart')
def handle_storage_relation(dead_chicken): # Remove this once Juju storage is no longer experiemental and # everyone has had a chance to upgrade. data_rels = context.Relations()["data"] if len(data_rels) > 1: helpers.status_set("blocked", "Too many relations to the storage subordinate") return elif data_rels: relid, rel = list(data_rels.items())[0] rel.local["mountpoint"] = external_volume_mount if needs_remount(): reactive.set_state("postgresql.storage.needs_remount") apt.queue_install(["rsync"]) # Migrate any data when we can restart. coordinator.acquire("restart")