iis服务器助手广告广告
返回顶部
首页 > 资讯 > 数据库 >PostgreSQL中在忘记密码或无权限登录数据库时怎么recover administrator
  • 997
分享到

PostgreSQL中在忘记密码或无权限登录数据库时怎么recover administrator

2024-04-02 19:04:59 997人浏览 安东尼
摘要

这篇文章主要介绍“postgresql中在忘记密码或无权限登录数据库时怎么recover administrator”,在日常操作中,相信很多人在Postgresql中在忘记密码或无权限登录数据库时怎么re

这篇文章主要介绍“postgresql中在忘记密码或无权限登录数据库时怎么recover administrator”,在日常操作中,相信很多人在Postgresql中在忘记密码或无权限登录数据库时怎么recover administrator问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”PostgreSQL中在忘记密码或无权限登录数据库时怎么recover administrator”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

创建数据库,把管理员设置为NOLOGIN

[pg12@localhost ~]$ initdb -D /data/pg12/tmpdb
The files belonging to this database system will be owned by user "pg12".
This user must also own the server process.
The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
Data page checksums are disabled.
creating directory /data/pg12/tmpdb ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default timezone ... PRC
creating configuration files ... ok
running bootstrap script ... ok
perfORMing post-bootstrap initialization ... ok
syncing data to disk ... ok
initdb: warning: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.
Success. You can now start the database server using:
    pg_ctl -D /data/pg12/tmpdb -l logfile start
[pg12@localhost ~]$ pg_ctl -D /data/pg12/tmpdb -l logfile start
waiting for server to start.... done
server started
[pg12@localhost ~]$ psql -U pg12 -c "ALTER ROLE pg12 WITH NOLOGIN" -d postgres
ALTER ROLE

尝试登录数据库,提示无法登录

[pg12@localhost ~]$ psql -d postgres
psql: error: could not connect to server: FATAL:  role "pg12" is not permitted to log in

可通过single user mode处理此类”事故”
关闭数据库

[pg12@localhost ~]$  pg_ctl -D /data/pg12/tmpdb -l logfile stop
waiting for server to shut down.... done
server stopped

以single user mode模式启动数据库

[pg12@localhost ~]$ postgres --single -D /data/pg12/tmpdb postgres
PostgreSQL stand-alone backend 12beta1
backend>

执行维护任务

backend> alter role pg12 with login
backend>

启动数据库,登录

[pg12@localhost ~]$ pg_ctl -D /data/pg12/tmpdb -l logfile start
waiting for server to start.... done
server started
[pg12@localhost ~]$ psql -U pg12 -d postgres
psql (12beta1)
Type "help" for help.
postgres=#

到此,关于“PostgreSQL中在忘记密码或无权限登录数据库时怎么recover administrator”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注编程网网站,小编会继续努力为大家带来更多实用的文章!

您可能感兴趣的文档:

--结束END--

本文标题: PostgreSQL中在忘记密码或无权限登录数据库时怎么recover administrator

本文链接: https://www.lsjlt.com/news/63826.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作