Deepgreen & Greenplum DBA小白普及课之二(管理问题解答)

来源:互联网 发布:js正则替换指定字符串 编辑:程序博客网 时间:2024/05/16 17:46

原文链接

摘要: 不积跬步无以至千里,要想成为一名合格的数据库管理员,首先应该具备扎实的基础知识及问题处理能力。本文参考Pivotal官方FAQ,对在管理Deepgreen & Greenplum时经常会遇到的问题提出解决思路/答案。

074f69580b19f3e9185c564025209dfa3cfad3e7

不积跬步无以至千里,要想成为一名合格的数据库管理员,首先应该具备扎实的基础知识及问题处理能力。本文参考Pivotal官方FAQ,对在管理Deepgreen & Greenplum时经常会遇到的问题提出解决思路/答案。希望对大家有所帮助,如果有朋友有更多的问题分享,请留言,我将一并整理。

下面单刀直入,开始问题浏览及解决思路梳理:
1.执行gpstart命令失败了,我该怎么办?
  • 查看gpstart命令在Master执行失败后返回的错误原因;
  • 检查gpstart的启动日志,这里可能存着更详细的信息,日志存储在:~gpadmin/gpAdminLogs/gpstart_yyyymmdd.log;
  • 检查pg startup产生的日志文件$MASTER_DATA_DIRECTORY/pg_log/startup.log,看能否发现蛛丝马迹;
  • 如果Segment启动失败,在以上几个日志中,我们可以定位出启动失败的Segment编号,紧接着我们可以切换到对应的Segment 主机下面,找到以上两个日志去查看Segment失败的具体原因。
2.为什么我们需要gpstart -m和gpstop -m命令?
  • 这两个命令允许我们只启动或关闭Master,不启动Segment数据节点。这两个命令主要用来配合管理员做一些数据库高级配置操作,一般用户最好不要使用。
3.如何查看数据库在线时间?
在psql界面执行如下语句:
postgres=# select now() - pg_postmaster_start_time() ;       ?column?       ----------------------- 1 day 13:51:04.865115(1 row)

4.怎样才能删除Mirror节点?
  • Deepgreen和Greenplum不提供Mirror节点删除工具,所以添加Mirror之前请慎重考虑。如果非要去除Mirror节点,可以重新初始化集群,再把之前的数据恢复回来。
5.gpcheckcat是用来干嘛的?如何执行这个命令?
gpcheckcat工具用来检查Master和Segments之间的catalog差异,存在$GPHOME/bin/lib目录下,如果没有设置到环境变量,需要手工切换到该目录下执行。
语法如下:
Usage: gpcheckcat [dbname]        -?        -B parallel: number of worker threads        -g dir     : generate SQL to rectify catalog corruption, put it in dir        -h host    : DB host name        -p port    : DB port number        -P passwd  : DB password        -o         : check OID consistency        -U uname   : DB User Name        -v         : verbose
执行举例(报告结果在最后):
dgadmin@flash:~/deepgreendb/bin/lib$ ./gpcheckcat postgresConnected as user 'dgadmin' to database 'postgres', port '15432', gpdb version '4.3'-------------------------------------------------------------------Performing test 'duplicate'Total runtime for this test: 0:00:24.49Performing test 'missing_extraneous'Total runtime for this test: 0:00:25.51Performing test 'inconsistent'Total runtime for this test: 0:00:40.60Performing test 'foreign_key'Total runtime for this test: 0:00:01.74Performing test 'acl'Total runtime for this test: 0:00:00.04Performing test 'persistent'Total runtime for this test: 0:00:00.38Performing test 'pgclass'Total runtime for this test: 0:00:00.01Performing test 'namespace'Total runtime for this test: 0:00:00.05Performing test 'distribution_policy'Total runtime for this test: 0:00:00.00Performing test 'dependency'Total runtime for this test: 0:00:02.18Performing test 'owner'Total runtime for this test: 0:00:00.04Performing test 'part_integrity'Total runtime for this test: 0:00:00.03Performing test 'part_constraint'Total runtime for this test: 0:00:00.04Performing test 'duplicate_persistent'Total runtime for this test: 0:00:00.43SUMMARY REPORT===================================================================Total runtime for 14 test(s): 0:01:35.59Found no catalog issue

6.怎样删除Standby?
  • 想要移除当前配置的Standby节点,只需要在Master主机上执行命令:gpinitstandby -r   。
7.如何执行Master和Standby之间的重新同步?
如果已经配置了Standby节点,并且想要同步主备之间的数据,可以执行以下命令:
gpinitstandby -n

8.如何恢复一个无效的Segment节点?
  • 使用gprecoverseg工具,它能识别哪个Segment需要被恢复并执行恢复。
