Fly.Postgres.LSN (Fly Postgres v0.3.4) View Source

Data structure that represents a PostgreSQL LSN or Log Sequence Number.

Two LSN values can be compared using the replicated?/2 function. An LSN associated with the DB modification has a source of :insert. On a replica instance, that can be used to see when the insert has been replicated locally.

Link to this section Summary

Functions

After performing a database modification, calling current_wal_insert/1 returns a value that can be used to compare against a WAL value from the replica database to determine when the changes have been replayed on the replica.

When talking to a replica database, this returns a value for what changes have been replayed on the replica from the primary.

When talking to a replica database, this returns a value for what changes have been replayed on the replica from the primary.

Create a new Fly.Postgres.LSN struct from the a queried WAL value.

Compare two Fly.Postgres.LSN structs to determine if the transaction representing a data change on the primary has been replayed locally.

Convert an LSN struct back into a text value.

Link to this section Types

Specs

t() :: %Fly.Postgres.LSN{
  fpart: nil | integer(),
  offset: nil | integer(),
  source: :not_replicating | :insert | :replay
}

Link to this section Functions

Link to this function

current_wal_insert(repo)

View Source

After performing a database modification, calling current_wal_insert/1 returns a value that can be used to compare against a WAL value from the replica database to determine when the changes have been replayed on the replica.

When talking to a replica database, this returns a value for what changes have been replayed on the replica from the primary.

Link to this function

last_wal_replay_watch(repo, from_lsn)

View Source

Specs

last_wal_replay_watch(module(), nil | t()) :: nil | t()

When talking to a replica database, this returns a value for what changes have been replayed on the replica from the primary.

Specs

new(lsn :: nil | String.t(), source :: :insert | :replay) :: no_return() | t()

Create a new Fly.Postgres.LSN struct from the a queried WAL value.

Link to this function

replicated?(replay_lsn, insert_lsn)

View Source

Compare two Fly.Postgres.LSN structs to determine if the transaction representing a data change on the primary has been replayed locally.

They are compared where the replay/replica value is in argument 1 and the insert value is in argument two.

Examples

repo |> last_wal_replay() |> replicated?(primary_lsn)

Specs

to_text(t()) :: nil | String.t()

Convert an LSN struct back into a text value.