PostgreSQL 实现登录及修改密码操作

postgresql登录

1、可通过客户端pgadmin iii直接登录

2、可通过命令行

命令:psql -h 10.10.10.10 -u user -d postgres -p 5570

-h:数据库ip

-u:登录用户

-d:登录的数据库

-p:登录端口

方法:进入postgresql的客户端安装目录(我的安装目录:c:\program files\postgresql\9.4\bin),执行psql命令,其中\q表示退出数据库

修改密码

直接执行以下sql即可修改密码

alter user pguser with password 'new password';

补充:postgresql修改密码认证方式

我就废话不多说了,大家还是直接看代码吧~

[postgres@postgres_vm ~]$ psql
psql (12.4)
type "help" for help.
postgres=# show password_encryption ;
 password_encryption
---------------------
 md5
(1 row)
postgres=# select * from pg_authid where rolname='hr';
 oid | rolname | rolsuper | rolinherit | rolcreaterole | rolcreatedb | rolcanlogin | rolreplication | rolbypassrls | rolconnlimit |       r
olpassword       | rolvaliduntil
-------+---------+----------+------------+---------------+-------------+-------------+----------------+--------------+--------------+--------------
-----------------------+---------------
 16386 | hr   | f    | t     | f       | f      | t      | f       | f      |      -1 | md566ad2e6b6f
adaa9fd11bfcab906e84c8 |
(1 row)
postgres=# set password_encryption to "scram-sha-256";
set
postgres=# select * from pg_authid where rolname='hr';
 oid | rolname | rolsuper | rolinherit | rolcreaterole | rolcreatedb | rolcanlogin | rolreplication | rolbypassrls | rolconnlimit |       r
olpassword       | rolvaliduntil
-------+---------+----------+------------+---------------+-------------+-------------+----------------+--------------+--------------+--------------
-----------------------+---------------
 16386 | hr   | f    | t     | f       | f      | t      | f       | f      |      -1 | md566ad2e6b6f
adaa9fd11bfcab906e84c8 |
(1 row)
postgres=# alter user hr with password 'abcd1234';
alter role
postgres=# select * from pg_authid where rolname='hr';
 oid | rolname | rolsuper | rolinherit | rolcreaterole | rolcreatedb | rolcanlogin | rolreplication | rolbypassrls | rolconnlimit |
                        rolpassword                               | rolvaliduntil
-------+---------+----------+------------+---------------+-------------+-------------+----------------+--------------+--------------+--------------
-------------------------------------------------------------------------------------------------------------------------+---------------
 16386 | hr   | f    | t     | f       | f      | t      | f       | f      |      -1 | scram-sha-256
$4096:df5wnznkgxen0mtqzewlda==$2k8sshkearhox93x5hmijkspxhecxdkjz56erjif+du=:fbby3+22nvxf83lbfk6dhbk2qpakja/0rri3oxs4cdi= |
(1 row)
postgres=#

以上为个人经验,希望能给大家一个参考,也希望大家多多支持www.887551.com。如有错误或未考虑完全的地方,望不吝赐教。

(0)
上一篇 2022年3月21日
下一篇 2022年3月21日

相关推荐