Skip to content

Commit 951ef23

Browse files
authored
Merge pull request #37 from fracek/replication-slot-config
Add configuration option to use named replication slots
2 parents 9d24b60 + 1f5ac4e commit 951ef23

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

server/lib/realtime/application.ex

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ defmodule Realtime.Application do
1212
# Use this var to convert to sigil at connection
1313
host = System.get_env("DB_HOST") || 'localhost'
1414
port = System.get_env("DB_PORT") || 5432
15+
# Use a named replication slot if you want realtime to pickup from where
16+
# it left after a restart because of, for example, a crash.
17+
# You can get a list of active replication slots with
18+
# `select * from pg_replication_slots`
19+
slot_name = System.get_env("SLOT_NAME") || :temporary
1520
{port_number, _} = :string.to_integer(to_charlist(port))
1621
epgsql_params = %{
1722
host: ~c(#{host}),
@@ -29,7 +34,7 @@ defmodule Realtime.Application do
2934
{
3035
Realtime.Replication,
3136
epgsql: epgsql_params,
32-
slot: :temporary, # :temporary is also supported if you don't want Postgres keeping track of what you've acknowledged
37+
slot: slot_name,
3338
wal_position: {"0", "0"}, # You can provide a different WAL position if desired, or default to allowing Postgres to send you what it thinks you need
3439
publications: ["supabase_realtime"]
3540
},

0 commit comments

Comments
 (0)