Tech Journal Back to Tech Journal

Creating a user in Postgres (and a DB, too!)

To create a user with a matching DB:

$ su postgres
$ createuser -S -D -R -P username
$ create -O username dbname

You should be aware, that if you are using IDENT in Postgres to authenticate, this won't work, unless there's a user in the operating system named username. To switch to a scheme that uses only the Postgres server's internal users (those defined with createuser), you must edit pg_hba.conf (usually in /var/lib/pgsql/data) and change the local line from:

local   all         all                               ident sameuser

to be:

local   all         all                               md5

then send a SIGHUP to the process, to reload the config. You must note that this might cause some issues with existing applications that might rely on IDENT, and with some users who lack passwords.

Last updated on 2007-08-25 12:15:23 -0700, by Shalom Craimer

Back to Tech Journal