在PostgreSQL中恢复postgres用户 [英] Recover postgres user in PostgreSQL

查看:125
本文介绍了在PostgreSQL中恢复postgres用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为 postgres 用户恢复超级用户特权,因为它失去了超级用户资格。

I need to recover the superuser privilege for the postgres user, because it lost the superuser qualification.

我在 psql 外壳中无能为力,它给出了消息

I cannot do anything in the psql shell, it gives the message

must be superuser to create superusers

系统为Ubuntu 16.04和PostgreSQL 9.5。

我可以恢复此 postgres 用户吗?

The system is Ubuntu 16.04 and PostgreSQL 9.5.
Can I recover this postgres user?

推荐答案

从所有用户中删除超级用户特权后,您将必须以单用户模式启动数据库:

If you managed to remove superuser privileges from all your users, you'll have to start the database in single user mode:


  1. 停止数据库服务器作为操作系统用户 postgres

/path/to/postgresql/bin/pg_ctl stop -D /path/to/data/directory


  • 以单用户模式启动服务器:

  • Start the server in single user mode:

    /path/to/postgresql/bin/postgres --single -D /path/to/data/directory postgres
    

    现在您是超级用户。

    还原超级用户特权:

    ALTER ROLE postgres SUPERUSER
    


  • 使用 CTRL + D退出会话kbd>(如果在Windows上,则为 CTRL + Z )。

    重新启动PostgreSQL您通常会这样做。

    Restart PostgreSQL the way you normally do it.

    这篇关于在PostgreSQL中恢复postgres用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