3

I have installed Postgres v12 on Windows Machine. I have looked documentation of Postgres, but they are using command-line tools commands as

create user <username> etc,

I am using these commands but didn't get Logged into it.It says

fe_sendauth: no password supplied

Sql Shell

How Can I add a user in Postgres psql shell without a password ?

1
  • 1
    An alternative solution is to set a password with \password user1. Commented May 21, 2020 at 18:41

3 Answers 3

7

If you don't want to be prompted for a password, you will need to have provision for that user in your pg_hba.conf file.

For example:

# TYPE  DATABASE        USER            ADDRESS                 METHOD

host    all             user1           0.0.0.0/0               trust
host    all             all             127.0.0.1/32            md5

The first line beginning with "host" uses the method of "trust" which means the user will go unchallenged. You can change any of the other parameters as you see fit, but as long as they hit this rule first, other rules won't insist on a password. Once you make this change, you'll need to reload the service for it to take effect.

Sign up to request clarification or add additional context in comments.

3 Comments

In which directory pg_hba.conf will be located ?
Depends on how your distro is set up, but it's typically in the data directory alongside posgresql.conf. On some distros it can be found under /etc/postgresql/. If you want to know where this is, you can run SHOW data_directory; in psql.
I've updated the example to illustrate the change you need to make. The first line with "host" at the beginning is the line you would need to add. The lines following need to remain in the file unedited in this instance. Note that the example shows a method of "trust" at the end of the line, which means don't prompt for a password. The line that shows "md5" means that it will prompt for a password (using an md5 hash to send it to the database).
0

You can make use of the .pgpass file to automatically provide the password to the postgresql commands.

Create a file ~/.pgpass with the following line:

localhost:*:*:username:

This refers to hostname:port:database:username:password if you want to make it more specific.

https://www.postgresql.org/docs/current/libpq-pgpass.html

Comments

0

In Windows 11, it appears that connections from localhost are defaulting to Ipv6 addressing, so you will want a line like this:

# IPv6 local connections:
host    all             user1             ::1/128                 trust

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.