配置 madlib for PolarDB 实现数据库机器学习功能

本文涉及的产品
云原生数据库 PolarDB MySQL 版,Serverless 5000PCU 100GB
云原生数据库 PolarDB PostgreSQL 版,企业版 4核16GB
推荐场景:
HTAP混合负载
云原生数据库 PolarDB MySQL 版,通用型 2核4GB 50GB
简介: PolarDB 的云原生存算分离架构, 具备低廉的数据存储、高效扩展弹性、高速多机并行计算能力、高速数据搜索和处理; PolarDB与计算算法结合, 将实现双剑合璧, 推动业务数据的价值产出, 将数据变成生产力.本文将介绍PolarDB结合madlib, 让PolarDB具备机器学习功能.madlib库无疑是大而全的数据库机器学习库-Deep Learning-Graph-Model Selection-Sampling-Statistics-Supervised Learning-Time Series Analysis-Unsupervised Learning

背景

PolarDB 的云原生存算分离架构, 具备低廉的数据存储、高效扩展弹性、高速多机并行计算能力、高速数据搜索和处理; PolarDB与计算算法结合, 将实现双剑合璧, 推动业务数据的价值产出, 将数据变成生产力.

本文将介绍PolarDB结合madlib, 让PolarDB具备机器学习功能.

madlib库无疑是大而全的数据库机器学习库,

  • Deep Learning
  • Graph
  • Model Selection
  • Sampling
  • Statistics
  • Supervised Learning
  • Time Series Analysis
  • Unsupervised Learning

将madlib安装到PolarDB, 让PolarDB具备机器学习功能

这个例子直接在PolarDB容器中部署pgcat.

PolarDB部署请参考:

进入PolarDB环境

docker exec -it 67e1eed1b4b6 bash    

下载madlib rpm

https://cwiki.apache.org/confluence/display/MADLIB/Installation+Guide

wget https://dist.apache.org/repos/dist/release/madlib/1.20.0/apache-madlib-1.20.0-CentOS7.rpm  

安装madlib

sudo rpm -ivh apache-madlib-1.20.0-CentOS7.rpm  

加载madlib到PolarDB数据库对应DB中(非extension管理)

/usr/local/madlib/bin/madpack -s madlib -p postgres -c [user[/password]@][host][:port][/database] install  
  
or  
  
/usr/local/madlib/bin/madpack -s madlib -p postgres install  

测试madlib安装正确性

/usr/local/madlib/bin/madpack -s madlib -p postgres install-check  

使用madlib

[postgres@67e1eed1b4b6 ~]$ psql -h 127.0.0.1  
psql (11.9)  
Type "help" for help.  
  
postgres=# set search_path =madlib, "$user", public;  
SET  
  
  
postgres=# \dT+  
                                                               List of data types  
 Schema |               Name                |           Internal name           | Size  | Elements |  Owner   | Access privileges | Description   
