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

    xiaoxiao2023-07-11  173

    不积跬步无以至千里,要想成为一名合格的数据库管理员,首先应该具备扎实的基础知识及问题处理能力。本文参考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 postgres Connected as user 'dgadmin' to database 'postgres', port '15432', gpdb version '4.3' ------------------------------------------------------------------- Performing test 'duplicate' Total runtime for this test: 0:00:24.49 Performing test 'missing_extraneous' Total runtime for this test: 0:00:25.51 Performing test 'inconsistent' Total runtime for this test: 0:00:40.60 Performing test 'foreign_key' Total runtime for this test: 0:00:01.74 Performing test 'acl' Total runtime for this test: 0:00:00.04 Performing test 'persistent' Total runtime for this test: 0:00:00.38 Performing test 'pgclass' Total runtime for this test: 0:00:00.01 Performing test 'namespace' Total runtime for this test: 0:00:00.05 Performing test 'distribution_policy' Total runtime for this test: 0:00:00.00 Performing test 'dependency' Total runtime for this test: 0:00:02.18 Performing test 'owner' Total runtime for this test: 0:00:00.04 Performing test 'part_integrity' Total runtime for this test: 0:00:00.03 Performing test 'part_constraint' Total runtime for this test: 0:00:00.04 Performing test 'duplicate_persistent' Total runtime for this test: 0:00:00.43 SUMMARY REPORT =================================================================== Total runtime for 14 test(s): 0:01:35.59 Found 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 postgres psql (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.out gpcheckperf -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 --help createuser 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 exit Connection 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 prompt If one of -d, -D, -r, -R, -s, -S, and ROLENAME is not specified, you will be 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查看: dgadmin@flash:~$ postgres --gp-version postgres (Greenplum Database) 4.3.99.00 build Deepgreen DB 18.pg_hba.conf、日志文件、master_data_directory目录都在哪? 数据库安装完后,一般都会设置$MASTER_DATA_DIRECTORY的位置,通常在:/数据目录/master/seg-1下面,具体依据你的设置。pg_hba.conf、pg_log、postgresql.conf和一些常规的数据库目录都在这个路径下。 19.vacuum工具是做什么用的?什么情况下执行vacuum? vacuum命令用于回收删除操作以后没有被及时释放的空间。在一般的数据库操作中,表数据在被更新或删除后,并没有真正的从物理上删除掉,真正的删除发生在vacuum命令执行完后。基于这个原因,很有必要对经常更新的表做周期性的vacuum操作。 20.vacuum 和 vacuum full两个工具有什么区别? vacuum会将表中更新\删除操作后的脏数据清除,把空间回收回来给当前表存储其他数据使用,仍然可以用于当前的表。vacuum full则会将当前的数据重新写入一个新文件,然后把原来的数据文件全部释放。这样会导致锁表、负载增加,所以要慎用。 21.analyze命令是做什么用的?多频繁运行它才合理? analyze用来收集数据库表的统计信息并存储在数据库中,查询优化器通过这些信息来分析每个查询并给出最有效的查询执行计划。规律的执行analyze是很有效的,另外在表有很大的变化时,一定要执行analyze。一个通用的方案是每天都执行一次analyze和vacuum操作,当然如果表更新频繁,建议在每次更新完成后即刻执行。 22.资源队列是什么? 资源队列用来管理数据库的资源负载。资源队列中的所有用户/查询都具有某种优先权。详细信息参见官网参考手册。 23.gp_toolkit是什么? gp_toolkit是数据库中的一个模式,其中包含很多表、视图和函数,用来在数据库启动状态下帮助管理员更好的管理数据库。 同系列相关文章:

    Deepgreen & Greenplum DBA小白普及课之一(一般问题解答)

    Deepgreen & Greenplum DBA小白普及课之三(备份问题解答)

    Deepgreen & Greenplum DBA小白普及课之四(性能问题解答)

    相关资源:Greenplum日常运维手册
    最新回复(0)