title: manually create replication slot for publication in PostgreSQL 10
body: <p>I am trying to get a stream of updates for certain tables from my PostgreSQL database. The regular way of getting all updates looks like this:</p>
  
  <p>You create a logical replication slot</p>
  
  <pre><code>pg_create_logical_replication_slot('my_slot', 'wal2json');
  </code></pre>
  
  <p>And either connect to it using <code>pg_recvlogical</code> or making special SQL queries. This allows you to get <strong>all</strong> the actions from the database in json (if you used <a href="https://github.com/eulerto/wal2json" rel="noreferrer">wal2json</a> plugin or similar) and then do whatever you want with that data.</p>
  
  <p>But in PostgreSQL 10 we have Publication/Subscription mechanism which allows us to replicate selected tables only. This is very handy because a lot of useless data is not being sent. The process looks like this:</p>
  
  <p>First, you create a publication</p>
  
  <pre><code>CREATE PUBLICATION foo FOR TABLE herp, derp;
  </code></pre>
  
  <p>Then you subscribe to that publication from another database</p>
  
  <pre><code>CREATE SUBSCRIPTION mysub CONNECTION &lt;connection stuff&gt; PUBLICATION foo;
  </code></pre>
  
  <p>This creates a replication slot on a master database under the hood and starts listening to updates and commit them to the same tables on a second database. This is fine if your job was to replicate some tables, but want to get a raw stream for my stuff.</p>
  
  <p>As I mentioned, the <code>CREATE SUBSCRIPTION</code> query is creating a replication slot on the master database under the hood, but how can I create one manually without the subscription and a second database? <a href="https://www.postgresql.org/docs/10/static/sql-createsubscription.html" rel="noreferrer">Here</a> the docs say:</p>
  
  <blockquote>
    <p>To make this work, create the replication slot separately (using the function pg_create_logical_replication_slot with the plugin name pgoutput)</p>
  </blockquote>
  
  <p>According to the docs, this is possible, but <code>pg_create_logical_replication_slot</code> only creates a regular replication slot. Is the <code>pgoutput</code> plugin responsible for all the magic? If yes, then it becomes impossible to use other plugins like <code>wal2json</code> with publications.</p>
  
  <p>What am I missing here?</p>