PostgreSQL - Create user/database

Frequently Asked Questions
Locked
mikeb
Posts: 725
Joined: Thu Jul 27, 2006 11:58 am

PostgreSQL - Create user/database

Post by mikeb »

Locate your pg_hba.conf file, usually it is located at: /var/lib/pgsql/data/pg_hba.conf

Once located, edit it and confirm that the "local" line at the bottom has method "password".

# TYPE DATABASE USER CIDR-ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all password
# IPv4 local connections:
host all all 127.0.0.1/32 password
# IPv6 local connections:
host all all ::1/128 password

Restart PostgreSQL to make sure the changes take effect, then
confirm that you are logged in as root and follow the below commands:

[root@timetrex ~]# su postgres
[postgres@timetrex root]$ createuser --interactive -P timetrex
Enter password for new role: <password>
Enter it again: <password>
Shall the new role be a superuser? (y/n) n
Shall the new role be allowed to create databases? (y/n) y
Shall the new role be allowed to create more new roles? (y/n) n
CREATE ROLE

[postgres@timetrex root]$ psql template1 timetrex
Welcome to psql 8.1.1, the PostgreSQL interactive terminal.

Type: \copyright for distribution terms
\h for help with SQL commands
\? for help with psql commands
\g or terminate with semicolon to execute query
\q to quit

template1=> create database timetrex;
CREATE DATABASE
template1=>\q
[postgres@timetrex root]$

You should now be ready to install TimeTrex with the "timetrex" user.

If you made a mistake, the easiest thing to do is drop the user and database and start over again. You can do that with these commands at the shell:

dropuser timetrex
dropdb timetrex
Locked