Generate incrementing IDs without sequences
Stick to one serial column per document and create a gap-less sequence per user_id dynamically in a VIEW - if you really need it.

CREATE TABLE users (
  user_id serial PRIMARY KEY
, email text
);
CREATE TABLE document (
  document_id serial PRIMARY KEY
, user_id int NOT NULL
, document text);

CREATE VIEW document_with_rn_per_user AS
SELECT *, row_number() OVER (PARTITION BY user_id
                             ORDER BY document_id) AS doc_per_usr_id
FROM   document;


Never use basic type names like text as identifier. It's allowed, but it makes queries and error messages confusing. Generally, use descriptive names.

Related:


Compacting a sequence in PostgreSQL