EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login

PostgreSQL User Password

Home » Data Science » Data Science Tutorials » PostgreSQL Tutorial » PostgreSQL User Password

PostgreSQL User Password

Introduction to PostgreSQL User Password

PostgreSQL provides user management facility, in which we can create user, can create password for the user, change password of specified user. Also we can update the role of user, delete password of the user. User password is very important in PostgreSQL because it maintains the security of the database management system. The user management plays an important role in the database administration of systems. Under user management we can change the role of the user as well as change the password of the user to maintain a safe environment.

How does Sort Function work in PostgreSQL?

  • We must install PostgreSQL in our system.
  • We require basic knowledge about PostgreSQL.
  • We must require users to perform different operations.
  • We must need basic knowledge about user management that means how it is used.
  • We can perform different operations on users with the help of psql and pgAdmin.

How to Create a Password for Users in PostgreSQL?

First we see how to create users in PostgreSQL.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

Following statement is used to create a password for the user.

Syntax:

create user user  name;

Explanation:

  • In above syntax where create user or role statement is used to create user or role in PostgreSQL and user name means specified user name or role name. Here we just create users without any privilege. Second syntax also used to create user through the psql terminal.

Example:

Code:

create user sam;

In the above example we use a create statement to create a user and sam is a new user that we need to create.

Illustrate the end result of the above declaration by using the use of the following snapshot.

Output:

PostgreSQL User Password 1

Now we have the same user, so we create a password for the sam user using the following syntax.

Syntax:

alter user    user name   password ‘XXXXXXXX’;

Explanation:

  • In the above syntax we use an alter user or role statement to create a password for the user, where user name is specified user name which we need to assign password by using password keyword.

Example:

Code:

alter user sam password ‘123456’;

Explanation:

  • In the above example we use an alter user statement, where sam is a specified user name and we assign a password to sam user by using the above statement.
  • Illustrate the end result of the above declaration by using the use of the following snapshot.

Output:

PostgreSQL User Password 2

How to Change a Password for the User in PostgreSQL?

If we change the password time to time then it is convenient to protect data and a safe environment can be maintained to users. In this type, suppose we need to change the user password. At that time we used the following syntax and it was an easy method to change passwords.

Syntax:

alter  user  user  name  with password  ‘xxxxxxx’;

Explanation:

  • In above syntax we use alter user or role statement, where name is the specified user name and with and password is a keyword to change user password, where user name means specified user name and new password for that user.

Example:

Suppose we need to change the password of sam user at that time we use the following statement.

Code:

alter  user sam with  password 'sam123';

Explanation:

  • In the above statement we used alter user statement, where sam is specified user name and with, password is a keywords used to change password of sam user.
  • Illustrate the end result of the above declaration by using the use of the following snapshot.

Output:

PostgreSQL User Password 3

Suppose after some days we want to change the password of the user or update password of user at that time we provide a valid date to the user password. Now see how we can provide validity to the password of the specified user.

Syntax:

alter   user   user   name with  password  ‘xxxxxxx’ valid until  timestamp;

Explanation:

  • In above syntax we use alter user or role statement where user name means specified user name with, password and valid until is a keyword to assign password and timestamp to the user.
  • Timestamp means assigning a valid date of password to a specific user.

Example:

Code:

alter   user   sam with password 'sam123' valid until   '1 August 2020';

Explanation:

  • In above example we use alter user statement, where sam is specified user name and we assign password to sam user with valid date of password. Here the assigned password is sma123 and valid until 1 August 2020.
  • Illustrate the end result of the above declaration by using the use of the following snapshot.

Output:

we assign password to sam

How to Delete a Password for the User in PostgreSQL?

In this type, suppose we need to delete the password of the user. But when we delete the password it cannot protect data as well as the safe environment of the user at that time we use the following syntax.

Syntax:

alter  user   user name   with  password  null;

Explanation:

  • In the above syntax we use an alter user or role statement.
  • Where user name means specified user name, with and password is the keywords it is used to assign password to specific user in above syntax we use null keyword for assign null password.

Example:

Code:

alter user  sam  with  password  null;

Explanation:

  • In the above statement where we use the alter user statement, sam is specified user name, where with and password is the keywords and null indicates password is null for sam user.
  • Illustrate the end result of the above declaration by using the use of the following snapshot.

Output:

 sam is specified user name

Conclusion

From the above article we saw basic syntax of create user, create password, change password and delete password. We also saw how we can implement them in PostgreSQL with different examples of each type. In this article we saw how we can maintain security of data and how we can maintain a safe environment. From this article we saw how we can handle User Passwords in PostgreSQL on the server.

