after initdb - Re: How to CREATEDB in commandline with no prompt for password - Mailing list pgsql-admin

From bwnabble
Subject after initdb - Re: How to CREATEDB in commandline with no prompt for password
Date
Msg-id 15817886.post@talk.nabble.com
Whole thread Raw
In response to Re: How to create a new user with password in commandline with no prompt for password  ("Rajiv Rajaian" <rajiv.pgsql@gmail.com>)
Responses Re: after initdb - Re: How to CREATEDB in commandline with no prompt for password  (Shane Ambler <pgsql@Sheeky.Biz>)
List pgsql-admin


Rajiv Rajaian-2 wrote:
>
> [root@g151 ~]# su postgres -c "createdb postgres"
> could not change directory to "/root"
> CREATE DATABASE
> [root@g151 ~]# echo "CREATE USER globus WITH PASSWORD 'globus' CREATEDB;"
> |
> psql -U postgres -d postgres
> psql: FATAL:  Ident authentication failed for user "postgres"
> [root@g151 ~]# su postgres -c "echo \"CREATE USER globus WITH PASSWORD
> 'globus' CREATEDB;\" | psql -U postgres -d postgres"
> could not change directory to "/root"
> CREATE USER
> [root@g151 ~]# su globus -c "createdb rftDatabase"
> could not change directory to "/root"
> CREATE DATABASE
>

Rajiv,

Did you have your METHODs set to "trust" in your "pg_hba.conf" file (in the
$PGDATA directory)?

My question is, similar to yours, is there a way to:
1) run "initdb" as user "postgres" on an empty $PGDATA directory to start
from scratch
2) change the METHODs in "$PGDATA/pg_hba.conf" from "trust" -> "password"
3) start the postgresql server
4) run "createdb mydb" with no prompt for a password? (as user root or
postgres?)

I can only perform step 4 (createdb mydb) when the default METHOD is "trust"
in pg_hba.conf and I'm wondering if is any way around it?  I want to disable
"trust" for security purposes.

Must I use the METHOD "trust" first in order to create a user with
"createdb" privileges, and then change METHODs in pg_hba.conf from "trust"
to "password"?

--
View this message in context:
http://www.nabble.com/How-to-create-a-new-user-with-password-in-commandline-with-no-prompt-for-password-tp15583904p15817886.html
Sent from the PostgreSQL - admin mailing list archive at Nabble.com.


pgsql-admin by date:

Previous
From: Mary Anderson
Date:
Subject: Re: Documenting a DB schema
Next
From: bwnabble
Date:
Subject: after initdb - Re: How to CREATEDB in commandline with no prompt for password