I have Postgresql server 8.2 running on a Windows server. I am trying to reset the root postgres account password and just not having any luck. I have so far done the following:
Edited pg_hba.conf to allow:
local all all trust
I then restarted the postgres server so changes could be applied.
Then I opened command prompt and change directory to the bin folder of the postgres installation folder that has all the postgres .exe files.
From what I understand I am supposed to type the following:
psql -U postgres
And at this point it should let me in and should type:
ALTER USER postgres with password 'newpassword';
However, it keeps prompting me for password for user postgres:
And it just does not seem to be working. So from my understanding it seems that the the trust local rule in the pg_hba.conf is not really working correctly.
Update
My pg_hba.conf file only has the following uncommented tags in it:
host all all 127.0.0.1/32 trust
local all all trust
host all all ::1/128 md5
You seem to be asking to change the user on the operating system password. The Postgres user is a user on the the operating system.
Plus you are locked out due to the security hierarchy in Host Based Authentication (HBA)
host all all 127.0.0.1/32 trust
local all all trust
-> host all all ::1/128 md5 <-
NB Loopback Address - ::1/128
::1/128 is the loopback address of the local host which is the equivalent of the 127.0.0.1 in IPv4.
If the postgres user password (as in operating system user) is not set, the postgresq user password is stored
%APPDATA%\postgresql\pgpass.conf
Ref Location of postgresql default user password if not set
On Unix systems, the permissions on .pgpass must disallow any access to world or group; achieve this by the command chmod 0600 ~/.pgpass. If the permissions are less strict than this, the file will be ignored. On Microsoft Windows, it is assumed that the file is stored in a directory that is secure, so no special permissions check is made.
You could update you Host Based Authentication (HBA) file and if you wanted to; change the password for the postgres user on the operating system or windows Then everything should be fine from psql
Hope this helps
Related
I'm a noob in PostgreSQL. I installed ver 9.2 on windows7. During installation it asked for password and i entered it.
Now whenever i run d:\tools\PostgreSQL9.2\bin\psql.exe it asks for password. When i enter the password it doesn't accept and
it shows "password authentication failed for user "user1". I have re-installed twice already. Also i tried entering my system
password.
I'm trying to get the below command to work
psql.exe -f db/codedb.sql development
What should i do to get this working ?
Try setting the user name when connecting.
psql.exe -U username -d dbname -f somefile.sql
You've probably set up the default "postgres" user during installation. Not sure if you've created any others.
To add other users and databases just connect to as postgres to the postgres database and do something like:
CREATE USER myuser WITH ENCRYPTED PASSWORD 'secret';
CREATE DATABASE mydb OWNER myuser;
If your machine is secure you might also like to set up a password file
change "trust" instead of "md5" in the pg_hba.conf to connect to the database and change your password.
--------------------configuration in pg_hba.conf---------------
local all all trust
local all postgres trust
host all all ::1/128 trust
Here is the simple solution for installation Postgresql without getting errors(cluster errors and authentication errors),i have followed below steps and i got installed postgresql sucessfully
create new user in windows from controlpanel-->user accounts
After logged into new user(whic u hve created) copy postrgresql(.exe) application into any directory(other than 'C') and click on the application to install(dont forget to change the installation directory to which u have copied the application file above).
after completion of installaion change below configurations in postgresql.conf and pg_hba.cof
add like below in your postgresql.conf
listen_addresses = '*'
add like below in your pg_hba.cof
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
# host sameuser postgres 127.0.0.1/32 trust
#host replication postgres ::1/128 md5
I'm struggling to get Rails up and running through Windows Bash - for some reason, PostgreSQL is requiring passwords for all TCP/IP connections. It does not prompt for a password when connecting through a unix socket. Ideally my environment would never require a password.
All the advice I can find on this issue points to modifying the pg_hba.conf file. I've edited mine accordingly - there's only one (v9.5). I've reloaded the config via select pg_reload_conf(); and restarted the service to no avail.
# Database administrative login by Unix domain socket
local all postgres trust
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
I've tried to remove the password from the default "postgres" account, but it still requires the password "root" when I try to connect via $ psql -h localhost -U postgres. When I supply no password, I get psql: fe_sendauth: no password supplied and the prompt terminates.
I've created a new role, root, with no password. This has the same behavior, except the password "root" doesn't work - I'm not sure what password it expects, but it does expect one.
Little lost on what to do next. Everything I can find online points to modifying the pg_hba.conf file to look similar to what I have. I've tried uninstalling/reinstalling postgresql packages, but ran into the same problem. Any ideas?
I found my posgresql database server is not asking password for user postgres when remote connecting through pgadmin. I mean this is when I connect to remote database server from my local computer through pgAdmin.
I did add a password in psql, ALTER USER postgres PASSWORD 'mypassword'.
This is my pg_hba.config file:
/usr/local/pgsql/bin/psql -qAt -c "show hba_file" | xargs grep -v -E '^[[:space:]]*#'
local all all trust
host all all 127.0.0.1/32 md5
host all all 0.0.0.0/0 md5
host all all ::1/128 md5
So, I do not quite understand what is happening here.
Can anyone help with this?
Thanks a lot.
UPDATE:
If i change:
local all all trust
to
local all all md5
Now, local connections (via SSH) will be asked for password ( wasn't asking for password before.) but remote connections will still connect without a password.
Acutally, I tried connecting to this database server by a rails appliaction from another server, without a password, and the rails server started without a problem.
PUTTING RESULT HERE FOR THE CONVENIENCE
The real reason of this issue was the .pgpass file. Mac stored the password locally in the .pgpass file under user home folder. Then every time when user try to login without a password, PostgreSQL will send the password for user.
Official doc here
Thanks for all the comments and answers ppl!
But the real reason of this issue was the .pgpass file. My mac stored the password locally in the .pgpass file under my user home folder. Then every time when i try to login without a password, PostgreSQL will send the password for me.
So that was the issue i was having....
Thanks for all the reply and the comments again!
For more details can refer to here
Reading the documentation at Postgresql.org
https://www.postgresql.org/docs/current/auth-pg-hba-conf.html
I would suggest that you change the user field with the names of the few users allowed to connect remotely:
host all john,charles 0.0.0.0/0 scram-sha-256
host all john,charles ::1/128 scram-sha-256
Further, for security reasons, I would advice that you look into using hostssl and also that you specify the name of the database(s) that can be accessed remotely:
hostsll webapp123 john,charles 0.0.0.0/0 scram-sha-256
And if the remote access is only from specific computers, specify their static IP addresses (if DHCP is used, use a mask accordingly.)
hostsll webapp123 john,charles 1.2.3.4/32 scram-sha-256
This way you only compromise database webapp123, to what users john and charles can do, and only from computer 1.2.3.4.
As mentioned in the documentation, you can have any number of entries, so if you want to add a test server (i.e. your server at home) then you can add one line so it looks like this:
hostsll webapp123 john,charles 1.2.3.4/32 scram-sha-256
hostsll webapp123 henry home-ip/32 scram-sha-256
By not specifying the users, you probably allow any user, including those without passwords and one of them is selected and it works...
Of course, I would strongly advice that you do not name a user who has administration rights in your database unless you also specify his static IP address.
I'm trying to register new server in pgadmin3 with following settings:
Name: postgres
Host: localhost
Username: postgres
Password: <password which works for psql>
Service: empty or postgres
But it shows error:
FATAL: Ident authentification failed for user "postgres"
I've restarted postgresql service, but to no avail.
Contents of /var/lib/pgsql/data/pg_hba.conf:
# TYPE DATABASE USER CIDR-ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 ident
EDIT: Tools -> Server Configuration -> pg_hba.conf is greyed out.
It looks like PgAdmin-III is probably connecting over IPv6 by default, so it's using the ident line that matches the IPv6 address for localhost, ::1/128.
If you want to use password authentication, you probably want:
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
I'm not sure why you have the unix domain socket line set to trust, but that's probably OK if it's just a development machine, so leave it unchanged. It's really much safer to have it as ident (if you want the unix user to have to be the same as the Pg user) or md5 (for password auth on local unix sockets) though.
You'll need to edit pg_hba.conf directly in a text editor if PgAdmin-III doesn't have permissions to edit it. You could run PgAdmin-III as user postgres via sudo, but it's way safer (and probably easier) to just use nano or a similar command-line text editor to modify pg_hba.conf.
The password works for psql because psql will, unless told otherwise, connect over a unix domain socket, and you have that set to trust. You'll probably find you could give any password to psql and it'll still work, because it's never being asked to actually give the password, it's just being automatically trusted.
Yes this type of error is seen by every newbie user to pgadmin.
I have found this solution and it worked for me.
sudo -u postgres psql
This will ask for your system password and then you will get the postgres prompt.
and then in psql type below command to change the password.
\password
now enter the new password and re-enter it.
PostGreSQL Account Debugging Steps (Linux Specific):
Make sure you actually have it installed (not just the client, the server too).
Make sure it is running.
Make sure you know where this is - usually in /var/lib/pgsql/data - however this could be anywhere - /var/lib/pgsql/unrelated-instance. Check your postgres process to see which directory (-D argument) this is.
Modify the pg_hba.conf file in the directory from the last step. I have no idea why this step isn't in the postgres documentation.
The specific configuration has been covered in e.g. Jay and Craig Ringer's answer. Make sure to configure both IPV4 and IPV6.
Restart the server.
Test that your configuration worked. Repeat 5-7 until you can login successfully.
Important Don't stop! Now you should configure a more secure password option - postgres may be fine for doing quick local setup, but you want to be using a more secure, configurable authentication mechanism, like LDAP, Kerberos, or GSSAPI. Additionally, you want to make sure you have SSL turned on.
I'm a noob in PostgreSQL. I installed ver 9.2 on windows7. During installation it asked for password and i entered it.
Now whenever i run d:\tools\PostgreSQL9.2\bin\psql.exe it asks for password. When i enter the password it doesn't accept and
it shows "password authentication failed for user "user1". I have re-installed twice already. Also i tried entering my system
password.
I'm trying to get the below command to work
psql.exe -f db/codedb.sql development
What should i do to get this working ?
Try setting the user name when connecting.
psql.exe -U username -d dbname -f somefile.sql
You've probably set up the default "postgres" user during installation. Not sure if you've created any others.
To add other users and databases just connect to as postgres to the postgres database and do something like:
CREATE USER myuser WITH ENCRYPTED PASSWORD 'secret';
CREATE DATABASE mydb OWNER myuser;
If your machine is secure you might also like to set up a password file
change "trust" instead of "md5" in the pg_hba.conf to connect to the database and change your password.
--------------------configuration in pg_hba.conf---------------
local all all trust
local all postgres trust
host all all ::1/128 trust
Here is the simple solution for installation Postgresql without getting errors(cluster errors and authentication errors),i have followed below steps and i got installed postgresql sucessfully
create new user in windows from controlpanel-->user accounts
After logged into new user(whic u hve created) copy postrgresql(.exe) application into any directory(other than 'C') and click on the application to install(dont forget to change the installation directory to which u have copied the application file above).
after completion of installaion change below configurations in postgresql.conf and pg_hba.cof
add like below in your postgresql.conf
listen_addresses = '*'
add like below in your pg_hba.cof
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
# host sameuser postgres 127.0.0.1/32 trust
#host replication postgres ::1/128 md5