PostgreSQL中在忘记密码或无权限登录数据库时怎么recover administrator
发表于:2026-11-02 作者:千家信息网编辑
千家信息网最后更新 2026年11月02日,这篇文章主要介绍"PostgreSQL中在忘记密码或无权限登录数据库时怎么recover administrator",在日常操作中,相信很多人在PostgreSQL中在忘记密码或无权限登录数据库时怎
千家信息网最后更新 2026年11月02日PostgreSQL中在忘记密码或无权限登录数据库时怎么recover administrator
这篇文章主要介绍"PostgreSQL中在忘记密码或无权限登录数据库时怎么recover administrator",在日常操作中,相信很多人在PostgreSQL中在忘记密码或无权限登录数据库时怎么recover administrator问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答"PostgreSQL中在忘记密码或无权限登录数据库时怎么recover administrator"的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
创建数据库,把管理员设置为NOLOGIN
[pg12@localhost ~]$ initdb -D /data/pg12/tmpdbThe 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 ... okcreating subdirectories ... okselecting dynamic shared memory implementation ... posixselecting default max_connections ... 100selecting default shared_buffers ... 128MBselecting default timezone ... PRCcreating configuration files ... okrunning bootstrap script ... okperforming post-bootstrap initialization ... oksyncing data to disk ... okinitdb: warning: enabling "trust" authentication for local connectionsYou 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 startwaiting for server to start.... doneserver started[pg12@localhost ~]$ psql -U pg12 -c "ALTER ROLE pg12 WITH NOLOGIN" -d postgresALTER ROLE
尝试登录数据库,提示无法登录
[pg12@localhost ~]$ psql -d postgrespsql: 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 stopwaiting for server to shut down.... doneserver stopped
以single user mode模式启动数据库
[pg12@localhost ~]$ postgres --single -D /data/pg12/tmpdb postgresPostgreSQL stand-alone backend 12beta1backend>
执行维护任务
backend> alter role pg12 with loginbackend>
启动数据库,登录
[pg12@localhost ~]$ pg_ctl -D /data/pg12/tmpdb -l logfile startwaiting for server to start.... doneserver started[pg12@localhost ~]$ psql -U pg12 -d postgrespsql (12beta1)Type "help" for help.postgres=#
到此,关于"PostgreSQL中在忘记密码或无权限登录数据库时怎么recover administrator"的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注网站,小编会继续努力为大家带来更多实用的文章!
数据
数据库
登录
密码
权限
学习
更多
帮助
实用
接下来
事故
任务
文章
方法
模式
理论
知识
管理员
篇文章
网站
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
互联网科技公司起名
互联网科技公司的优势
互联网科技媒体
互联网科技革命
亿账通互联网科技
火传媒上海互联网科技
狮子座互联网科技培训
上海电发互联网科技有限公司
开启互联网科技时代小说
农村开互联网科技讲堂
江苏南京365互联网科技
中国科技互联网公司收入
栖莱科技互联网股份有限公司
宝灵互联网科技有限公司
辽宁互联网新科技
晋城互联网科技
长沙茂晟互联网科技有限公司
互联网科技企业商标注意事项
互联网科技对化妆品行业
颐高云石互联网科技
什么是科技互联网
互联网佳科技有限公司
互联网和科技创新
合肥互联网科技公司
深圳齐家互联网科技
昭通云南众福互联网科技有限公司
岳阳华臻互联网科技有限公司
朱啸虎曾投资哪些互联网科技企业
互联网科技如何创业
云南省自由互联网科技有限公司