Re: [GENERAL] createuser: How to specify a database to connect to - Mailing list pgsql-general

From Guillaume Lelarge
Subject Re: [GENERAL] createuser: How to specify a database to connect to
Date
Msg-id CAECtzeWSiuL3DTfra1acXXGS8-nc_HOaUQfW4T2rX80n+4fpEw@mail.gmail.com
Whole thread Raw
In response to [GENERAL] createuser: How to specify a database to connect to  (Schmid Andreas <Andreas.Schmid@bd.so.ch>)
Responses Re: [GENERAL] createuser: How to specify a database to connect to
List pgsql-general
2017-03-13 16:29 GMT+01:00 Schmid Andreas <Andreas.Schmid@bd.so.ch>:
Hi

I'm trying to add a new DB user with the following command from my client machine:
createuser -h my.host.name -U mysuperusername --pwprompt newusername

I'm getting the following message:
createuser: could not connect to database postgres: FATAL:  no pg_hba.conf entry for host "10.0.0.1", user "mysuperusername", database "postgres", SSL on

Now, it's true that our pg_hba.conf doesn't allow access to the postgres database. We did this intentionally, as usually no one needs to connect to this database.

So I tried to do
export PGDATABASE=sogis
before the createuser command. But no success. Does anyone know of another way to achieve what I'm trying?

I whish to do it with createuser rather than with the SQL command CREATE USER because this way I can avoid the password for the new user to show up anywhere in the history.

I'm on 9.2 on Ubuntu 14.04.


You can't. The createuser.c code specifically targets the "postgres" database, which surprises me. Anyway, the only other way to do it is to use psql, something like: psql -c "CREATE USER..." -h ... your_database


--

pgsql-general by date:

Previous
From: Schmid Andreas
Date:
Subject: [GENERAL] createuser: How to specify a database to connect to
Next
From: Tom Lane
Date:
Subject: Re: [GENERAL] createuser: How to specify a database to connect to