This reference is based on Debian. Please do appropriate changes on your own operating system.
Installation
PostgreSQL server is listening on 5432 by default.
Optionally you could choose to install pgAdmin III graphical administration utility.
Add new user and database
After initial installation, a database and database user both named “postgres” are generated automatically. In the mean while, a Linux user called “postgres” is created as well.
You can add new users and databases in different ways.
1). Use PostgreSQL console
Add new Linux user “newuser”:
Switch to user “postgre”:
You can connect to PostgreSQL terminal now.
No need password here as database user name is same with Linux user name.
In terminal, set password to “postgre”:
Then add database user “newuser” and set password.
Create database “mydb” and set owner to “newuser”:
Don’t forget to grant privileges. Otherwise, “newuser” still can’t access “mydb”.
Use “\q” or ctrl+D to quit terminal.
2). Use shell commands
Create database user “newuser” and set him to superuser:
Set password to “newuser” in terminal and quit terminal:
Then create database in shell:
Connect to database
If the current Linux user has same name with database user, you can omit the username in above command and you won’t be asked to provide password.
If there is a database named “newuser”, you can even omit database name.
Twitter · Facebook
Linkedin · Delicious
GitHub · Douban · Xbox Live