--------+-----------------------------------+-----------------------------------+-------+----------+----------+-------------------+-------------  
 madlib | args_and_value_double             | args_and_value_double             | tuple |          | postgres |                   |   
 madlib | __arima_lm_result                 | __arima_lm_result                 | tuple |          | postgres |                   |   
 madlib | __arima_lm_stat_result            | __arima_lm_stat_result            | tuple |          | postgres |                   |   
 madlib | __arima_lm_sum_result             | __arima_lm_sum_result             | tuple |          | postgres |                   |   
 madlib | assoc_rules_results               | assoc_rules_results               | tuple |          | postgres |                   |   
 madlib | bytea8                            | bytea8                            | var   |          | postgres |                   |   
 madlib | _cat_levels_type                  | _cat_levels_type                  | tuple |          | postgres |                   |   
 madlib | chi2_test_result                  | chi2_test_result                  | tuple |          | postgres |                   |   
 madlib | closest_column_result             | closest_column_result             | tuple |          | postgres |                   |   
 madlib | closest_columns_result            | closest_columns_result            | tuple |          | postgres |                   |   
 madlib | __clustered_agg_result            | __clustered_agg_result            | tuple |          | postgres |                   |   
 madlib | __clustered_lin_result            | __clustered_lin_result            | tuple |          | postgres |                   |   
 madlib | __clustered_log_result            | __clustered_log_result            | tuple |          | postgres |                   |   
 madlib | __clustered_mlog_result           | __clustered_mlog_result           | tuple |          | postgres |                   |   
 madlib | complex                           | complex                           | tuple |          | postgres |                   |   
 madlib | __coxph_a_b_result                | __coxph_a_b_result                | tuple |          | postgres |                   |   
 madlib | __coxph_cl_var_result             | __coxph_cl_var_result             | tuple |          | postgres |                   |   
 madlib | coxph_result                      | coxph_result                      | tuple |          | postgres |                   |   
 madlib | coxph_step_result                 | coxph_step_result                 | tuple |          | postgres |                   |   
 madlib | cox_prop_hazards_result           | cox_prop_hazards_result           | tuple |          | postgres |                   |   
 madlib | __cox_resid_stat_result           | __cox_resid_stat_result           | tuple |          | postgres |                   |   
 madlib | __dbscan_edge                     | __dbscan_edge                     | tuple |          | postgres |                   |   
 madlib | __dbscan_losses                   | __dbscan_losses                   | tuple |          | postgres |                   |   
 madlib | __dbscan_record                   | __dbscan_record                   | tuple |          | postgres |                   |   
 madlib | dense_linear_solver_result        | dense_linear_solver_result        | tuple |          | postgres |                   |   
 madlib | __elastic_net_result              | __elastic_net_result              | tuple |          | postgres |                   |   
 madlib | _flattened_tree                   | _flattened_tree                   | tuple |          | postgres |                   |   
 madlib | f_test_result                     | f_test_result                     | tuple |          | postgres |                   |   
 madlib | __glm_result_type                 | __glm_result_type                 | tuple |          | postgres |                   |   
 madlib | _grp_state_type                   | _grp_state_type                   | tuple |          | postgres |                   |   
 madlib | heteroskedasticity_test_result    | heteroskedasticity_test_result    | tuple |          | postgres |                   |   
 madlib | kmeans_result                     | kmeans_result                     | tuple |          | postgres |                   |   
 madlib | kmeans_state                      | kmeans_state                      | tuple |          | postgres |                   |   
 madlib | ks_test_result                    | ks_test_result                    | tuple |          | postgres |                   |   
 madlib | lda_result                        | lda_result                        | tuple |          | postgres |                   |   
 madlib | lincrf_result                     | lincrf_result                     | tuple |          | postgres |                   |   
 madlib | linear_svm_result                 | linear_svm_result                 | tuple |          | postgres |                   |   
 madlib | linregr_result                    | linregr_result                    | tuple |          | postgres |                   |   
 madlib | lmf_result                        | lmf_result                        | tuple |          | postgres |                   |   
 madlib | __logregr_result                  | __logregr_result                  | tuple |          | postgres |                   |   
 madlib | marginal_logregr_result           | marginal_logregr_result           | tuple |          | postgres |                   |   
 madlib | marginal_mlogregr_result          | marginal_mlogregr_result          | tuple |          | postgres |                   |   
 madlib | margins_result                    | margins_result                    | tuple |          | postgres |                   |   
 madlib | matrix_result                     | matrix_result                     | tuple |          | postgres |                   |   
 madlib | __mlogregr_cat_coef               | __mlogregr_cat_coef               | tuple |          | postgres |                   |   
 madlib | mlogregr_result                   | mlogregr_result                   | tuple |          | postgres |                   |   
 madlib | mlogregr_summary_result           | mlogregr_summary_result           | tuple |          | postgres |                   |   
 madlib | mlp_result                        | mlp_result                        | tuple |          | postgres |                   |   
 madlib | __multinom_result_type            | __multinom_result_type            | tuple |          | postgres |                   |   
 madlib | mw_test_result                    | mw_test_result                    | tuple |          | postgres |                   |   
 madlib | one_way_anova_result              | one_way_anova_result              | tuple |          | postgres |                   |   
 madlib | __ordinal_result_type             | __ordinal_result_type             | tuple |          | postgres |                   |   
 madlib | path_match_result                 | path_match_result                 | tuple |          | postgres |                   |   
 madlib | _pivotalr_lda_model               | _pivotalr_lda_model               | tuple |          | postgres |                   |   
 madlib | _prune_result_type                | _prune_result_type                | tuple |          | postgres |                   |   
 madlib | __rb_coxph_hs_result              | __rb_coxph_hs_result              | tuple |          | postgres |                   |   
 madlib | __rb_coxph_result                 | __rb_coxph_result                 | tuple |          | postgres |                   |   
 madlib | residual_norm_result              | residual_norm_result              | tuple |          | postgres |                   |   
 madlib | robust_linregr_result             | robust_linregr_result             | tuple |          | postgres |                   |   
 madlib | robust_logregr_result             | robust_logregr_result             | tuple |          | postgres |                   |   
 madlib | robust_mlogregr_result            | robust_mlogregr_result            | tuple |          | postgres |                   |   
 madlib | sparse_linear_solver_result       | sparse_linear_solver_result       | tuple |          | postgres |                   |   
 madlib | summary_result                    | summary_result                    | tuple |          | postgres |                   |   
 madlib | __svd_bidiagonal_matrix_result    | __svd_bidiagonal_matrix_result    | tuple |          | postgres |                   |   
 madlib | __svd_lanczos_result              | __svd_lanczos_result              | tuple |          | postgres |                   |   
 madlib | __svd_vec_mat_mult_result         | __svd_vec_mat_mult_result         | tuple |          | postgres |                   |   
 madlib | svec                              | svec                              | var   |          | postgres |                   |   
 madlib | _tree_result_type                 | _tree_result_type                 | tuple |          | postgres |                   |   
 madlib | t_test_result                     | t_test_result                     | tuple |          | postgres |                   |   
 madlib | __utils_scales                    | __utils_scales                    | tuple |          | postgres |                   |   
 madlib | wsr_test_result                   | wsr_test_result                   | tuple |          | postgres |                   |   
 madlib | xgb_gridsearch_train_results_type | xgb_gridsearch_train_results_type | tuple |          | postgres |                   |   
 public | vector                            | vector                            | var   |          | postgres |                   |   
