Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a user to PostgreSQL in Windows?

I'm running PostgreSQL on mt Windows 7 machine. To run a database I type:

C:\psql -Upostgres mydb 

and this works, but it would be nice if I could leave off the -U stuff, but then Postgres thinks I'm trying to log in as 'Eric', since that is my user profile.

So I need to add a user to Postgres, obviously. But how? If I try:

C:\createuser Eric 

Postgres thinks I'm trying to add a user Eric as the user Eric which fails. Adding the -U flag doesn't seem to work here.

What am I missing? My command window is in administrator mode, and there is no sudo available, obviously.

like image 306
Eric Wilson Avatar asked Mar 04 '11 02:03

Eric Wilson


People also ask

How do I add users to pgAdmin?

To add a user, click the Add (+) button at the top right corner. Provide information about the new pgAdmin role in the row: Use the drop-down list box next to Authentication source field to select the type of authentication that should be used for the user.


1 Answers

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.

like image 102
digitaljoel Avatar answered Sep 23 '22 14:09

digitaljoel