publication "electric_publication_default" already exists
"publication "electric_publication_default" already exists" when running ElectricSQL with Docker and connecting to PostgreSQL on Windows 10
1.1.7
Bug description
I am trying to run an ElectricSQL instance using docker-compose.yaml and connect it to a PostgreSQL database that already exists and is running locally on my Windows 10 machine.
Even though I have tried all possible solutions, I consistently get the following error in Docker logs:
pid=<0.2921.0> [error] Electric.DBConnection unknown error: %Postgrex.Error{
message: nil,
postgres: %{
code: :duplicate_object,
line: "765",
message: "publication "electric_publication_default" already exists",
file: "publicationcmds.c",
unknown: "ERROR",
severity: "ERROR",
pg_code: "42710",
routine: "CreatePublication"
},
connection_id: 107728,
query: nil
}
Steps Taken
-
Verified that
wal_levelis set tologicalinpostgresql.conf. -
Verified the correct
postgresql.conffile usingSHOW config_file;. -
Verified connection settings (
pg_hba.confmodified accordingly). -
Restarted PostgreSQL service multiple times.
-
Dropped the publication manually using:
DROP PUBLICATION IF EXISTS electric_publication_default; -
Confirmed that the publication no longer exists via:
SELECT * FROM pg_publication;
Yet, when ElectricSQL starts, it still fails with the same error.
Environment
- OS: Windows 10
- PostgreSQL: 17.6 (running locally, installed via PostgreSQL installer)
- ElectricSQL: Latest Docker image (electricsql/electric)
- Docker: Running on Windows 10 with WSL2 backend
Expected behavior ElectricSQL should be able to connect to an existing PostgreSQL instance and create the publication if it does not exist, or reuse it without failing.
Actual Behavior ElectricSQL fails to start due to a duplicate publication error, even after dropping the publication and confirming it no longer exists.
Additional Notes
- The issue might be related to connecting ElectricSQL running in Docker to a PostgreSQL instance running natively on Windows (outside Docker).
- It seems ElectricSQL is not properly detecting or reusing the existing publication.
Any guidance or fix for this issue would be appreciated.
docker-compose.yaml
name: "electric_connection_to_postgres_custom"
services:
electric:
image: docker.io/electricsql/electric:latest
container_name: electriccustom
ports:
- "3000:3000"
environment:
- DATABASE_URL=postgresql://postgres:[email protected]:5432/electricsql_db?sslmode=disable
- ELECTRIC_INSECURE=true
restart: always
@Konrud could you share more of the log so we could see what was happening in the leadup to the error? You should also add the ELECTRIC_LOG_LEVEL: debug environment variable to make Electric produce more verbose logs.
@Konrud could you share more of the log so we could see what was happening in the leadup to the error? You should also add the
ELECTRIC_LOG_LEVEL: debugenvironment variable to make Electric produce more verbose logs.
Thank you, @alco, for the prompt reply. Here is the log before the publication "electric_publication_default" already exists error
=INFO REPORT==== 29-Aug-2025::11:29:34.937744 ===
Loading 142 CA(s) from otp store
11:29:35.119 pid=<0.2878.0> [info] Starting ElectricSQL 1.1.7
11:29:35.159 pid=<0.2889.0> [notice] Starting telemetry reporter. Electric will send anonymous usage data to [https://checkpoint.electric-sql.com.](https://checkpoint.electric-sql.com./) You can configure this with `ELECTRIC_USAGE_REPORTING` environment variable, see [https://electric-sql.com/docs/reference/telemetry](https://electric-sql.com/docs/reference/telemetry) for more information.
13:29:35.161 pid=<0.2893.0> [notice] Starting telemetry reporter. Electric will send anonymous usage data to [https://checkpoint.electric-sql.com.](https://checkpoint.electric-sql.com./) You can configure this with `ELECTRIC_USAGE_REPORTING` environment variable, see [https://electric-sql.com/docs/reference/telemetry](https://electric-sql.com/docs/reference/telemetry) for more information.
11:29:35.190 pid=<0.2881.0> [info] Running Electric.Plug.Router with Bandit 1.7.0 at 0.0.0.0:3000 (http)
11:29:35.418 pid=<0.2922.0> [info] Acquiring lock from postgres with name electric_slot_default
11:29:35.423 pid=<0.2922.0> [info] Lock acquired from postgres with name electric_slot_default
11:29:35.572 pid=<0.2921.0> [info] Postgres server version = 170006, system identifier = 7541309916738139608, timeline_id = 1
11:29:35.579 pid=<0.3231.0> [error] :gen_statem {:"Electric.ProcessRegistry:single_stack", {Electric.Postgres.ReplicationClient, nil}} terminating
** (Postgrex.Error) ERROR 42710 (duplicate_object) publication "electric_publication_default" already exists
(electric 1.1.7) lib/electric/postgres/replication_client/connection_setup.ex:98: Electric.Postgres.ReplicationClient.ConnectionSetup.create_publication_result/2
(electric 1.1.7) lib/electric/postgres/replication_client/connection_setup.ex:37: Electric.Postgres.ReplicationClient.ConnectionSetup.process_query_result/2
(electric 1.1.7) lib/electric/postgres/replication_client.ex:211: Electric.Postgres.ReplicationClient.handle_result/2
(postgrex 0.20.0) lib/postgrex/replication_connection.ex:561: Postgrex.ReplicationConnection.handle/5
(stdlib 7.0.1) gen_statem.erl:3750: :gen_statem.loop_state_callback/11
(stdlib 7.0.1) proc_lib.erl:333: :proc_lib.init_p_do_apply/3
Process Label: {:replication_client, "single_stack"}
Queue: [internal: {:connect, :init}]
Postponed: []
...
I am also getting this error on Windows 11
Electric is running in Docker PostgreSQL(17) is chosen to be local
services:
electric:
image: electricsql/electric:latest
container_name: electric
restart: always
ports:
- "5133:5133"
environment:
DATABASE_URL: "postgresql://postgres:[email protected]:5432/electric"
ELECTRIC_SECRET: "88068b920ec6797f4e8295661dd2e7ec5a94acbc4149438377a602a579d9facc"
ELECTRIC_HOST: "0.0.0.0"
ELECTRIC_PORT: "5133"
extra_hosts:
- "host.docker.internal:host-gateway"
But there is no problem when both Electric and PostgreSQL are running in Docker.
name: "electric_quickstart"
services:
postgres:
image: docker.io/postgres:16-alpine
environment:
POSTGRES_DB: electric
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
ports:
- "54321:5432"
tmpfs:
- /tmp
volumes:
- ./data/postgres:/var/lib/postgresql/data
command:
- -c
- listen_addresses=*
- -c
- wal_level=logical
healthcheck:
test: [ "CMD-SHELL", "pg_isready -U postgres" ]
interval: 5s
timeout: 5s
retries: 5
electric:
image: docker.io/electricsql/electric:latest
environment:
DATABASE_URL: postgresql://postgres:password@postgres:5432/electric?sslmode=disable
# Not suitable for production. Only use insecure mode in development or if you've otherwise secured the Electric API.
# See https://electric-sql.com/docs/guides/security
ELECTRIC_INSECURE: true
ports:
- "3000:3000"
depends_on:
postgres:
condition: service_healthy
I had the same problem. It turns out my database was using my native language, German, but according to the publication logic in https://github.com/electric-sql/electric/blob/main/packages/sync-service/lib/electric/postgres/replication_client/connection_setup.ex#L168 only English is supported.
The fix is to set the language of the database to English by updating this setting in the postgresql.conf:
lc_messages = 'C'