greenplum的数据库的日常使用

标签(空格分隔): greenplum系列



一: 参数修改方法

gp的参数修改方法:
   修改参数
gpconfig -c shared_buffers -v 129MB -m 126MB
gpconfig -c max_connections -v 1000 -m 300
gpconfig -s shared_buffers
gpconfig -s max_connections
gpstop -u
远程登录:
psql -h 192.168.100.11 -p5432 -U gpadmin

常见优化参数:

gpconfig -c gp_vmem_protect_limit -m 16384 -v 8196

gpconfig -c shared_buffers -m 4GB -v 2GB

gpconfig -c max_connections -m 500 -v 950

gpconfig -c max_prepared_transactions -m 600 -v 1000 

gpconfig -c statement_mem -v 512MB

gpconfig -c work_mem -m 1024MB -v 1024MB

#(1)全局死锁检测开关

#在Greenplum 6中其默认关闭,需要打开它才可以支持并发更新/删除操作;

gpconfig -c gp_enable_global_deadlock_detector -v on

#(2) 禁用GPORCA优化器(据说GPDB6默认的优化器为:GPORCA)

gpconfig -c optimizer -v off

#(3)关闭日志

#此GUC减少不必要的日志,避免日志输出对I/O性能的干扰。

gpconfig -c log_statement -v none

#注意:参数配置修改后,我使用gpstop -u重新加了配置,并用gpconfig -s检查了各个参数确为修改成功。

gpconfig -c wal_buffers -v 256MB

#将WAL日志缓存调大。修改该参数需要重启实例。

gpconfig -c random_page_cost -v 10

#将随机访问代价开销调小,有利于查询走索引。

gpconfig -c checkpoint_segments -v 2 --skipvalidation

#GUC影响checkpoint主动刷盘的频率,默认值8会降低刷盘频率,但是每次刷盘的数据量较大,导致整个集群瞬时的性能下降。针对OLTP大量更新类语句适当调小此设置会增加刷盘频率,但由于每次刷盘数据量变小,平均性能会有较明显提升;Greenplum 5支持此GUC但是并无明显效果,这是由于Greenplum 5的性能瓶颈并不在于I/O,而是在表锁导致的串行化。

修改参数之后重启:
  gpstop -M fast 
  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 分段查询:

相关使用命令
select version();

查看分段: 
   select * from gp_segment_configuration order by content asc,dbid;

image_1f9is6vo26u01avmte4oc61sj79.png-56.9kB

image_1f9is7rvevou1l96otq1s4f1maem.png-298kB

2.2 关于segment 的 连接

psql -h 192.168.100.13 -p55000 -U gpadmin

(
psql: FATAL:  connections to primary segments are not allowed
DETAIL:  This database instance is running as a primary segment in a Greenplum cluster and does not permit direct connections.
HINT:  To force a connection anyway (dangerous!), use utility mode.
)

image_1f9isdg0hr6m1k5a12ba11r17fa1j.png-94kB

image_1f9isf7tqg5vc9b1t29gah1g3h20.png-89.6kB

data 节点连接
PGOPTIONS='-c gp_session_role=utility' psql -h127.0.0.1 -p55000
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

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

image_1f9ispp6lbq01n3l2tjdch1bc541.png-72kB

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

image_1f9ispdk41vs16gfjl31j6q1dqe3k.png-122.3kB

image_1f9isr65i1pg4pj0v481jkp13e4e.png-49.8kB

新建一个查询:
create database flyfishdb  [创建一个库]
create user flyfish with password 'flyfish123.com'(创建普通用户授权)
create table flyfish_table01 (id int,name varchar(10), age int); (建表)

insert into flyfish_table01 values(1,'flyfish02',30);
insert into flyfish_table01 values(1,'flyfish03',31);
insert into flyfish_table01 values(1,'flyfish04',32);
insert into flyfish_table01 values(1,'flyfish05',33);
insert into flyfish_table01 values(1,'flyfish06',34);
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

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

image_1f9itk2cd1o541paiubn1uhoev87e.png-29.2kB


2.5 greenplum 常用数据库分析命令

统计数据库下表大小(包含索引)

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;

统计所有库表大小:

select datname,pg_size_pretty(pg_database_size(datname)) from pg_database;

查看当前连接数
SELECT * FROM pg_stat_activity; 

psql -d postgres -c "select count(*) from pg_stat_activity"

查看某个数据库的大小
 select pg_size_pretty(pg_database_size('flyfish_table01'));
 
 查看磁盘空间:
 select dfhostname, dfspace,dfdevice from gp_toolkit.gp_disk_free order by dfhostname;
 
 其他可以去gpcc 监控上面去看.