Recommended Articles

This is a guide to PostgreSQL User Password. Here we discuss the introduction, how sort function works? how to create, change and delete password for users in PostgreSQL? You may also have a look at the following articles to learn more –

  1. PostgreSQL IS NULL
  2. PostgreSQL DDL
  3. PostgreSQL ORDER BY Random
  4. PostgreSQL Clone Database

All in One Data Science Bundle (360+ Courses, 50+ projects)

360+ Online Courses

50+ projects

1500+ Hours

Verifiable Certificates

Lifetime Access

Learn More

0 Shares
Share
Tweet
Share
Primary Sidebar
PostgreSQL Tutorial
  • Basic
    • What is PostgreSQL
    • PostgreSQL Features
    • How to Install PostgreSQL
    • PostgreSQL Versions
    • PostgreSQL Architecture
    • PostgreSQL GUI
    • Postgres Command-Line
    • PostgreSQL Variables
    • PostgreSQL Data Types
    • PostgreSQL NOT NULL
    • PostgreSQL Integer
    • PostgreSQL Boolean
    • PostgreSQL BIGINT
    • PostgreSQL NULLIF
    • PostgreSQL Administration
    • PostgreSQL Commands
    • PostgreSQL Operators
    • PostgreSQL IN Operator
    • Postgres like query
    • PostgreSQL encode
    • PostgreSQL Cheat Sheet
    • PostgreSQL List Databases
    • PostgreSQL Rename Database
  • Control Statement
    • PostgreSQL IF Statement
    • PostgreSQL if else
    • PostgreSQL CASE Statement
    • PostgreSQL LOOP
    • PostgreSQL For Loop
    • PostgreSQL While Loop
  • Joins
    • Joins in PostgreSQL
    • PostgreSQL Inner Join
    • PostgreSQL Outer Join
    • LEFT OUTER JOIN in PostgreSQL
    • PostgreSQL FULL OUTER JOIN
    • PostgreSQL LEFT JOIN
    • PostgreSQL Full Join
    • PostgreSQL Cross Join
    • PostgreSQL NATURAL JOIN
    • PostgreSQL UPDATE JOIN
  • Queries
    • PostgreSQL Queries
    • PostgreSQL INSERT INTO
    • PostgreSQL WHERE Clause
    • PostgreSQL WITH Clause
    • PostgreSQL ORDER BY
    • PostgreSQL ORDER BY Random
    • PostgreSQL ORDER BY DESC
    • PostgreSQL GROUP BY
    • PostgreSQL group_concat
    • PostgreSQL HAVING
    • PostgreSQL Recursive Query
  • Advanced
    • PostgreSQL Schema
    • Postgres List Schemas
    • PostgreSQL Drop Schema
    • PostgreSQL VARCHAR
    • Array in PostgreSQL
    • PostgreSQL DDL
    • PostgreSQL List Users
    • Postgres Default User
    • Postgres add user
    • PostgreSQL User Password
    • PostgreSQL log_statement
    • PostgreSQL repository
    • PostgreSQL shared_buffer
    • PostgreSQL String Functions
    • PostgreSQL Compare Strings
    • PostgreSQL Text Search
    • PostgreSQL TEXT
    • PostgreSQL String Array
    • PostgreSQL where in array
    • PostgreSQL Constraints
    • PostgreSQL UNIQUE Constraint
    • PostgreSQL CHECK Constraint
    • PostgreSQL INTERSECT
    • PostgreSQL Like
    • Cursors in PostgreSQL
    • PostgreSQL UNION ALL
    • Indexes in PostgreSQL
    • PostgreSQL Index Types
    • PostgreSQL REINDEX
    • PostgreSQL UNIQUE Index
    • PostgreSQL Clustered Index
    • PostgreSQL DROP INDEX
    • PostgreSQL DISTINCT
    • PostgreSQL FETCH
    • PostgreSQL RAISE EXCEPTION
    • PostgreSQL Auto Increment
    • Sequence in PostgreSQL
    • Wildcards in PostgreSQL
    • PostgreSQL Subquery
    • PostgreSQL Alias
    • PostgreSQL LIMIT
    • PostgreSQL Limit Offset
    • PostgreSQL LAG()
    • PostgreSQL Table
    • Postgres Show Tables
    • PostgreSQL Describe Table
    • PostgreSQL Lock Table
    • PostgreSQL ALTER TABLE
    • Postgres Rename Table
    • PostgreSQL List Tables
    • PostgreSQL TRUNCATE TABLE
    • PostgreSQL Table Partitioning
    • Postgres DROP Table
    • PostgreSQL Functions
    • PostgreSQL Math Functions
    • PostgreSQL Window Functions
    • Aggregate Functions in PostgreSQL
    • PostgreSQL Primary Key
    • Foreign Key in PostgreSQL
    • PostgreSQL Procedures
    • PostgreSQL Stored Procedures
    • PostgreSQL Views
    • PostgreSQL Materialized Views
    • Postgres Create View
    • PostgreSQL Triggers
    • PostgreSQL DROP TRIGGER
    • PostgreSQL Date Functions
    • PostgreSQL TO_DATE()
    • PostgreSQL datediff
    • PostgreSQL Timestamp
    • PostgreSQL CURRENT_TIMESTAMP()
    • PostgreSQL Notify
    • PostgreSQL LENGTH()
    • PostgreSQL blob
    • PostgreSQL Median
    • PostgreSQL kill query
    • PostgreSQL Formatter
    • PostgreSQL RANK()
    • PostgreSQL Select
    • PostgreSQL Average
    • PostgreSQL DATE_PART()
    • PostgreSQL EXECUTE
    • PostgreSQL COALESCE
    • PostgreSQL EXTRACT()
    • PostgreSQL Sort
    • PostgreSQL TO_CHAR
    • PostgreSQL Interval
    • PostgreSQL Number Types
    • PostgreSQL ROW_NUMBER
    • Alter Column in PostgreSQL
    • PostgreSQL Identity Column
    • PostgreSQL SPLIT_PART()
    • PostgreSQL CONCAT()
    • PostgreSQL replace
    • PostgreSQL TRIM()
    • PostgreSQL MAX
    • PostgreSQL DELETE
    • PostgreSQL Float
    • PostgreSQL OID
    • PostgreSQL log
    • PostgreSQL REGEXP_MATCHES()
    • PostgreSQL MD5 
    • PostgreSQL NOW()
    • PostgreSQL RANDOM
    • PostgreSQL round
    • PostgreSQL Trunc()
    • PostgreSQL TIME
    • PostgreSQL IS NULL
    • PostgreSQL CURRENT_TIME
    • PostgreSQL MOD()
    • Postgresql Count
    • PostgreSQL Datetime
    • PostgreSQL MIN()
    • PostgreSQL age()
    • PostgreSQL enum
    • PostgreSQL OR
    • PostgreSQL Wal
    • PostgreSQL NOT IN
    • PostgreSQL SET
    • PostgreSQL Current Date
    • PostgreSQL Compare Date
    • PostgreSQL SERIAL
    • PostgreSQL UUID
    • PostgreSQL Merge
    • PostgreSQL Database
    • PostgreSQL Clone Database
    • PostgreSQL Copy Database
    • PostgreSQL Show Databases
    • PostgreSQL Restore Database
    • PostgreSQL DROP DATABASE
    • PostgreSQL ALTER DATABASE
    • Postgres DROP Database
    • Postgres Dump Database
    • PostgreSQL OFFSET
    • PostgreSQL GRANT
    • PostgreSQL COMMIT
    • PostgreSQL ROLLUP
    • PostgreSQL JSON
    • EXPLAIN ANALYZE in PostgreSQL
    • PostgreSQL Temporary Table
    • PostgreSQL Show Tables
    • PostgreSQL cluster
    • PostgreSQL Replication
    • PostgreSQL Logical Replication
    • PostgreSQL flush privileges
    • PostgreSQL Tablespaces
    • CAST in PostgreSQL
    • PostgreSQL CTE
    • hstore in PostgreSQL
    • PostgreSQL Encryption
    • PostgreSQL DECODE()
    • PostgreSQL Vacuum
    • PostgreSQL EXCLUDE
    • Postgres Change Password
    • Postgres Delete Cascade
    • PostgreSQL EXCEPT
    • PostgreSQL Roles
    • PostgreSQL Link
    • PostgreSQL Partition
    • PostgreSQL column does not exist
    • PostgreSQL Log Queries
    • PostgreSQL escape single quote
    • PostgreSQL Query Optimization
    • PostgreSQL Character Varying
    • PostgreSQL Transaction
    • PostgreSQL Extensions
    • PostgreSQL Import CSV
    • PostgreSQL Client
    • PostgreSQL caching
    • PostgreSQL Incremental Backup
    • PostgreSQL JSON vs JSONNB
    • PostgreSQL JDBC Driver
    • PostgreSQL Interview Questions
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Special Offer - All in One Data Science Bundle (360+ Courses, 50+ projects) Learn More