How can I implement a sequence for each foreign key value?
How about using a column in the table account called max_customer_id and updating that every time there's a new customer? That should be the simplest solution available that I can think of.

With this solution you have to take care of the concurrency. Take a look at the document PostgreSQL Concurrency issues:


  If two concurrent transactions try to
  insert rows having the same key value, then the second one will block until
  the first one finishes. If the first transaction commits, the second one must
  abort because of the uniqueness constraint; but if the first one aborts the
  second one can proceed.
  
  If you want to assign a serial number to each row in a table, you might try
  INSERT INTO mytable (id, ...)
  VALUES( (SELECT MAX(id) + 1 FROM mytable), ...);
  This will not work safely unless you take an explicit lock on the whole table,
  which will prevent concurrent insertions. (It’ll also be quite slow, because
  MAX scans the whole table in PostgreSQL.)


Alternatively you could place the value in a separate table. This table would contain the account_id and maximum account_specific_id in use for that account. That way you could handle the concurrency easier with UPDATEs. Same source:


  A variant is to use a single-row
  table to hold the next ID number to assign:
  SELECT next FROM mytable counter FOR UPDATE;
  UPDATE mytable counter SET next = $next + 1;
  INSERT INTO mytable (id, ...) VALUES($next, ...);
  This works (as long as you use FOR UPDATE), but you still have the
  problem that only one insertion transaction can proceed at a time. The
  implicit write lock on the counter row is the bottleneck.
  [The author goes on recommending sequences.]


The number 2 option with sequences is not however recommended in this case as new sequences are not meant to be routinely inserted in a production environment.