Force ID of user created by apt-get

Context:

I'm automatically installing postgresql-9.1 on an Ubuntu server with apt-get. This creates the required postgres user.

The Postgres data is on an external volume that survives reinstalls. This data is obviously owned by the postgres user.

The problem I'm having is that the ownership is not recorded under the name postgres, but under the UID that postgres had at creation time. When the server is reinstalled, postgres sometimes gets a different UID, and no longer owns the data directory, and thus does not work.


Question:

Can I force the UID of the user postgres created by apt-get to something fixed? Or is there another way to solve my problem?


(As you may have deduced, this is on Amazon EC2 with the data on an EBS volume)


Two ideas:

  1. Create your postgres user before installing PostgreSQL, using the correct UID.
  2. Create your own custom postgresql-9.1 package which installs the stock postgresql-9.1 package and then does the chown.

usermod -u {desired_UID} {username}

Stole this from here: Lethe's blog

But I actually think that a chown would be better than this, since it cannot fail on account of the desired_UID being already used or conflict laden in other ways.