Sometimes, what if I forget the password of the default user Postgres when PostgreSQL is installed?
Linux shell command input below: sudo-u postgres psql (so that you can directly login into the Postgres, and then in the inside can be added users, change passwords and so on, are not the problem!! )
--------------------------------------------------------------------------------------------------------------- --
Modify the Default user postgres password for the PostgreSQL database (note that it is not a Linux system account)
First step: 1, PostgreSQL login (using Psql client login)
# sudo-u Postgres Psql
Among them, Sudo-u Postgres is the use of Postgres user login meaning
PostgreSQL data By default creates a Postgres database user as the administrator of the database, the password is random, so here
Set to ' Postgres '
2. Modify the PostgreSQL login password:
postgres=# ALTER USER postgres with PASSWORD ' postgres ';
postgres= #为PostgreSQL下的命令提示符
3. Exiting the PostgreSQL psql client
postgres=# \q
[code Description]
The characters before ' # ' and ' # ' are the system prompt, ' postgres=# ' is the prompt for the Psql client, and the red character is the input command (the rest of this article is also true);
[function Description]
PostgreSQL data By default will create a Postgres database user as the administrator of the database, the password is random, I need to change to the specified password, which is set to ' Postgres '
Step Two: Modify the Postgres user's password for the Linux system (the password is the same as the password for the database user postgres)
1. Remove the PostgreSQL user password
# sudo passwd-d postgres
Passwd:password expiry information changed.
Passwd-d is the meaning of emptying the specified user password
2. Set the PostgreSQL user password
PostgreSQL data creates a Linux user Postgres by default and modifies the password to ' Postgres ' through the code above (depending on
The password in the second step, as long as it is the same). Now, we can use the Postgres account on the database server to operate the database through Psql or pgadmin and so on clients.
#sudo-U postgres passwd
Enter a new UNIX password:
Re-enter the new UNIX password:
passwd: Password has been successfully updated
Modify the password for the default user postgres of the PostgreSQL database