(73 rows)  
  
postgres=#   \do+  
                                                    List of operators  
 Schema | Name |   Left arg type    |   Right arg type   |   Result type    |           Function            | Description   
--------+------+--------------------+--------------------+------------------+-------------------------------+-------------  
 madlib | %*%  | double precision[] | double precision[] | double precision | madlib.svec_dot               |   
 madlib | %*%  | double precision[] | svec               | double precision | madlib.svec_dot               |   
 madlib | %*%  | svec               | double precision[] | double precision | madlib.svec_dot               |   
 madlib | %*%  | svec               | svec               | double precision | madlib.svec_dot               |   
 madlib | *    | double precision[] | double precision[] | svec             | float8arr_mult_float8arr      |   
 madlib | *    | double precision[] | svec               | svec             | float8arr_mult_svec           |   
 madlib | *    | svec               | double precision[] | svec             | svec_mult_float8arr           |   
 madlib | *    | svec               | svec               | svec             | svec_mult                     |   
 madlib | *||  | integer            | svec               | svec             | svec_concat_replicate         |   
 madlib | +    | double precision[] | double precision[] | svec             | float8arr_plus_float8arr      |   
 madlib | +    | double precision[] | svec               | svec             | float8arr_plus_svec           |   
 madlib | +    | svec               | double precision[] | svec             | svec_plus_float8arr           |   
 madlib | +    | svec               | svec               | svec             | svec_plus                     |   
 madlib | -    | double precision[] | double precision[] | svec             | float8arr_minus_float8arr     |   
 madlib | -    | double precision[] | svec               | svec             | float8arr_minus_svec          |   
 madlib | -    | svec               | double precision[] | svec             | svec_minus_float8arr          |   
 madlib | -    | svec               | svec               | svec             | svec_minus                    |   
 madlib | /    | double precision[] | double precision[] | svec             | float8arr_div_float8arr       |   
 madlib | /    | double precision[] | svec               | svec             | float8arr_div_svec            |   
 madlib | /    | svec               | double precision[] | svec             | svec_div_float8arr            |   
 madlib | /    | svec               | svec               | svec             | svec_div                      |   
 madlib | <    | svec               | svec               | boolean          | svec_lt                       |   
 madlib | <=   | svec               | svec               | boolean          | svec_le                       |   
 madlib | <>   | svec               | svec               | boolean          | svec_ne                       |   
 madlib | =    | svec               | svec               | boolean          | svec_eq                       |   
 madlib | ==   | svec               | svec               | boolean          | svec_eq                       |   
 madlib | >    | svec               | svec               | boolean          | svec_gt                       |   
 madlib | >=   | svec               | svec               | boolean          | svec_ge                       |   
 madlib | ^    | svec               | svec               | svec             | svec_pow                      |   
 madlib | ||   | svec               | svec               | svec             | svec_concat                   |   
 public | +    | vector             | vector             | vector           | vector_add                    |   
 public | -    | vector             | vector             | vector           | vector_sub                    |   
 public | <    | vector             | vector             | boolean          | vector_lt                     |   
 public | <#>  | vector             | vector             | double precision | vector_negative_inner_product |   
 public | <->  | vector             | vector             | double precision | l2_distance                   |   
 public | <=   | vector             | vector             | boolean          | vector_le                     |   
 public | <=>  | vector             | vector             | double precision | cosine_distance               |   
 public | <>   | vector             | vector             | boolean          | vector_ne                     |   
 public | =    | vector             | vector             | boolean          | vector_eq                     |   
 public | >    | vector             | vector             | boolean          | vector_gt                     |   
 public | >=   | vector             | vector             | boolean          | vector_ge                     |   
