Greenplum:超级管理员权限被删除如何恢复

简介: gpadmin,pg_authid,`postgres --single -P -O -D -p -c gp_session_role=utility`

问题

由于一次误操作,将gpadmin的superuser权限被撤销了,现在创建数据库或者其他用户等命令都是无法执行。

实验

查看pg_authid相关文件

postgres=# \d+ pg_authid;
                           Table "pg_catalog.pg_authid"
      Column       |           Type           | Modifiers | Storage  | Description 
-------------------+--------------------------+-----------+----------+-------------
 rolname           | name                     | not null  | plain    | 
 rolsuper          | boolean                  | not null  | plain    | 
 rolinherit        | boolean                  | not null  | plain    | 
 rolcreaterole     | boolean                  | not null  | plain    | 
 rolcreatedb       | boolean                  | not null  | plain    | 
 rolcatupdate      | boolean                  | not null  | plain    | 
 rolcanlogin       | boolean                  | not null  | plain    | 
 rolconnlimit      | integer                  | not null  | plain    | 
 rolpassword       | text                     |           | extended | 
 rolvaliduntil     | timestamp with time zone |           | plain    | 
 rolconfig         | text[]                   |           | extended | 
 rolresqueue       | oid                      |           | plain    | 
 rolcreaterextgpfd | boolean                  |           | plain    | 
 rolcreaterexthttp | boolean                  |           | plain    | 
 rolcreatewextgpfd | boolean                  |           | plain    | 
 rolcreaterexthdfs | boolean                  |           | plain    | 
 rolcreatewexthdfs | boolean                  |           | plain    | 
Indexes:
    "pg_authid_oid_index" UNIQUE, btree (oid), tablespace "pg_global"
    "pg_authid_rolname_index" UNIQUE, btree (rolname), tablespace "pg_global"
    "pg_authid_rolresqueue_index" btree (rolresqueue), tablespace "pg_global"
Triggers:
    pg_sync_pg_authid AFTER INSERT OR DELETE OR UPDATE ON pg_authid FOR EACH STATEMENT EXECUTE PROCEDURE fl
atfile_update_trigger()
Has OIDs: yes

Tablespace: "pg_global"

postgres=# select oid,relfilenode from pg_class where relname='pg_authid_oid_index';
 oid  | relfilenode 
------+-------------
 2677 |        2677
(1 row)

postgres=# select oid,relfilenode from pg_class where relname='pg_authid_rolname_index';
 oid  | relfilenode 
------+-------------
 2676 |        2676
(1 row)

postgres=# select oid,relfilenode from pg_class where relname='pg_authid_rolresqueue_index';
 oid  | relfilenode 
------+-------------
 6029 |        6029
(1 row)

postgres=# select oid,relfilenode from pg_class where relname='pg_authid';
 oid  | relfilenode 
------+-------------
 1260 |        1260
(1 row)
AI 代码解读

在备份环境下(最好按照生产环境重新创建一份)创建出来足够的用户

​ 模拟创建用户,要求用户名和密码一致才可以(尤其是gpadmin默认密码)

postgres=# create role only_select login password '123456';
NOTICE:  resource queue required -- using default resource queue "pg_default"
CREATE ROLE
AI 代码解读

检查pg_authid的表和索引文件路径并将测试环境下相关路径文件拷贝到生产服务器上

​ $DATA/global/1260

​ $DATA/global/6029

​ $DATA/global/2676

​ $DATA/global/2677

注意替换时这些文件尽量备份

模拟误操作

postgres=# alter role gpadmin  nosuperuser;
ALTER ROLE

postgres=# select * from pg_authid where rolname='gpadmin';                                                
-[ RECORD 1 ]-----+------------------------------------
rolname           | gpadmin
rolsuper          | f
rolinherit        | t
rolcreaterole     | t
rolcreatedb       | t
rolcatupdate      | f
rolcanlogin       | t
rolconnlimit      | -1
rolpassword       | md5b44a9b06d576a0b083cd60e5f875cf48
rolvaliduntil     | 
rolconfig         | 
rolresqueue       | 6055
rolcreaterextgpfd | t
rolcreaterexthttp | t
rolcreatewextgpfd | t
rolcreaterexthdfs | t
rolcreatewexthdfs | t
AI 代码解读

关闭数据库

​ 在关闭数据库前去各个正常的segment的节点上执行命令

$  PGOPTIONS='-c gp_session_role=utility' psql -d postgres -p 6001
select oid,relfilenode from pg_class where relname='pg_authid_oid_index';(都要看看)
AI 代码解读
$ gpstop -af
AI 代码解读

替换所有的数据目录的global下对应的oid名

​ 首先替换的文件要备份出来,防止误操作

​ 其次最好检查一下每个数据节点是否存在这几个文件其次这几个文件是否属于这个表oid文件

最后结果

gpstart -a

postgres=# \du
                        List of roles
  Role name  |            Attributes             | Member of 
-------------+-----------------------------------+-----------
 gpadmin     | Superuser, Create role, Create DB | 
 only_select |                                   | 
