I use Windows 7 on my own home computer. I have installed PostgreSQL and now I would like to create an database.

I tried with createdb mydatabase but I got this error message:

createdb: could not connect to database postgres: FATAL: role "Jonas" does
not exist

I have also tried to create a role "Jonas" with createuser Jonas but I got the same error, even if I was logged in as Administrator in PowerShell.

How can I create a PostgreSQL database on my Windows 7 machine?



Another response could be this:

createdb: could not connect to database postgres: FATAL:  user "joe" does not

where your own login name is mentioned. This will happen if the administrator has not created a PostgreSQL user account for you. (PostgreSQL user accounts are distinct from operating system user accounts.) If you are the administrator, see Chapter 18 for help creating accounts. You will need to become the operating system user under which PostgreSQL was installed (usually postgres) to create the first user account.

  • 1
    I tried to start PowerShell as Administrator and then execute createuser Jonas but I got the same error message. – Jonas Dec 10 '10 at 22:34
  • Did you try to start PowerShell as postgres? – ta.speot.is Dec 10 '10 at 22:42
  • No, how can I do that? I asked a related question to solve this, but that only works for Administrator. – Jonas Dec 10 '10 at 22:52
  • It worked when I started PowerShell with runas /user:ComputerName\postgres powershell and then executed createuser Jonas – Jonas Dec 10 '10 at 23:34

From http://www.postgresql.org/docs/8.1/static/tutorial-createdb.html

It could also be that you were assigned a PostgreSQL user name that is different from your operating system user name; in that case you need to use the -U switch or set the PGUSER environment variable to specify your PostgreSQL user name.

I met the same problem, now I do it with

createdb -U postgres dbname

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.