title: Why in PostgreSQL when you delete a row in a table the id number of the future inserted row is not sequential?
body: <p>I create the following table</p>
  
  <pre><code>CREATE TABLE dogs (
    id serial,
    name VARCHAR(15),
    age integer;
  </code></pre>
  
  <p>I have the table looking like this</p>
  
  <pre><code>                                  Table "public.birds"
   Column  |         Type          |                     Modifiers                      
  ---------+-----------------------+-------------------------------------    
   id      | integer               | not null default nextval('birds_id_seq'::regclass)
   name    | character varying(25) | 
   age     | integer               | 
  </code></pre>
  
  <p>I insert two rows</p>
  
  <pre><code>INSERT INTO dogs (name, age) 
  VALUES ('puffy', 13),
   ('fluffy', 15);
  </code></pre>
  
  <p>The table now looks like this</p>
  
  <pre><code>  id |  name  | age 
   ----+--------+-----
     1 | puffy  |  13
     2 | fluffy |  15
   (2 rows)
  </code></pre>
  
  <p>Then I delete the row with id = 2</p>
  
  <pre><code>DELETE FROM dogs WHERE id = 2;
  </code></pre>
  
  <p>And add another row instead</p>
  
  <pre><code>INSERT INTO dogs (name, age) VALUES('mimi', 20);
  </code></pre>
  
  <p>The table is</p>
  
  <pre><code>  id | name  | age 
   ----+-------+-----
     1 | puffy |  13
     3 | mimi  |  20
   (2 rows)
  </code></pre>
  
  <p>My question is why the next number for id in the second row is not 2 but 3? I guess that somewhere underneath something stores the last value in a memory and it doesn't matter that the row with that id was deleted. I know I can insert value for id explicitly if I need to. But I would like to be clear why it happens in this case.
   And what functionality or feature is responsible for that? How does it work?</p>