SoFunction
Updated on 2025-04-08

Postgresql default username and password operation

After installing PostgreSQL in the UNIX platform, PostgreSQL will create a user named "postgres" in the UNIX system. PostgreSQL's default username and database are also "postgres".

But there is no default password. After installing PostgreSQL, you can log in as the default user or create a new username.

Log in as default user

Yu @Coat ~ $ sudo su postgres   #Switch to postgrespostgres @Coat /home /Yu $ psql postgres #Login the default database[ sudo ] password for Yu:
psql (9.1.6 )
Type "help" for help.

The above command can also be simplified to:

Yu @Coat ~ $ sudo -u postgres psql postgres

After logging in, set password for the default user "postgres"

postgres= # \password postgres #Set password for postgres userEnter new password:
Enter it again:
postgres= #

Create a new user

The "createuser" command in the UNIX shell can create a user.

sudo -u postgres createuser username #by“postgres”User execution createuser usernameStatement

If there are the following tips

createuser: could not connect to database postgres:
FATAL: role "xxx" does not exist

This is because only postgres users in UNIX systems can use createuser/dropuser to create or delete users (role) in the database.

Additional: PostgreSQL questions about username and password

Today I encountered such a problem when connecting to PostgreSQL, and I was very depressed. Open Postgre to connect to the database, enter password: PWD_A, and the error form keeps popping up.

I thought the password to connect to the server was wrong, but I couldn't enter the password to modify it.

The first problem cannot be solved, check whether the service is not started.

It turns out that the service has not started, and the Postgres client pops up an error message.

I just started the service, but the service cannot start, so it is probably a password problem.

Post "My Computer" -- "Management" -- "User" -- "Postgres",

Reset the user password of Postgres to: PWD_A.

The problem lies here. The password for Postgres in the computer management user is the computer boot password set when installing Postgres.

So just change the user password of Postgres here to set the power-on password at the beginning.

After a long time of struggle, I realized that the Postgres password is different from the client connection server password. Depressed... The reason lies in the fact that I have always believed that the passwords in the two places are the same. What a sucking ~~~~.

Practice tells you everything. . . .

The above is personal experience. I hope you can give you a reference and I hope you can support me more. If there are any mistakes or no complete considerations, I would like to give you advice.