Deepgreen & Greenplum DBA小白普及課之二(管理問題解答)
不積跬步無以至千裏,要想成為一名合格的數據庫管理員,首先應該具備紮實的基礎知識及問題處理能力。本文參考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是數據庫中的一個模式,其中包含很多表、視圖和函數,用來在數據庫啟動狀態下幫助管理員更好的管理數據庫。
End~
最後更新:2017-07-02 11:27:16