How to add a user to PostgreSQL in Windows?

In pgadmin you can create a new "Login Role" and name it Eric and give it permissions graphically, or from command line you can do something like this

psql -U postgres -c "CREATE ROLE Eric LOGIN NOSUPERUSER INHERIT CREATEDB CREATEROLE;" mydb

see http://developer.postgresql.org/pgdocs/postgres/sql-createrole.html for information on the CREATE ROLE options.


The documentation for createuser indicates that a -U switch is accepted:

-U username
--username username

User name to connect as (not the user name to create).

This is what I would expect to use (although I've never tried to set up PostgreSQL on Windows, only on unices).


Just to add more information. From official documentation: you can specify the user under which createuser utility logs in to postgres via environment variable:

PGUSER

One liner for powershell:

& { $env:PGUSER="postgres"; .\createuser.exe Eric}