Getting a new account set up on PostgreSQL is a simple process…
Create our new user:
$ sudo su postgres -c createuser daz
Then you have to give this new user role a name (I called it daz), and then say ‘y’ to the question “Shall the new role be a superuser?” if you want the user to be an administrator.
Give the user a database password (this does not have to be the same as their unix password):
$ sudo su postgres -c psql
postgres=# ALTER USER daz WITH PASSWORD 'mypassword';
postgres=# \q
Finally, give the new user a database to play with:
$ sudo su postgres -c createdb daz
Pretty straight forward…
Hi Darren,
sudo su postgres -c createdb dazThis did not work for me….I’ve been having this problem since and beginning to think postgresql is a pain }:)
it came up with this error
can you help ..I need to get this right..cheers
Hi ya,
Right, need to check a couple of things first…
$ sudo su postgres -c createdb postgres?If it is the last one (as the error message you are getting suggests this), you are trying to create a database that already exists - you don’t need to create a database for the postgres user as there is one created by default upon install. You only need to create a database for other users that you create.
Let me know if you’re still having troubles.
Hi, No…I did
$ sudo su postgres -c createdb xyz… and got the errorthen I changed to the su user I already created … and I did
$ sudo su newkid -c createdb xyzand I still got the same error:
I however Installed phppgadmin and logged in as the newkid user then created the database xyz from there and it worked.
i don’t know why it won’t do it from the command line.
Cheers
Pingback: Setup PostgreSQL Database server in Ubuntu « Going GNU
$ sudo su postgres -c createdb xyz … and got the error
Gave me exactly the same error message so I separated the steps :
user01~$ sudo su postgres postgres~$ createdb xyz CREATE DATABASE postgres~$ exit user01~$
Worked for me
Strangely, was having the same problem and also the problem that it would not take my password when I tried no sign on. Newbies answer worked for me and made the database and now I can sign on.
Hi Daz, you can also do:
$ sudo su postgres -c psql postgres=# CREATE USER daz WITH PASSWORD ‘mypassword’; postgres=# \q
Instead “ALTER”, supposing “sudo su postgres -c createuser daz” wasn’t executed.
Thanks, and nice blog.
Great post! Was very helpful to me!
I know this is a bit late, but… The “ERROR: database “postgres” already exists” problem is caused by missing quotes. su wants the command and its arguments to be passed in as one argument. So sudo su postgres -c “createdb blah” will create a database called blah. sudo su postgres -c createdb blah (no quotes) seems to be using the default db - which is the same as the username.
Yes it is pretty straight forward. Easy to follow.