PostgreSQL

Module pglift.postgresql exposes the following API to manipulate a PostgreSQL cluster:

async pglift.postgresql.status(instance)

Return the status of an instance.

Raises:

InstanceNotFound – if pg_ctl status command exits with status code 4 (data directory not found).

Parameters:

instance (PostgreSQLInstance)

Return type:

Status

async pglift.postgresql.check_status(instance, expected)

Check actual instance status with respected to expected one.

Raises:

InstanceStateError – in case the actual status is not expected.

Parameters:
Return type:

None

pglift.postgresql.is_ready(instance, *, cmd=<object object>)

Return True if the instance is ready per pg_isready.

Parameters:
  • instance (PostgreSQLInstance)

  • cmd (Annotated[CommandType, Dependency(var=<ContextVar name='Command' default=<module 'pglift.system.cmd' from '/home/docs/checkouts/readthedocs.org/user_builds/pglift/envs/v3.1.0/lib/python3.14/site-packages/pglift/system/cmd.py'> at 0x7bfc81884d60>)])

Return type:

bool

pglift.postgresql.logs(instance, *, timeout=None, poll_interval=0.1, fs=<object object>)

Return the content of current log file as an iterator.

Parameters:
  • instance (PostgreSQLInstance)

  • timeout (float | None)

  • poll_interval (float)

  • fs (Annotated[AbstractFS[PurePath] | AbstractFS[Path], Dependency(var=<ContextVar name='FileSystem' default=<pglift.system.fs.LocalFS object at 0x7bfc81a096a0> at 0x7bfc818849f0>)])

Return type:

Iterator[str]

async pglift.postgresql.replication_lag(instance)

Return the replication lag of a standby instance.

The instance must be running; if the primary is not running, None is returned.

Raises:

TypeError – if the instance is not a standby.

Parameters:

instance (PostgreSQLInstance)

Return type:

Decimal | None