(41 rows)  

参考

https://madlib.apache.org/docs/latest/index.html

https://cwiki.apache.org/confluence/display/MADLIB/Installation+Guide

相关实践学习
使用PolarDB和ECS搭建门户网站
本场景主要介绍基于PolarDB和ECS实现搭建门户网站。
阿里云数据库产品家族及特性
阿里云智能数据库产品团队一直致力于不断健全产品体系,提升产品性能,打磨产品功能,从而帮助客户实现更加极致的弹性能力、具备更强的扩展能力、并利用云设施进一步降低企业成本。以云原生+分布式为核心技术抓手,打造以自研的在线事务型(OLTP)数据库Polar DB和在线分析型(OLAP)数据库Analytic DB为代表的新一代企业级云原生数据库产品体系, 结合NoSQL数据库、数据库生态工具、云原生智能化数据库管控平台,为阿里巴巴经济体以及各个行业的企业客户和开发者提供从公共云到混合云再到私有云的完整解决方案,提供基于云基础设施进行数据从处理、到存储、再到计算与分析的一体化解决方案。本节课带你了解阿里云数据库产品家族及特性。
相关文章
|
4天前
|
资源调度 关系型数据库 MySQL
【Flink on YARN + CDC 3.0】神操作!看完这篇教程,你也能成为数据流处理高手!从零开始,一步步教会你在Flink on YARN模式下如何配置Debezium CDC 3.0,让你的数据库变更数据瞬间飞起来!
【8月更文挑战第15天】随着Apache Flink的普及,企业广泛采用Flink on YARN部署流处理应用,高效利用集群资源。变更数据捕获(CDC)工具在现代数据栈中至关重要,能实时捕捉数据库变化并转发给下游系统处理。本文以Flink on YARN为例,介绍如何在Debezium CDC 3.0中配置MySQL连接器,实现数据流处理。首先确保YARN上已部署Flink集群,接着安装Debezium MySQL连接器并配置Kafka Connect。最后,创建Flink任务消费变更事件并提交任务到Flink集群。通过这些步骤,可以构建出从数据库变更到实时处理的无缝数据管道。
16 2
|
10天前
|
存储 关系型数据库 MySQL
"Linux环境下MySQL数据库名及表名大小写敏感性设置详解:从配置到影响,确保数据库操作的准确与高效"
【8月更文挑战第9天】在Linux环境中,MySQL数据库名及表名的大小写敏感性是一项重要配置。默认情况下,MySQL在Linux上区分大小写,但这可通过配置文件 `/etc/my.cnf` 中的 `lower_case_table_names` 参数调整。该参数设为0时,名称存储时保持原样,查询时不区分大小写;设为1则全部转换为小写。通过编辑配置文件并重启MySQL服务,可根据需求灵活控制名称的大小写敏感性,确保数据一致性和应用兼容性。
27 3
|
10天前
|
SQL 关系型数据库 分布式数据库
PolarDB Proxy配置与优化:提升数据库访问效率
PolarDB是阿里云的高性能分布式数据库,PolarDB Proxy作为关键组件,解析并转发SQL请求至集群。本文概览PolarDB Proxy功能,包括连接池管理、负载均衡及SQL过滤;并提供配置示例,如连接池的最大连接数与空闲超时时间设置、一致哈希路由及SQL安全过滤规则。最后探讨了监控调优、查询缓存及网络优化策略,以实现高效稳定的数据库访问。
39 2
|
4天前
|
安全 Nacos 数据库
【技术安全大揭秘】Nacos暴露公网后被非法访问?!6大安全加固秘籍,手把手教你如何保护数据库免遭恶意篡改,打造坚不可摧的微服务注册与配置中心!从限制公网访问到启用访问控制,全方位解析如何构建安全防护体系,让您从此告别数据安全风险!
【8月更文挑战第15天】Nacos是一款广受好评的微服务注册与配置中心,但其公网暴露可能引发数据库被非法访问甚至篡改的安全隐患。本文剖析此问题并提供解决方案,包括限制公网访问、启用HTTPS、加强数据库安全、配置访问控制及监控等,帮助开发者确保服务安全稳定运行。
12 0
|
4天前
|
druid Java 数据库连接
SpringBoot项目整合MybatisPlus持久层框架+Druid数据库连接池,以及实现增删改查功能
SpringBoot项目整合MybatisPlus和Druid数据库连接池,实现基本的增删改查功能。
17 0
|
5天前
|
SQL 关系型数据库 MySQL
MySql⭐一、配置MySql数据库,并创建一个表单
MySql⭐一、配置MySql数据库,并创建一个表单
|
10天前
|
安全 关系型数据库 MySQL
"深度解析:MySQL密码修改与远程登录配置全攻略,保障数据库安全与灵活访问"
【8月更文挑战第9天】MySQL是广受青睐的开源关系型数据库系统,其安全性和易用性对DBA和开发者至关重要。本文通过实例解析MySQL中用户密码更新及远程登录配置,确保数据库安全访问与高效管理。首先介绍如何分步修改密码,包括登录MySQL、选择数据库、使用`ALTER USER`命令更新密码,并刷新权限。接着,指导如何配置远程访问,涉及调整MySQL监听地址、授权用户远程登录、检查网络设置及测试远程连接。遵循这些步骤,可强化数据库安全性并实现灵活管理。
46 0
|
20天前
|
关系型数据库 分布式数据库 数据库
PolarDB产品使用问题之数据库处于只读状态,如何恢复其读写功能
PolarDB产品使用合集涵盖了从创建与管理、数据管理、性能优化与诊断、安全与合规到生态与集成、运维与支持等全方位的功能和服务,旨在帮助企业轻松构建高可用、高性能且易于管理的数据库环境,满足不同业务场景的需求。用户可以通过阿里云控制台、API、SDK等方式便捷地使用这些功能,实现数据库的高效运维与持续优化。
PolarDB产品使用问题之数据库处于只读状态,如何恢复其读写功能
|
6天前
|
关系型数据库 Serverless 分布式数据库
揭秘PolarDB Serverless:大促洪峰秒级应对,无感伸缩见证科技魔法!一探云数据库管理的颠覆性革新,强一致性的守护神来了!
【8月更文挑战第13天】在云计算背景下,阿里巴巴的云原生数据库PolarDB Serverless针对弹性伸缩与高性能一致性提供了出色解决方案。本文通过一个电商平台大促活动的真实案例全面测评PolarDB Serverless的表现。面对激增流量,PolarDB Serverless能秒级自动扩展资源,如通过调用`pd_add_reader`快速增加读节点分摊压力;其无感伸缩确保服务平滑运行,不因扩展中断;强一致性模型则保障了数据准确性,即便在高并发写操作下也确保库存等数据的同步一致性。PolarDB Serverless简化了数据库管理,提升了系统效能,是追求高效云数据库管理企业的理想选择。
34 7
|
4天前
|
关系型数据库 MySQL Serverless
在部署云数据库PolarDB MySQL版 Serverless集群的过程中问题点
在部署PolarDB MySQL Serverless过程中,常见问题包括配置误解、网络配置错误、资源未及时释放及压测不熟练。建议深入理解配置项,确保合理设置伸缩策略;明确业务需求,使PolarDB与现有服务同处一地域与VPC;利用提醒功能管理资源生命周期;按官方指南执行压测。新用户面临的学习曲线、资源管理自动化不足及成本控制难题,可通过增强文档友好性、引入智能成本管理与用户界面优化来改善。
18 1

热门文章

最新文章

相关产品

  • 云原生数据库 PolarDB