In this example we, create a database called mytestdatabase
and grant
local access to a "user" called mypsqluser
on mytestdatabase
. Feel
free to change these names.
aptitude install postgresql echo "local mytestdatabase mypsqluser password" >> /etc/postgresql/8.3/main/pg_hba.confOpen /etc/postgresql/8.3/main/pg_hba.conf and move that line just above this line:
local all postgres ident sameuserAfter your edits, that part of pg_hba.conf should read like this:
local mytestdatabase mypsqluser password local all postgres ident sameuserThe point here is that for a certain database
mytestdatabase
the username mypsqluser
should be able to authenticate against the server, even if mypsqluser
does not have a unix account on this computer. Such a setup is preferable to use for integration of apache to postgresql, since it does not require a new user with login possibilities on the server, using the same password as apache does to connect to postgresql.
Now, make postgresql reload its configuration files:
/etc/init.d/postgresql reloadTo create a user
mypsqluser
, do this:
su -s /bin/sh postgresNow, as user postgres, issue
createuser -DRS mypsqluser createdb -O mypsqluser mytestdatabase psql -c "alter USER mypsqluser with password 'pv8D6Z2gnc84ja1'" exit
If you want a postgresql-user with priviledges to create new databases, use -d
rather than -D
.