Add postgresql.get_version() function

This commit is contained in:
Lance Edgar 2019-09-23 15:25:39 -05:00
parent fef0ccbac5
commit 21bdc2b391

View file

@ -25,6 +25,7 @@ Fabric Library for PostgreSQL
"""
import os
import re
from rattail_fabric2 import apt
@ -36,6 +37,16 @@ def install(c):
apt.install(c, 'postgresql')
def get_version(c):
"""
Fetch the version of PostgreSQL running on the target system
"""
result = c.run('psql --version', warn=True)
if not result.failed:
match = re.match(r'^psql \(PostgreSQL\) (\d+\.\d+)(?:\.\d+)?', result.stdout.strip())
if match:
return float(match.group(1))
def restart(c):
"""
Restart the PostgreSQL database service