title: How to globally redefine nextval in PostgreSQL?
body: <p>The <code>nextval</code> computes the next value by adding <code>1</code> to the previous value <code>i</code> in the <code>some_id_seq</code>:</p>
  <p><code>nextval = i + 1</code>.</p>
  <p>But I want the <code>nextval</code> increment primary keys for all tables based on the server ID <code>N</code> in environment variable <code>export SERVER_ID=N</code>, by rule:</p>
  <p><code>nextval = (i // 1000 + 1) * 1000 + N</code>,</p>
  <p>producing sequence that always ends with a few zeros-padded server <code>N</code>'s ID, like so, if <code>SERVER_ID=3</code>:</p>
  <p><code>1003, 2003, 3003, 4003, 5003, 6003, 7003, 8003, 9003, 10003, ...</code>.</p>
  <p>Is there a way to globally redefine the <code>nextval</code> function in PostgreSQL, on a per-server basis?</p>
  <p><strong>Related answer:</strong> <a href="https://dba.stackexchange.com/questions/71702/primary-key-with-randomly-varying-increments-so-it-cannot-be-guessed-easily/71719#71719">Primary key with randomly varying increments</a>.</p>