JIYIK CN >

Current Location:Home > Learning > DATABASE > PostgreSQL >

Changing User Password in Postgres

Author:JIYIK Last Updated:2025/04/27 Views:

In this article, we will change the user password in Postgres.

Changing User Passwords in Postgres Using Windows

  • Open from the menu or search bar SQL Shell (psql).
  • Connect to the default database using the default port. If you set it up with the defaults, your configuration should look like this:
    Server [localhost]:
    Database [postgres]:
    Port [5432]:
    Username [postgres]:
    Password for user postgres:

If you leave the field empty and press empty, it will take on the default value shown between the square brackets.

Then, log in using the default password you set during installation. If you are successful, you will get the SQL command line:

psql (14.0)
WARNING: Console code page (437) differs from Windows code page (1252)
         8-bit characters might not work correctly. See psql reference
         page "Notes for Windows users" for details.
Type "help" for help.

postgres=#

Now, if you want to see usera list of all, type the command:

postgres=# select * from USER;
   user
----------
 postgres
(1 row)

You need to use ALTERChange User Information to change the user password. The modified 用户密码query format is:

postgres=# ALTER USER postgres WITH PASSWORD 'ROOT';
ALTER ROLE
postgres=#

You can enter the password you want to update 用户名instead, postgresand you can use the password you defined instead Root.

Alternatively, there is another way to change your password without writing any SQL queries. psqlOnce the command line is open, enter \password user_name.

It will then ask for 新密码and again ask to re-enter the new password.

postgres=# \password postgres
Enter new password: <Enter-your-password>
Enter it again: <Retype-your-password>
postgres=#

Changing User Password in Postgres Using Linux

You can enter psqlthe console without any password. Use sudothe command.

Here's psqlhow you can log in without a password:

$sudo -u <username> psql <database>

Use the above method to change psqlthe password of the user in .

It is best to encrypt the user password and save it. You can use the following command:

postgres=# ALTER USER postgres WITH ENCRYPTED PASSWORD 'ROOT';

For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.

Article URL:

Related Articles

Killing a process ID in PostgreSQL

Publish Date:2025/04/27 Views:191 Category:PostgreSQL

Today, we will learn how to kill or stop a running query in the background when working with PostgreSQL database. This may happen if the frontend stops working but a background process is still running. In this case, you may want to kill th

How to install and deploy PostgreSQL as a Docker container

Publish Date:2025/04/27 Views:50 Category:PostgreSQL

PostgreSQL , also known as Postgres, is a leading object-relational database system. It is popular because it is highly compliant with the SQL standard and includes additional features that simplify processing complex data sets at scale. Po

Add unique constraint after creating table in PostgreSQL

Publish Date:2025/04/27 Views:63 Category:PostgreSQL

Today we will learn how to add constraints after the rows in a table have been created UNIQUE . The UNIQUE constraint guarantees that the data in a row is unique in that column. So if the column ID exists, all rows will have unique values,

Creating a Schema in PostgreSQL

Publish Date:2025/04/27 Views:196 Category:PostgreSQL

This article will discuss creating schemas in PostgreSQL using SQL queries or psql. CREATE SCHEMA Use the statement to create a pattern in SQL query To create a new schema, execute the following command. CREATE SCHEMA test_schema To view al

Terminate the PostgreSQL connection

Publish Date:2025/04/11 Views:200 Category:PostgreSQL

In this article, we will learn how to terminate a PostgreSQL session. Any open connections are run by background processes or tasks, PSQL which may no longer exist despite exiting the user interface or command line tool. Use ps -ef or grep

Single query to rename and change column type in PostgreSQL

Publish Date:2025/04/11 Views:166 Category:PostgreSQL

This article describes how to rename a column and change its type in PostgreSQL using only a single query. Renaming and changing column types in MySQL In MySQL , if you want to change the column type and rename it, you can use a simple stat

Joining columns using Select in PostgreSQL

Publish Date:2025/04/11 Views:177 Category:PostgreSQL

MySQL PostgreSQL is an object-relational database system, which means it can support more complex data types than its competitors . Today we will learn how to use SELECT the operator to join the columns of a table. Using operators to || joi

Scan to Read All Tech Tutorials

Social Media
  • https://www.github.com/onmpw
  • qq:1244347461

Recommended

Tags

Scan the Code
Easier Access Tutorial