title: postgresql: change primary key
body: <p>Until now I had a column <code>account_name</code> as the primary key for my database.  I'd now like to use a hash of <code>account_name</code> as the primary key instead.  </p>
  
  <p>So as an interim measure, I added an <code>account_hash</code> column and gave it the UNIQUE constraint, so that both <code>account_name</code> and <code>account_hash</code> exist together.</p>
  
  <p>I populated <code>account_hash</code> for all database entries, and am now actually using <code>account_hash</code> as the key for the database, and am no longer actively using <code>account_name</code> for anything.  </p>
  
  <p>But of course because <code>account_name</code> is the "official" primary key, and must be NOT NULL, for any new entries I have been populating both <code>account_name</code> and <code>account_hash</code> with the same hash.</p>
  
  <p>It's all working fine like this, but now I'd like to clean up the database, to get rid of <code>account_name</code> entirely, and to make <code>account_hash</code> the primary key instead.</p>
  
  <p>What is the best way of doing this?  It is a working database that is in use constantly, so any change needs to be at minimum disruption to the users.</p>
  
  <p>Here is the <code>\d+</code> information relating to the relevant columns:</p>
  
  <pre><code>            Column             |          Type          |          Modifiers          | Storage  | Stats target | Description 
  -------------------------------+------------------------+-----------------------------+----------+--------------+-------------
   account_name                  | character varying(255) | not null                    | extended |              | 
   account_hash                  | character varying(256) |                             | extended |              | 
  Indexes:
      "users_pkey" PRIMARY KEY, btree (account_name)
      "users_account_hash_256_key" UNIQUE CONSTRAINT, btree (account_hash)
  Has OIDs: no
  </code></pre>
  
  <p>Thanks for any help!</p>