How to keep an unique counter per row with PostgreSQL?
SEQUENCE is guaranteed to be unique, and your use-case looks applicable if your number of documents isn't too high (else you have a lot of sequences to manage). Use the RETURNING clause to get the value that was generated by the sequence.
For example, using 'A36' as a document_id:


Per document, you could create a sequence to track the increment.
Managing the sequences will need to be handled with some care. You could perhaps keep a separate table containing the document names and the sequence associated with that document_id to reference when inserting/updating the document_revisions table.

 CREATE SEQUENCE d_r_document_a36_seq;

 INSERT INTO document_revisions (document_id, rev)
 VALUES ('A36',nextval('d_r_document_a36_seq')) RETURNING rev;