I am trying to create a user in PostgreSQL in Mac with the following command
createuser -P project_user
It then prompts
Enter password for new role:
Enter it again:
Password:
I enter thrice the new password for project_user but authentication fails with the below error.
createuser: could not connect to database postgres: FATAL: password authentication failed for user <my_mac_user_name>.
I was able to enter psql terminal with following command and password as 'postgres'
sudo -u postgres psql
\du displays the user project_user.
But same error appears when trying to create database with below command
createdb -O project_user DB_NAME
Related
I follow the official documentation for Windows at https://laravel.com/docs/9.x#getting-started-on-windows.
curl -s https://laravel.build/example-app | bash
cd example-app
./vendor/bin/sail up
Containers are fine and running. I open mysql command line and run:
mysql -h localhost -u root -p
I enter no password (just enter) and I get:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
I have a Windows PostgreSQL installation.
According to some posts, there is no default password set for the 'postgres' user yet I can't connect using an empty password string.
I'm receiving this exception when I try to connect:
Caused by: org.postgresql.util.PSQLException: FATAL: password authentication failed for user "postgres"
The most relevant tip was this:
https://stackoverflow.com/a/25943227/1005607
Open pg_hba.conf
Change md5 -> TRUST
then restart PgAdmin.
I tried that and restarted PGAdmin but it still asks me for the password when I try to connect:
The task manager in Windows shows some PostgreSQL processes are running. I can't switch them off.
I have tried this and it failed:
pg_ctl restart
ERROR:
pg_ctl: no database directory specified and environment variable PGDATA unset
psql.exe postgres
Password: (none)
ERROR:
psql: fe_sendauth: no password supplied
How can I reset the default password for user 'postgres'?
Based on AK47's answer and some additional info I fixed it by doing the following,
1) Stop Postgres if currently running, command line below. Need to give it the 'data' dir. In my case C:\PostgreSQL\data
pg_ctl -D C:\PostgreSQL\data stop
2) Edit the file pg_hba.conf (it's also in the \data dir) as follows:
As AK40 wrote, change all MD5 references to trust , e.g.
# TYPE DATABASE USER ADDRESS METHOD
# 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 replication all 127.0.0.1/32 trust
host replication all ::1/128 trust
3) Now run
psql -U postgres
4) In the PG Command Prompt that appears type,
ALTER USER Postgres WITH PASSWORD '<newpassword>';
5) Save this by typing wq enter to exit the PG Prompt
6) Now start Postgres
pg_ctl -D C:\PostgreSQL\data start
7) Might want to revert the MD5 -> Trust change later in the pg_hba.conf.
Update your pg_hba.conf file to allow for trusted local connections
[root#server] vim pg_hba.conf
>> local all all trust
then restart your PostgreSQL server
[user#machine] pg_ctl -D C:\PostgreSQL\data restart (Windows)
[root#server] service postgresql restart (Linux)
at this point you can connect to your server as postgres user using a local connection without the need to enter a password (omitting the -h parameter when calling the psql command will use a local connection - if you pass -h then this will match the line host all all 0.0.0.0/0 <method> in your pg_hba.conf file)
[root#server] psql -U postgres
You can then alter the postgres user role and set the password to whatever you like using the following command in the psql terminal
[psql] alter role postgres password <new_password>;
Once this is done you can restart your PostgreSQL server again
[user#machine] pg_ctl -D C:\PostgreSQL\data restart (Windows)
[root#server] service postgresql restart (Linux)
and at this point your password should be changed to the new password
I was having the same issue and I couldn't use Postgres in the CLI on my windows machine but I managed to trace down where the passwords were stored via
%APPDATA%\PostgreSQL\pgpass.conf
NB: You must have selected store password option when creating a server or database in the pgAdmin.
I hope this helps. Thanks.
I've previously been using PostgreSQL in Ubuntu using:
$sudo -i -u postgres
to access postgres through the terminal to create a role and database. And then able to log in and make changes using:
$sudo -u [dbname] psql
However now I need to use PostgreSQL with LabVIEW so I've had to download PostgreSQL on a Windows PC. I can access the database through Pgadmin and have created a database but when I go into SQL shell it comes up with:
Server [localhost]:
Database [postgres]:
Port [5432]:
Username [postgres]:
I'm not sure if this has anything to do with roles, as I haven't created one for the windows database. But I can't even get past the above to create a role or make any changes in the command prompt.
When I type my computer host name, it says
psql: could not translate host name "Lisa" to address: Unknown host
It says I am connected on PgAdmin and I am able to create databases and tables through the interface, but I can't figure out how to access it in the SQL Shell (psql).
Entered server as localhost IP.
Server [localhost]: 127.0.0.1
Database [localhost]: [dbname]
Port [5432]: 5432
Username [postgres]: [username]
I run my OpenERP through this command:
ghelo#pc$ /usr/bin/python2 openerp-server -c my_config.conf
I have these as database credentials:
username: odoo
password: some_password
My my_config.conf file has these relative lines:
db_host = False
db_maxconn = 64
db_name = False
db_password = some_password
db_port = False
db_template = template1
db_user = odoo
dbfilter = .*
My pg_hba.conf file has these append, restarting the sevice postgresql at every edit:
host all ghelo all md5
local all odoo trust
However running the server raises this exemption:
FATAL: Peer authentication failed for user "odoo"
My question is, how can i run the OpenERP server?
Other Facts:
odoo has a bash account via: $ sudo useradd odoo
psql: # CREATE USER odoo WITH SUPERUSER LOGIN CREATEDB INHERIT PASSWORD 'some_password';
psql: # CREATE DATABASE odoo OWNER odoo;
Unfortunately I have these limitations:
I cannot run sudo -u odoo COMMAND or any bash command to use a different bash user.
I can only run using /usr/bin/python2.
Bash username and database username cannot be the same.
I feel silly, I have been rule of precedence-ed. The ordering of lines in pg_hba.conf matter. I solved the issue by:
Placing this line:
local all odoo trust
Just before:
# "local" is for Unix domain socket connections only
local all all peer
and then restart your postgresql service from root user using this command:
systemctl restart postgresql.service
I just installed PostgreSQL 9.2 from enterprisedb onto Mac OS X 10.8.2. I mistyped my postgres user password, so I can't connect. How do I reset the password?
Found directions:
sudo su postgres
modify /Library/PostgreSQL/9.2/data/pg_hba.conf
-local all all md5
+local all all trust
restart postgres
/Library/PostgreSQL/9.2/bin/pg_ctl restart -D /Library/PostgreSQL/9.2/data/
Connect to postgres:
psql
Inside psql (\q to quit):
ALTER USER postgres WITH ENCRYPTED PASSWORD 'password';
modify pg_hba.conf back
+local all all md5
-local all all trust
restart postgres
/Library/PostgreSQL/9.2/bin/pg_ctl restart -D /Library/PostgreSQL/9.2/data/