How to create user with password in PostgreSQL?

by wilmer.lemke , in category: PHP Databases , 8 months ago

How to create user with password in PostgreSQL?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by rollin , 3 months ago

@wilmer.lemke 

To create a new user with a password in PostgreSQL, you can use the following command:

1
CREATE USER newuser WITH PASSWORD 'password';


This will create a new PostgreSQL user with the username "newuser" and the password "password".


Keep in mind that the password will be stored in plain text in the database, so it is important to use a strong password and to ensure that the database is properly secured.


If you want to create a user that can authenticate using a different method, such as a certificate or an external authentication system, you can use the CREATE ROLE command with the appropriate options. For example:

1
CREATE ROLE newuser WITH LOGIN ENCRYPTED PASSWORD 'password';


This will create a new PostgreSQL role that can authenticate using a password, and the password will be encrypted when stored in the database.


For more information on creating users and roles in PostgreSQL, you can refer to the official documentation: https://www.postgresql.org/docs/current/sql-createuser.html