title: postgres could not create replication slot
body: <p>I'm trying to setup a simple replication scenario in <a href="/questions/tagged/postgres" class="post-tag" title="show questions tagged &#39;postgres&#39;" rel="tag">postgres</a> using <a href="/questions/tagged/logical-replication" class="post-tag" title="show questions tagged &#39;logical-replication&#39;" rel="tag">logical-replication</a> and <a href="/questions/tagged/docker-compose" class="post-tag" title="show questions tagged &#39;docker-compose&#39;" rel="tag">docker-compose</a>. As you can see I'm using a postgres service for the master database (publisher) and one more for the replica (subscriber). <code>wal_level = logical</code> is configured in both services by using this <a href="https://github.com/docker-library/docs/blob/master/postgres/README.md#database-configuration" rel="nofollow noreferrer">method</a>.</p>
  <p><em>docker-compose.yml:</em></p>
  <pre class="lang-yaml prettyprint-override"><code>version: '3.3'
  
  services:
    master:
      image: postgres:11
      env_file:
        - .env
      volumes:
        - ./postgres.conf:/etc/postgresql/postgresql.conf
        - ./master-init.sql:/docker-entrypoint-initdb.d/init.sql
      ports:
      - 5432:5432
  
    replica:
      image: postgres:11
      env_file:
        - .env
      volumes:
        - ./postgres.conf:/etc/postgresql/postgresql.conf
        - ./replica-init.sql:/docker-entrypoint-initdb.d/init.sql
      ports:
      - 6543:5432
      depends_on:
        - master
  </code></pre>
  <p><em>master-init.sql:</em></p>
  <pre class="lang-sql prettyprint-override"><code>create table if not exists products
  (
      product_id int
          constraint products_pk
              primary key,
      price      float not null,
      brand_id   int   not null
  );
  
  create table if not exists brand_avg
  (
      brand_id  int unique not null,
      avg_price float      not null
  );
  
  create publication main_pub for all tables;
  
  insert into products
      (product_id, price, brand_id)
  values (1, 2.45, 1),
         (2, 4.21, 1),
         (3, 5.21, 1),
         (4, 6.34, 1),
         (5, 90.1, 2),
         (6, 87.1, 2),
         (7, 21, 3),
         (8, 23, 3),
         (9, 1, 4),
         (10, 2, 1),
         (11, 32, 3)
  on conflict do nothing;
  
  insert into brand_avg
      (brand_id, avg_price)
  select brand_id, avg(price)
  from products
  group by brand_id
  order by brand_id
  on conflict do nothing;
  </code></pre>
  <p><em>replica-init.sql:</em></p>
  <pre class="lang-sql prettyprint-override"><code>create table if not exists products
  (
      product_id int
          constraint products_pk
              primary key,
      price      float not null,
      brand_id   int   not null
  );
  
  create table if not exists brand_avg
  (
      brand_id  int unique not null,
      avg_price float      not null
  );
  
  create subscription main_sub connection 'dbname=random host=master user=sample password=1234asdf' publication main_pub;
  </code></pre>
  <p><em>postgres.conf:</em></p>
  <pre class="lang-ini prettyprint-override"><code>listen_addresses = '*'
  wal_level = logical
  </code></pre>
  <p>while I'm trying to start the services, I'm getting this error:</p>
  <pre class="lang-plaintext prettyprint-override"><code>master_1   | 2021-02-04 19:02:07.549 UTC [90] ERROR:  logical decoding requires wal_level &gt;= logical
  replica_1  | psql:/docker-entrypoint-initdb.d/init.sql:16: ERROR:  could not create replication slot &quot;main_sub&quot;: ERROR:  logical decoding requires wal_level &gt;= logical
  replica_1  | 2021-02-04 19:02:07.549 UTC [81] ERROR:  could not create replication slot &quot;main_sub&quot;: ERROR:  logical decoding requires wal_level &gt;= logical
  replica_1  | 2021-02-04 19:02:07.549 UTC [81] STATEMENT:  create subscription main_sub connection 'dbname=random host=master user=sample password=1234asdf' publication main_pub;
  db-rbr_replica_1 exited with code 3
  </code></pre>
  <p>Below you can find the whole standard output:</p>
  <pre class="lang-txt prettyprint-override"><code>$ docker-compose up
  Creating network &quot;db-rbr_default&quot; with the default driver
  Creating db-rbr_master_1 ... done
  Creating db-rbr_replica_1 ... done
  Attaching to db-rbr_master_1, db-rbr_replica_1
  master_1   | The files belonging to this database system will be owned by user &quot;postgres&quot;.
  master_1   | This user must also own the server process.
  master_1   |
  master_1   | The database cluster will be initialized with locale &quot;en_US.utf8&quot;.
  master_1   | The default database encoding has accordingly been set to &quot;UTF8&quot;.
  master_1   | The default text search configuration will be set to &quot;english&quot;.
  master_1   |
  master_1   | Data page checksums are disabled.
  master_1   |
  master_1   | fixing permissions on existing directory /var/lib/postgresql/data ... ok
  master_1   | creating subdirectories ... ok
  master_1   | selecting default max_connections ... 100
  master_1   | selecting default shared_buffers ... 128MB
  master_1   | selecting default timezone ... Etc/UTC
  master_1   | selecting dynamic shared memory implementation ... posix
  master_1   | creating configuration files ... ok
  master_1   | running bootstrap script ... ok
  replica_1  | The files belonging to this database system will be owned by user &quot;postgres&quot;.
  replica_1  | This user must also own the server process.
  replica_1  |
  replica_1  | The database cluster will be initialized with locale &quot;en_US.utf8&quot;.
  replica_1  | The default database encoding has accordingly been set to &quot;UTF8&quot;.
  replica_1  | The default text search configuration will be set to &quot;english&quot;.
  replica_1  |
  replica_1  | Data page checksums are disabled.
  replica_1  |
  replica_1  | fixing permissions on existing directory /var/lib/postgresql/data ... ok
  replica_1  | creating subdirectories ... ok
  replica_1  | selecting default max_connections ... 100
  replica_1  | selecting default shared_buffers ... 128MB
  replica_1  | selecting default timezone ... Etc/UTC
  replica_1  | selecting dynamic shared memory implementation ... posix
  replica_1  | creating configuration files ... ok
  replica_1  | running bootstrap script ... ok
  master_1   | performing post-bootstrap initialization ... ok
  master_1   | syncing data to disk ... ok
  master_1   |
  master_1   | Success. You can now start the database server using:
  master_1   |
  master_1   |     pg_ctl -D /var/lib/postgresql/data -l logfile start
  master_1   |
  master_1   |
  master_1   | WARNING: enabling &quot;trust&quot; authentication for local connections
  master_1   | You can change this by editing pg_hba.conf or using the option -A, or
  master_1   | --auth-local and --auth-host, the next time you run initdb.
  master_1   | waiting for server to start....2021-02-04 19:02:06.696 UTC [46] LOG:  listening on Unix socket &quot;/var/run/postgresql/.s.PGSQL.5432&quot;
  master_1   | 2021-02-04 19:02:06.707 UTC [47] LOG:  database system was shut down at 2021-02-04 19:02:06 UTC
  master_1   | 2021-02-04 19:02:06.710 UTC [46] LOG:  database system is ready to accept connections
  master_1   |  done
  master_1   | server started
  replica_1  | performing post-bootstrap initialization ... ok
  replica_1  | syncing data to disk ... ok
  replica_1  |
  replica_1  | Success. You can now start the database server using:
  replica_1  |
  replica_1  |     pg_ctl -D /var/lib/postgresql/data -l logfile start
  replica_1  |
  replica_1  |
  replica_1  | WARNING: enabling &quot;trust&quot; authentication for local connections
  replica_1  | You can change this by editing pg_hba.conf or using the option -A, or
  replica_1  | --auth-local and --auth-host, the next time you run initdb.
  replica_1  | waiting for server to start....2021-02-04 19:02:07.050 UTC [46] LOG:  listening on Unix socket &quot;/var/run/postgresql/.s.PGSQL.5432&quot;
  replica_1  | 2021-02-04 19:02:07.060 UTC [47] LOG:  database system was shut down at 2021-02-04 19:02:06 UTC
  replica_1  | 2021-02-04 19:02:07.064 UTC [46] LOG:  database system is ready to accept connections
  master_1   | CREATE DATABASE
  master_1   |
  master_1   |
  master_1   | /usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/init.sql
  replica_1  |  done
  replica_1  | server started
  master_1   | CREATE TABLE
  master_1   | CREATE TABLE
  master_1   | CREATE PUBLICATION
  master_1   | INSERT 0 11
  master_1   | INSERT 0 4
  master_1   |
  master_1   |
  master_1   | waiting for server to shut down...2021-02-04 19:02:07.165 UTC [46] LOG:  received fast shutdown request
  master_1   | .2021-02-04 19:02:07.166 UTC [46] LOG:  aborting any active transactions
  master_1   | 2021-02-04 19:02:07.167 UTC [46] LOG:  background worker &quot;logical replication launcher&quot; (PID 53) exited with exit code 1
  master_1   | 2021-02-04 19:02:07.168 UTC [48] LOG:  shutting down
  master_1   | 2021-02-04 19:02:07.180 UTC [46] LOG:  database system is shut down
  master_1   |  done
  master_1   | server stopped
  master_1   |
  master_1   | PostgreSQL init process complete; ready for start up.
  master_1   |
  master_1   | 2021-02-04 19:02:07.280 UTC [1] LOG:  listening on IPv4 address &quot;0.0.0.0&quot;, port 5432
  master_1   | 2021-02-04 19:02:07.280 UTC [1] LOG:  listening on IPv6 address &quot;::&quot;, port 5432
  master_1   | 2021-02-04 19:02:07.282 UTC [1] LOG:  listening on Unix socket &quot;/var/run/postgresql/.s.PGSQL.5432&quot;
  master_1   | 2021-02-04 19:02:07.301 UTC [83] LOG:  database system was shut down at 2021-02-04 19:02:07 UTC
  master_1   | 2021-02-04 19:02:07.305 UTC [1] LOG:  database system is ready to accept connections
  replica_1  | CREATE DATABASE
  replica_1  |
  replica_1  |
  replica_1  | /usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/init.sql
  replica_1  | CREATE TABLE
  replica_1  | CREATE TABLE
  master_1   | 2021-02-04 19:02:07.549 UTC [90] ERROR:  logical decoding requires wal_level &gt;= logical
  replica_1  | psql:/docker-entrypoint-initdb.d/init.sql:16: ERROR:  could not create replication slot &quot;main_sub&quot;: ERROR:  logical decoding requires wal_level &gt;= logical
  replica_1  | 2021-02-04 19:02:07.549 UTC [81] ERROR:  could not create replication slot &quot;main_sub&quot;: ERROR:  logical decoding requires wal_level &gt;= logical
  replica_1  | 2021-02-04 19:02:07.549 UTC [81] STATEMENT:  create subscription main_sub connection 'dbname=random host=master user=sample password=1234asdf' publication main_pub;
  db-rbr_replica_1 exited with code 3
  </code></pre>