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)

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

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

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

检查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

关闭数据库

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

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

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

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

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

最后结果

gpstart -a

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

实验2

将superuser权限取消

postgres=# alter role gpadmin  nosuperuser;
ALTER ROLE

正常关闭数据库

$ gpstop -af

命令解析

/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

/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 

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

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

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

启动数据库

$ gpstart -a
....

小结

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

目录
相关文章
|
11月前
|
人工智能 自然语言处理 安全
AI技术对英语学习的改进
AI正重塑英语学习:从工具升级为“全天候数字教育基建”。2026年,智能语伴具备长期记忆与主动交互;多模态技术实现口型/肢体精准纠偏;“i+1”动态分级适配兴趣与水平;写作指导聚焦逻辑与思维润色;教师获AI赋能,实现精准教学与高效备课。(239字)
|
9月前
|
云安全 运维 监控
阿里云CDN应急响应服务方案(转载)
阿里云推出CDN应急响应服务,提供7×24小时故障与安全双重保障:故障方面分级响应、专家快速定位修复;安全方面支持远程/现场处置,涵盖攻击遏制、恶意程序清理、溯源分析及加固指导,全面提升CDN稳定性与安全性。(239字)
667 1
阿里云CDN应急响应服务方案(转载)
|
存储 人工智能 搜索推荐
详解MySQL字符集和Collation
MySQL支持了很多Charset与Collation,并且允许用户在连接、Server、库、表、列、字面量多个层次上进行精细化配置,这有时会让用户眼花缭乱。本文对相关概念、语法、系统变量、影响范围都进行了详细介绍,并且列举了有可能让字符串发生字符集转换的情况,以及来自不同字符集的字符串进行比较等操作时遵循的规则。对于最常用的基于Unicode的字符集,本文介绍了Unicode标准与MySQL中各个字符集的关系,尤其详细介绍了当前版本(8.0.34)默认字符集utf8mb4。
|
12月前
|
XML Java 数据格式
SpringBoot@Configuration使用总结
被@Configuration标注的类视为Spring配置类,等同于XML配置文件。通过@Bean注册Bean,结合AnnotationConfigApplicationContext可启动IOC容器,加载并管理Bean实例,包括配置类自身。
|
机器学习/深度学习 人工智能 搜索推荐
从零构建短视频推荐系统:双塔算法架构解析与代码实现
短视频推荐看似“读心”,实则依赖双塔推荐系统:用户塔与物品塔分别将行为与内容编码为向量,通过相似度匹配实现精准推送。本文解析其架构原理、技术实现与工程挑战,揭秘抖音等平台如何用AI抓住你的注意力。
3225 7
从零构建短视频推荐系统:双塔算法架构解析与代码实现
|
人工智能 监控 数据挖掘
AiPy发布第五期大模型适配度测评报告:Claude、GLM、豆包位居前三,美团LongCat落后
10月13日,AiPy发布《大模型适配度测评第五期报告》,覆盖20款国内外主流大模型,聚焦数据分析、编程开发、UI设计等十大真实场景。报告从成功率、资源消耗、速度等多维度综合评估,Claude-Sonnet-4以90%成功率位居榜首,GLM-4.5、Doubao-Seed-1.6等国产模型表现亮眼,展现中国AI技术进步。测评发现代码质量、中文支持、任务规划仍是主要挑战,为用户选型与模型优化提供重要参考。
|
边缘计算 人工智能 监控
CC攻击防御指南:实战策略与技术解析
本文详解了2025年严峻的CC攻击形势及七大实战防护策略。涵盖流量监控、智能清洗、WAF防护、身份认证升级、应急响应与前沿技术应用,助力企业构建高效、自适应的安全防御体系,应对日益复杂的网络威胁。
1026 0
CC攻击防御指南:实战策略与技术解析
|
关系型数据库 分布式数据库 数据库
阿里云PolarDB数据库蝉联SIGMOD最佳论文奖
阿里云PolarDB凭借全球首创基于CXL Switch的分布式内存池技术,在SIGMOD 2025上荣获工业赛道“最佳论文奖”,连续两年蝉联该顶会最高奖项。其创新架构PolarCXLMem打破传统RDMA技术瓶颈,性能提升2.1倍,并已落地应用于内存池化场景,推动大模型推理与多模态存储发展,展现CXL Switch在高速互联中的巨大潜力。
阿里云PolarDB数据库蝉联SIGMOD最佳论文奖
|
缓存 NoSQL 中间件
Redis,分布式缓存演化之路
本文介绍了基于Redis的分布式缓存演化,探讨了分布式锁和缓存一致性问题及其解决方案。首先分析了本地缓存和分布式缓存的区别与优劣,接着深入讲解了分布式远程缓存带来的并发、缓存失效(穿透、雪崩、击穿)等问题及应对策略。文章还详细描述了如何使用Redis实现分布式锁,确保高并发场景下的数据一致性和系统稳定性。最后,通过双写模式和失效模式讨论了缓存一致性问题,并提出了多种解决方案,如引入Canal中间件等。希望这些内容能为读者在设计分布式缓存系统时提供有价值的参考。感谢您的阅读!
676 6
Redis,分布式缓存演化之路