[关闭]
@zhangyy 2021-07-02T14:24:49.000000Z 字数 2911 阅读 206

greenplum的数据库的日常使用

greenplum系列



一: 参数修改方法

  1. gp的参数修改方法:
  2. 修改参数
  3. gpconfig -c shared_buffers -v 129MB -m 126MB
  4. gpconfig -c max_connections -v 1000 -m 300
  5. gpconfig -s shared_buffers
  6. gpconfig -s max_connections
  7. gpstop -u
  8. 远程登录:
  9. psql -h 192.168.3.121 -p5432 -U gpadmin

  1. 常见优化参数:
  2. gpconfig -c gp_vmem_protect_limit -m 16384 -v 8196
  3. gpconfig -c shared_buffers -m 4GB -v 2GB
  4. gpconfig -c max_connections -m 500 -v 950
  5. gpconfig -c max_prepared_transactions -m 600 -v 1000
  6. gpconfig -c statement_mem -v 512MB
  7. gpconfig -c work_mem -m 1024MB -v 1024MB
  8. #(1)全局死锁检测开关
  9. #在Greenplum 6中其默认关闭,需要打开它才可以支持并发更新/删除操作;
  10. gpconfig -c gp_enable_global_deadlock_detector -v on
  11. #(2) 禁用GPORCA优化器(据说GPDB6默认的优化器为:GPORCA)
  12. gpconfig -c optimizer -v off
  13. #(3)关闭日志
  14. #此GUC减少不必要的日志,避免日志输出对I/O性能的干扰。
  15. gpconfig -c log_statement -v none
  16. #注意:参数配置修改后,我使用gpstop -u重新加了配置,并用gpconfig -s检查了各个参数确为修改成功。
  17. gpconfig -c wal_buffers -v 256MB
  18. #将WAL日志缓存调大。修改该参数需要重启实例。
  19. gpconfig -c random_page_cost -v 10
  20. #将随机访问代价开销调小,有利于查询走索引。
  21. gpconfig -c checkpoint_segments -v 2 --skipvalidation
  22. #GUC影响checkpoint主动刷盘的频率,默认值8会降低刷盘频率,但是每次刷盘的数据量较大,导致整个集群瞬时的性能下降。针对OLTP大量更新类语句适当调小此设置会增加刷盘频率,但由于每次刷盘数据量变小,平均性能会有较明显提升;Greenplum 5支持此GUC但是并无明显效果,这是由于Greenplum 5的性能瓶颈并不在于I/O,而是在表锁导致的串行化。

  1. 修改参数之后重启:
  2. gpstop -M fast
  3. gpstart

image_1f9irpeh41am217oi1ep3r9qh6m9.png-254.8kB

image_1f9irq1jd1ns11l0c1q8i14jvcoum.png-248.9kB

image_1f9irqus0d5c1mvp1abq1cat68413.png-467.9kB

image_1f9irrv2lb0s17lk1ev7mao1rff1g.png-248.5kB

image_1f9irsct915u21jao1evtst2bqk1t.png-314.5kB

image_1f9irsqkg19r21qc65l7e810lr2a.png-454.1kB

二: greenplum 的日常管理

2.1 分段查询:

  1. 相关使用命令
  2. select version();
  3. 查看分段:
  4. select * from gp_segment_configuration order by content asc,dbid;

image_1f9is6vo26u01avmte4oc61sj79.png-56.9kB

image_1f9is7rvevou1l96otq1s4f1maem.png-298kB

2.2 关于segment 的 连接

  1. psql -h 192.168.100.13 -p55000 -U gpadmin
  2. (
  3. psql: FATAL: connections to primary segments are not allowed
  4. DETAIL: This database instance is running as a primary segment in a Greenplum cluster and does not permit direct connections.
  5. HINT: To force a connection anyway (dangerous!), use utility mode.
  6. )

image_1f9isdg0hr6m1k5a12ba11r17fa1j.png-94kB

image_1f9isf7tqg5vc9b1t29gah1g3h20.png-89.6kB

  1. data 节点连接
  2. PGOPTIONS='-c gp_session_role=utility' psql -h127.0.0.1 -p55000
  3. PGOPTIONS='-c gp_session_role=utility' psql -h192.168.100.13 -p55000

image_1f9isgtjv126alqk18tqjfh1lo62d.png-69.2kB

image_1f9ish95vj2k1mbs1dlkesrc6u2q.png-64.2kB

2.4 远程工具连接

image_1f9isk8eu1o0vjrhhhnirs1c8637.png-278.9kB

  1. psql -h192.168.100.11 -p5432 -U gpadmin
  2. alter role gpadmin with password 'gpadmin';

image_1f9ispp6lbq01n3l2tjdch1bc541.png-72kB

  1. cd /greenplum/gpdata/master/gpseg-1
  2. vim pg_hba.conf
  3. ----
  4. 到最后加上:
  5. host all all 0.0.0.0/0 md5
  6. ----
  7. gpstop -u

image_1f9ispdk41vs16gfjl31j6q1dqe3k.png-122.3kB

image_1f9isr65i1pg4pj0v481jkp13e4e.png-49.8kB

  1. 新建一个查询:
  2. create database flyfishdb [创建一个库]
  3. create user flyfish with password 'flyfish123.com'(创建普通用户授权)
  4. create table flyfish_table01 (id int,name varchar(10), age int); (建表)
  5. insert into flyfish_table01 values(1,'flyfish02',30);
  6. insert into flyfish_table01 values(1,'flyfish03',31);
  7. insert into flyfish_table01 values(1,'flyfish04',32);
  8. insert into flyfish_table01 values(1,'flyfish05',33);
  9. insert into flyfish_table01 values(1,'flyfish06',34);
  10. insert into flyfish_table01 values(1,'flyfish07',35);

image_1f9iteiqk18sdgb51p351kr39av5q.png-58.4kB

image_1f9iteulf5q51v6k1pvbt7m1hc267.png-98kB

image_1f9ithb4915gmlb4654r295p6k.png-204.9kB

image_1f9ithrbprk9se7qvb1g269hi71.png-54.1kB

  1. 查看数据分段:
  2. select gp_segment_id,count(*) from flyfish_table01 group by gp_segment_id;

image_1f9itk2cd1o541paiubn1uhoev87e.png-29.2kB


2.5 greenplum 常用数据库分析命令

  1. 统计数据库下表大小(包含索引)
  2. select schemaname,tablename,round(pg_total_relation_size(schemaname||'.'||tablename)/1024/1024) "Size_MB" from pg_tables group by 1,2 order by 3 desc;
  3. 统计所有库表大小:
  4. select datname,pg_size_pretty(pg_database_size(datname)) from pg_database;
  5. 查看当前连接数
  6. SELECT * FROM pg_stat_activity;
  7. psql -d postgres -c "select count(*) from pg_stat_activity"
  8. 查看某个数据库的大小
  9. select pg_size_pretty(pg_database_size('flyfish_table01'));
  10. 查看磁盘空间:
  11. select dfhostname, dfspace,dfdevice from gp_toolkit.gp_disk_free order by dfhostname;
  12. 其他可以去gpcc 监控上面去看.
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注