I installed postgresql but it's asking me for passwords that I never had and never entered. There is a postgres ubuntu user and a database user named moodle. Neither of these were created with a password. Now that my system is asking me for those passwords, what should I do? Why is this process not easy?
$ psql -Umoodle -hlocalhost moodle < /var/www/vcmoodle/moodle/kth-install/moodle_fresh_postgres.sql
Password for user moodle:
psql: fe_sendauth: no password supplied
postgres@dac-VPCSA2Z9E:~$ sudo psql -Umoodle -hlocalhost moodle < /var/www/vcmoodle/moodle/kth-install/moodle_fresh_postgres.sql
[sudo] password for postgres:
postgres@dac-VPCSA2Z9E:~$ sudo -u moodle psql moodle
sudo: unknown user: moodle
sudo: unable to initialize policy plugin
postgres@dac-VPCSA2Z9E:~$ sudo -u postgres psql moodle
postgres is not in the sudoers file. This incident will be reported.
postgres@dac-VPCSA2Z9E:~$ sudo -u dac psql moodle
[sudo] password for postgres:
Sorry, try again.
[sudo] password for postgres:
sudo: 1 incorrect password attempt
postgres@dac-VPCSA2Z9E:~$ sudo -u postgres psql
postgres is not in the sudoers file. This incident will be reported.
postgres@dac-VPCSA2Z9E:~$
Best Answer
In
pg_hba.conf
, you should set:# TYPE DATABASE USER ADDRESS METHOD
Authentication method should be
TRUST
, that will allow you to enter postgres without a password and set it forpostgres
user. Below you see how to change password using SQL:However, you should use
psql
's\password
instead, so the password change (and the password itself) is not logged under any circumstance.From the PostgreSQL 9.4.12 Documentation for
psql
:Of course you should change option
TRUST
to for examplemd5
later for security reasons.