9.如何增加Mirror节点?
  • 如果集群初始化没有配置Mirror节点,可以通过gpaddmirrors工具增加Mirror节点。
  • 具体命令执行细节请参考:gpaddmirrors --help
10.如何查看Master,primary和mirror之间的映射关系?
通过执行下面语句,看整个集群映射关系:
postgres=# select * from gp_segment_configuration order by dbid; dbid | content | role | preferred_role | mode | status | port  | hostname | address | replication_port | san_mounts------+---------+------+----------------+------+--------+-------+----------+---------+------------------+------------    1 |      -1 | p    | p              | s    | u      | 15432 | flash    | flash   |                  |    2 |       0 | p    | p              | s    | u      | 25432 | flash    | flash   |            28432 |    3 |       1 | p    | p              | s    | u      | 25433 | flash    | flash   |            28433 |    4 |       0 | m    | m              | s    | u      | 26432 | flash    | flash   |            27432 |    5 |       1 | m    | m              | s    | u      | 26433 | flash    | flash   |            27433 |(5 rows)

11.如何以管理模式启动集群?
限制模式:
  • 执行gpstart -R可以启动限制模式,此时只有超级用户才可以连接到数据库。
系统模式:
  • 执行gpstart -m可以启动系统模式,此时我们可以单独连接到某一个Master或者Segment实例,例如只连接到Master实例
dgadmin@flash:~$ PGOPTIONS='-c gp_session_role=utility' psql -d postgrespsql (8.2.15)Type "help" for help.postgres=#

12.如何运行I/O、netperf检查工具gpcheckperf?
针对每个网络接口卡的网络I/O测试:
gpcheckperf -f seg_host_file_nic-1 -r N -d /data/gpcheckperf > seg_host_file_nic_1.outgpcheckperf -f seg_host_file_nic-2 -r N -d /data/gpcheckperf > seg_host_file_nic_2.out
针对磁盘IO的测试:
gpcheckperf -f seg_host_file_nic-1 -r ds -D -d /data/gpdb_p1 -d  /data/gpdb_p2 -d /data/gpdb_m1 -d  /data/gpdb_m2

13.如何更新postgresql.conf文件并使生效?
  • 除了常规的修改postgresql.conf文件并重载/重启使参数生效外,还可以使用gpconfig工具进行设置。具体命令参见:gpconfig --help
14.pg_hba.conf文件是干嘛用的?
  • Master主机上的pg_hba.conf文件用来控制客户端访问及授权。具体如何配置请参见官方数据库管理手册。
15.如何增加数据库新用户?
首先,可以使用createuser命令:
dgadmin@flash:~$ createuser --helpcreateuser creates a new PostgreSQL role.Usage:  createuser [OPTION]... [ROLENAME]Options:  -c, --connection-limit=N  connection limit for role (default: no limit)  -d, --createdb            role can create new databases  -D, --no-createdb         role cannot create databases  -e, --echo                show the commands being sent to the server  -E, --encrypted           encrypt stored password  -i, --inherit             role inherits privileges of roles it is a                            member of (default)  -I, --no-inherit          role does not inherit privileges  -l, --login               role can login (default)  -L, --no-login            role cannot login  -N, --unencrypted         do not encrypt stored password  -P, --pwprompt            assign a password to new role  -r, --createrole          role can create new roles  -R, --no-createrole       role cannot create roles  -s, --superuser           role will be superuser  -S, --no-superuser        role will not be superuser  --help                    show this help, then exit  --version                 output version information, then exitConnection options:  -h, --host=HOSTNAME       database server host or socket directory  -p, --port=PORT           database server port  -U, --username=USERNAME   user name to connect as (not the one to create)  -w, --no-password         never prompt for password  -W, --password            force password promptIf one of -d, -D, -r, -R, -s, -S, and ROLENAME is not specified, you willbe prompted interactively.Report bugs to <pgsql-bugs@postgresql.org>.
其次,可以在psql窗口通过sql命令创建:
CREATE USER or ROLE <ROLE_NAME> ....

16.如何在所有主机之间创建密码互信?
使用gpssh-exkeys工具来创建,参见下面语法:
gpssh-exkeys -h hostname1 -h hostname2 ..  -h hostnameN

17.如何查看数据库版本信息?
首先可以通过psql界面执行select version(); sql语句:
postgres=#  select version();                                                                                           version                                                                                         --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- PostgreSQL 8.2.15 (Greenplum Database 4.3.99.00 build Deepgreen DB) on x86_64-unknown-linux-gnu, compiled by GCC gcc (Ubuntu 4.9.4-2ubuntu1~14.04.1) 4.9.4 compiled on May 18 2017 05:19:19(1 row)
其次,可以通过在shell界面执行命令:postgres --gp-version查看:

原文链接