0

When I write createdb mydb in the bash terminal. I write the password, but I am getting an error for a user "amodhakal". I have not set up that user, so I was wondering how I can change that user to "postgres" so I can use createdb mydb. Thank You for helping. If more clarification is needed, just let me know!

$ createdb mydb
Password: 
Password: 
createdb: error: connection to server at "localhost" (::1), port 5432 failed: FATAL:  password authentication failed for user "amodhakal"

When I type psql, I get password for user amodhakal. Like I said, that user doesn't exist so I need to delete that user, and change it to "postgres"

psql
Password for user amodhakal:
Amodh
  • 367
  • 1
  • 3
  • 16
  • Like all postgres utility scripts, [`createdb`](https://www.postgresql.org/docs/current/app-createdb.html) takes a `-U` connection parameter option. – Bergi Apr 12 '22 at 20:34
  • I want to be where I can just use createdb without -U like how the invalid user "amodhakal" is – Amodh Apr 12 '22 at 20:36
  • Does this answer your question? [Create database from command line](https://stackoverflow.com/questions/30641512/create-database-from-command-line) – Bergi Apr 12 '22 at 20:36
  • That's just not how `createdb` works. It uses the current shell user (OS account) name if you don't specify a username explicitly. – Bergi Apr 12 '22 at 20:38
  • @bergi is there a way to change that funcitonality from using OS account explicitly to using postgres. I did use ```su - postgres``` from the post you said, but it is saying su: command not found – Amodh Apr 12 '22 at 20:40
  • So you're not on a unixoid OS that has [`su`](https://en.wikipedia.org/wiki/Su_(Unix))? But sure, the way change this functionality and explicitly use the postgres user is `createdb -U postgres …`. What's wrong with that? – Bergi Apr 12 '22 at 20:51
  • 1
    [createdb](https://www.postgresql.org/docs/current/app-createdb.html) is a `libpg` based client so you can use environment variables as shown in the **Environment** section of the `createdb` link to set the connection parameters. In your case `PGUSER`. Though this will become the 'default' user for all `libpq` based clients that are the same environment, unless overridden at the command line. – Adrian Klaver Apr 12 '22 at 21:14
  • @AdrianKlaver That should be an answer. – Laurenz Albe Apr 13 '22 at 06:09

1 Answers1

0

createdb is a libpq based client so you can use environment variables as shown in the Environment section of the createdb link to set the connection parameters. In your case PGUSER. Though this will become the 'default' user for all libpq based clients that are the same environment, unless overridden at the command line. For all the libpq environment variables available see libpq env

Adrian Klaver
  • 15,886
  • 2
  • 17
  • 28