electric-sql / electric-sql/electric

publication "electric_publication_default" already exists

Open
#3,069 4 comments 1 reaction 0 assignees View on GitHub
triage
Dominant language
TypeScript
Stars
10.4k
Forks
375
Avg merge
3d 1h
Merged PRs (30d)
18

Description

"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_level` is set to `logical` in `postgresql.conf`.
- Verified the correct `postgresql.conf` file using `SHOW config_file;`.
- Verified connection settings (`pg_hba.conf` modified 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`

```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:strongpassword@host.docker.internal:5432/electricsql_db?sslmode=disable
- ELECTRIC_INSECURE=true
restart: always
```

---

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.