PostgreSQL中在忘记密码或无权限登录数据库时怎么recover administrator
这篇文章主要介绍“PostgreSQL中在忘记密码或无权限登录数据库时怎么recover administrator”,在日常操作中,相信很多人在PostgreSQL中在忘记密码或无权限登录数据库时怎么recover administrator问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”PostgreSQL中在忘记密码或无权限登录数据库时怎么recover administrator”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
创建数据库,把管理员设置为NOLOGIN
[pg12@localhost~]$initdb-D/data/pg12/tmpdbThefilesbelongingtothisdatabasesystemwillbeownedbyuser"pg12".Thisusermustalsoowntheserverprocess.Thedatabaseclusterwillbeinitializedwithlocale"en_US.UTF-8".Thedefaultdatabaseencodinghasaccordinglybeensetto"UTF8".Thedefaulttextsearchconfigurationwillbesetto"english".Datapagechecksumsaredisabled.creatingdirectory/data/pg12/tmpdb...okcreatingsubdirectories...okselectingdynamicsharedmemoryimplementation...posixselectingdefaultmax_connections...100selectingdefaultshared_buffers...128MBselectingdefaulttimezone...PRCcreatingconfigurationfiles...okrunningbootstrapscript...okperformingpost-bootstrapinitialization...oksyncingdatatodisk...okinitdb:warning:enabling"trust"authenticationforlocalconnectionsYoucanchangethisbyeditingpg_hba.conforusingtheoption-A,or--auth-localand--auth-host,thenexttimeyouruninitdb.Success.Youcannowstartthedatabaseserverusing:pg_ctl-D/data/pg12/tmpdb-llogfilestart[pg12@localhost~]$pg_ctl-D/data/pg12/tmpdb-llogfilestartwaitingforservertostart....doneserverstarted[pg12@localhost~]$psql-Upg12-c"ALTERROLEpg12WITHNOLOGIN"-dpostgresALTERROLE
尝试登录数据库,提示无法登录
[pg12@localhost~]$psql-dpostgrespsql:error:couldnotconnecttoserver:FATAL:role"pg12"isnotpermittedtologin
可通过single user mode处理此类”事故”
关闭数据库
[pg12@localhost~]$pg_ctl-D/data/pg12/tmpdb-llogfilestopwaitingforservertoshutdown....doneserverstopped
以single user mode模式启动数据库
[pg12@localhost~]$postgres--single-D/data/pg12/tmpdbpostgresPostgreSQLstand-alonebackend12beta1backend>
执行维护任务
backend>alterrolepg12withloginbackend>
启动数据库,登录
[pg12@localhost~]$pg_ctl-D/data/pg12/tmpdb-llogfilestartwaitingforservertostart....doneserverstarted[pg12@localhost~]$psql-Upg12-dpostgrespsql(12beta1)Type"help"forhelp.postgres=#
到此,关于“PostgreSQL中在忘记密码或无权限登录数据库时怎么recover administrator”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。