AI 代码解读

实验2

将superuser权限取消

postgres=# alter role gpadmin  nosuperuser;
ALTER ROLE
AI 代码解读

正常关闭数据库

$ gpstop -af
AI 代码解读

命令解析

/data2/install-gpdb6/bin/postgres --single -P -O -D /data2/gpdb6/gpAux/gpdemo/datadirs/qddir/demoDataDir-1 -p 6000   -c gp_session_role=utility postgres
AI 代码解读

/data2/install-gpdb6/bin/postgres 数据库安装环境地址

/data2/gpdb6/gpAux/gpdemo/datadirs/qddir/demoDataDir-1数据库数据文件地址

-p 6000 这是数据库启动的端口号(如果不清楚,可以查看/data2/gpdb6/gpAux/gpdemo/datadirs/qddir/demoDataDir-1的postmaster.opts)

postgres这里指的是postgres数据库(默认pg,gp都有该数据库)

进入类似postgresql单用户模式并修改权限命令

​ 假设1个数据库有1个主节点(master),2个数据节点(slave1,slave2),每个数据节点有2个primary(primary1,primary2),2个mirror(mirror1,mirro2)

​ 就要找到各个segment的postmaster.opts(里面有执行的数据文件地址和端口号),然后进入类似postgresql单用户模式

$ /data/greenplum/greenplum-db-4.3.7.2/bin/postgres --single -P -O -D /data/primary2/gpseg1/ -p 40001 -c gp_session_role=utility postgres
PostgreSQL stand-alone backend 8.2.15
backend> alter user gpadmin superuser 
AI 代码解读

​ 使用快捷键CTRL+D就可以退出环境了

后期这里可以验证一下xmin,xmax是否发生变化

​ 这样的话就要前后执行9遍等执行结束后

启动数据库

$ gpstart -a
....
AI 代码解读

小结

两者的思路不同,前者是通过文件替换,后者通过单用户命令模式,相较而言,后者更适合实战

目录
相关文章
【微信小程序】-- uni-app 项目--- 购物车 -- 配置 tabBar 效果(五十一)
【微信小程序】-- uni-app 项目--- 购物车 -- 配置 tabBar 效果(五十一)
云上玩转DeepSeek系列之四:DeepSeek R1 蒸馏和微调训练最佳实践
本文将为您带来“DeepSeek R1+Qwen 大模型蒸馏和微调训练”最佳实践。阿里云 PAI 平台提供了围绕 DeepSeek 模型的最佳实践,涵盖快速部署、应用搭建、蒸馏和微调等环节,帮助开发者高效利用计算资源,使用 Model Gallery 功能,轻松完成部署与微调任务。
数据安全必备:三种实用的数据脱敏技术
在数字化时代,数据安全和隐私保护成为了企业和个人关注的焦点。数据脱敏作为一种有效的数据保护手段,能够降低数据泄露的风险,保护用户隐私。本文将介绍三种常见的数据脱敏方案,帮助您在实际工作中选择合适的脱敏技术。
688 2
Greenplum闭源?平滑迁移到 AnalyticDB 开启Data+AI新范式
知名开源 MPP 数据库 Greenplum 由于其丰富的企业级特性和出色的数据处理能力成为很多企业构建数仓的首选。近期 GP 公开 Github 仓库无法访问仅保留只读归档代码,业界纷纷猜测 GP 即将闭源。云原生数仓 AnalyticDB PostgreSQL 版完全掌控内核代码,完全兼容GP语法,全自研计算及存储引擎较比开源GP有五倍性能提升,全自研企业级特性在实时计算、弹性扩展、安全增强、高可用等方面实现对GP的全面超越,并在数仓能力上扩展了向量检索及一站式 RAG 服务,帮助企业快速构建 AI 应用、开启 Data+AI 新范式。
59395 3
OceanBase的竞争对手是谁?
【8月更文挑战第8天】OceanBase的竞争对手是谁?
314 3
Doris和Greenplum数据库简单对比
【5月更文挑战第3天】Doris和Greenplum数据库简单对比
1813 0
MyBatis-Plus查询工具类
MyBatis-Plus是一个MyBatis的增强工具类库,提供了许多实用的查询工具类。
119 0
OCR文字识别技术总结(一)
OCR (Optical Character Recognition,光学字符识别)是指电子设备(例如扫描仪或数码相机)检查纸上打印的字符,经过检测暗、亮的模式肯定其形状,而后用字符识别方法将形状翻译成计算机文字的过程;即,针对印刷体字符,采用光学的方式将纸质文档中的文字转换成为黑白点阵的图像文件,并经过识别软件将图像中的文字转换成文本格式,供文字处理软件进一步编辑加工的技术。如何除错或利用辅助信息提升识别正确率,是OCR最重要的课题,ICR(Intelligent Character Recognition)的名词也随之产生。
3837 0
OCR文字识别技术总结(一)
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等

登录插画

登录以查看您的控制台资源

管理云资源
状态一览
快捷访问