《童虎学习笔记》5分钟入门PG分布式集群Citus

《童虎学习笔记》11分钟学会MySQL基于时间点的恢复(gtid方式) 1 阅读详情

本专栏全部文章 https://blog.csdn.net/tonghu_note/category_11713514.html
总目录 https://blog.csdn.net/tonghu_note/article/details/124333034

来我的dou音 aa10246666, 看配套视频


一、实战环境

Citus是Postgres的一个extension扩展,将Postgres转换成一个分布式数据库,在集群的多个节点上分发数据和查询,具有像分片、分布式SQL引擎、复制表和分布式表等特性。

节点 cn_node1(协调节点,不存储数据) postgresql 14.2 10.211.55.9
节点 worker1_node2(工作节点,存储数据) postgresql 14.2 10.211.55.4
节点 worker2_node3(工作节点,存储数据) postgresql 14.2 10.211.55.6
citus-10.2 / debian 9

二、安装Citus

所有节点(cn, worker1, worker2)都做如下操作

1、安装Citus

curl https://install.citusdata.com/community/deb.sh | bash
apt-get -y install postgresql-14-citus-10.2
pg_conftool 14 main set shared_preload_libraries citus
pg_conftool 14 main set listen_addresses '*'

2、配置PG

文件 /etc/postgresql/14/main/pg_hba.conf 中添加

host    all     postgres             192.168.40.0/24                trust
host    all     appuser              192.168.40.0/24                trust

 其中postgres是系统用户用于添加节点、创建分布表、参考表等操作,appuser是应用程序连接cn节点使用数据库的帐号

重启PG使配置生效

systemctl restart  postgresql

3、新建样例数据库并授权

在这里我们新建了一个数据库d1, 又新建了一个用户appuser, 又在d1数据库里新建了扩展citus, 并授予appuser用户对d1数据库的all权限

create database d1;
CREATE user appuser;
\c d1
CREATE EXTENSION citus;
grant all on database d1 to appuser;
grant all on all tables in schema public to appuser;
grant all on all sequences in schema public to appuser;
grant all on all functions in schema public to appuser;
alter default privileges for user postgres in schema public grant all on tables to appuser;
alter default privileges for user postgres in schema public grant all on sequences to appuser;


三、添加worker节点

仅在cn节点做如下操作

1、添加2个worker节点

\c d1
SELECT * from citus_add_node('192.168.40.143', 5432);
SELECT * from citus_add_node('192.168.40.147', 5432);
SELECT rebalance_table_shards();

检查worker节点信息是否正确添加

d1=# SELECT * FROM citus_get_active_worker_nodes();
   node_name    | node_port 
----------------+-----------
 192.168.40.147 |      5432
 192.168.40.143 |      5432
(2 rows)


四、创建distributed分布表

分布表的特点是数据分布在每个worker节点上

1、方式1, 先建表,再将其设置为分布表,再向表中插入数据

在cn节点的d1上建表t1

\c d1
CREATE TABLE t1 (
  id bigint primary key,
  name text
);

以id列为分片键,将表设置为分布表, 默认一共创建32个分片,平均分配到每台worker上

SELECT create_distributed_table('t1', 'id');

此时到cn、worker1和worker2上查看一下t1表的分布情况

cn节点

d1=# \d+
                                         List of relations
 Schema |     Name     | Type  |  Owner   | Persistence | Access method |    Size    | Description 
--------+--------------+-------+----------+-------------+---------------+------------+-------------
 public | citus_tables | view  | postgres | permanent   |               | 0 bytes    | 
 public | t1           | table | postgres | permanent   | heap          | 8192 bytes | 
(2 rows)

worker1节点

d1=# \d+
                                         List of relations
 Schema |     Name     | Type  |  Owner   | Persistence | Access method |    Size    | Description 
--------+--------------+-------+----------+-------------+---------------+------------+-------------
 public | citus_tables | view  | postgres | permanent   |               | 0 bytes    | 
 public | t1_102008    | table | postgres | permanent   | heap          | 8192 bytes | 
 public | t1_102010    | table | postgres | permanent   | heap          | 8192 bytes | 
 public | t1_102012    | table | postgres | permanent   | heap          | 8192 bytes | 
 public | t1_102014    | table | postgres | permanent   | heap          | 8192 bytes | 
 public | t1_102016    | table | postgres | permanent   | heap          | 8192 bytes | 
 public | t1_102018    | table | postgres | permanent   | heap          | 8192 bytes | 
 public | t1_102020    | table | postgres | permanent   | heap          | 8192 bytes | 
 public | t1_102022    | table | postgres | permanent   | heap          | 8192 bytes | 
 public | t1_102024    | table | postgres | permanent   | heap          | 8192 bytes | 
 public | t1_102026    | table | postgres | permanent   | heap          | 8192 bytes | 
 public | t1_102028    | table | postgres | permanent   | heap          | 8192 bytes | 
 public | t1_102030    | table | postgres | permanent   | heap          | 8192 bytes | 
 public | t1_102032    | table | postgres | permanent   | heap          | 8192 bytes | 
 public | t1_102034    | table | postgres | permanent   | heap          | 8192 bytes | 
 public | t1_102036    | table | postgres | permanent   | heap          | 8192 bytes | 
 public | t1_102038    | table | postgres | permanent   | heap          | 8192 bytes | 
(17 rows)

d1=# 

worker2节点

d1=# \d+
                                         List of relations
 Schema |     Name     | Type  |  Owner   | Persistence | Access method |    Size    | Description 
--------+--------------+-------+----------+-------------+---------------+------------+-------------
 public | citus_tables | view  | postgres | permanent   |               | 0 bytes    | 
 public | t1_102009    | table | postgres | permanent   | heap          | 8192 bytes | 
 public | t1_102011    | table | postgres | permanent   | heap          | 8192 bytes | 
 public | t1_102013    | table | postgres | permanent   | heap          | 8192 bytes | 
 public | t1_102015    | table | postgres | permanent   | heap          | 8192 bytes | 
 public | t1_102017    | table | postgres | permanent   | heap          | 8192 bytes | 
 public | t1_102019    | table | postgres | permanent   | heap          | 8192 bytes | 
 public | t1_102021    | table | postgres | permanent   | heap          | 8192 bytes | 
 public | t1_102023    | table | postgres | permanent   | heap          | 8192 bytes | 
 public | t1_102025    | table | postgres | permanent   | heap          | 8192 bytes | 
 public | t1_102027    | table | postgres | permanent   | heap          | 8192 bytes | 
 public | t1_102029    | table | postgres | permanent   | heap          | 8192 bytes | 
 public | t1_102031    | table | postgres | permanent   | heap          | 8192 bytes | 
 public | t1_102033    | table | postgres | permanent   | heap          | 8192 bytes | 
 public | t1_102035    | table | postgres | permanent   | heap          | 8192 bytes | 
 public | t1_102037    | table | postgres | permanent   | heap          | 8192 bytes | 
 public | t1_102039    | table | postgres | permanent   | heap          | 8192 bytes | 
(17 rows)

可以看到cn节点的表是逻辑表,2个worker节点是是分片后的表,接下来我们在cn节点插入数据

INSERT INTO t1 (id, name) select generate_series(1,100000), 'aaa';

此时再到cn、worker1和worker2上查看一下t1表的分布情况

cn节点

d1=# \d+
                                         List of relations
 Schema | &nb

分布式 PostgreSQL 集群(Citus)官方教程 - 迁移现有应用程序 将现有应用程序迁移到 Citus 有时需要调整 schema 和查询以获得最佳性能。 Citus 扩展了 PostgreSQL 的分布式功能,但它不是扩展所有工作负载的直接替代品。高性能 Citus 集群需要考虑数据模型、工具和所使用的 SQL 功能的选择。 第一步是优化现有的数据库模式,以便它可以在多台计算机上高效工作。 确定分布策略 选择分布键(distribution key) 识别... 阅读详情

相关推荐

《童虎学习笔记》5分钟用Keepalived搭建MySQL高可用实现虚ip自动漂移

1

tonghu_note的博客 5623

PostgreSQL+Citus分布式数据库快速部署指南

Citus是基于PostgreSQL插件实现的一款开源分布式数据库,它允许数据库服务器(称为节点)在“无共享”架构中相互协调。这些节点形成一个集群,允许PostgreSQL保存更多数据并使用比单台计算机更多的CPU内核。这种架构还允许通过简单地向集群添加更多节点来扩展数据库。

weixin_46837188的博客 2617

PostgreSQL数据库集群部署

的方式区分多个后端。在进行恢复之前,需要确保当前的主服务器的数据库目录/opt/soft/pg_data中存在recovery_1st_stage和pgpool_remote_start两个脚本。配置很简单,就在三台机器的/etc/pgpool-II/pgpool_node_id文件中分别写入0,1,2就可以。从pgpool-II4.0开始,配置文件中的密码可以设置为空,如果密码参数为空,则pgpool-II将首先尝试从pool_passwd参数指定的文件中获取指定用户的密码,然后再使用空密码。

weixin_44228645的博客 6450

如何利用三阈值游程理论识别干旱事件_python

如果当前时间点与上一个干旱事件的结束位置相隔不超过一个月(`index - current_event['end_index']

weixin_44259522的博客 1954

Vue 10分钟入门VR全景显示 基于photo-sphere-viewer

文章目录前言一、引入photo-sphere-viewer?二、使用步骤1.引入库2.声明容器3.内容加载4.全部代码总结 前言 由于工作的需求,要实现全景图片的展示与预览,本来以为会是一个很难的内容,没想到使用现成的组件photo-sphere-viewer就可以轻松实现,上手只需要10分钟! 一、引入photo-sphere-viewer? 可以直接通过npm进行引入 npm install photo-sphere-viewer 二、使用步骤 1.引入库 photo-sphere-viewer

YIGE_MO的博客 5872

01-诊断开发流程概述

传送门 ==>> AutoSAR入门和实战系列总目录。

1787

ApacheCordova 13使用浏览器实现下载功能

Apache Cordova 13中,可通过HTML <a> 标签或JavaScript动态创建链接实现文件与图片下载。使用 download 属性可触发浏览器下载,图片可保存至相册。客户端通过 fileDownload 函数封装下载逻辑,服务端通过 File 方法返回文件流并指定类型与名称。适用于安卓应用中文件、图片的下载需求。

天马3798 66

Qt | 开发过程中总结的经验

关于如何判断自己的Qt库是多少位,有个误区就是很多人要么看成了QtCreator的关于信息中列出的位数,要么以为自己是64位的系统就认为是64位的Qt,最终要在Qt构建套件中查看具体位数,大概从Qt5.14开始基本上很少提供32位的库,尤其是Qt6.0以后基本上默认就是只有64位的库了,这也是顺应时代潮流,毕竟不久的将来(个人预计2030年以前)基本上32位的系统占比不超过1%,放心大胆的用64位的库吧,抛弃烦人的32位以及XP系统。Qt常用类的头文件的函数看完学完使用一遍并加以融会贯通,月薪30K起步。

Qt历险记,专注Qt技术,三年医疗设备研发经验,1年机器视觉研发经验,半年柔性传感研发经验。 506

单片机设计具备断电记忆功能的计时器

本文介绍了如何设计一款具备断电记忆功能的计时器,利用单片机和EEPROM存储器实现了计时器值的保存和恢复。当然,在实际的设计中还需要考虑其他因素,如电源管理、时钟精度等,以确保计时器的正常运行和准确性。选择合适的单片机:在设计计时器时,我们需要选择一款具备存储功能的单片机,以便在断电后能够保存计时器的状态。可以优化显示方式,使用更加直观的界面来展示计时器的值;函数中,我们首先从 EEPROM 中读取计时器的初始值,然后在一个无限循环中每秒钟增加计时器的值,并将新的值写入 EEPROM 中。

RlDart的博客 1101

电子元器件-三极管终终篇:三极管工作原理详解、参数/手册详解、开关应用详解、Ib电流研究、开关应用实例

三极管工作原理与应用摘要 三极管是一种电流控制器件,通过小基极电流控制大集电极电流。其内部结构由高掺杂发射区、薄低掺杂基区和中等掺杂集电区组成,形成NPN或PNP结。三极管有三种工作状态: 截止区:发射结和集电结均反偏,无放大作用 放大区:发射结正偏,集电结反偏,Ic=βIb 饱和区:两结均正偏,Ic不再随Ib增大 作为开关使用时,需确保三极管深度饱和(Vce≈0.2V)。设计要点包括: 基极电阻计算确保Ib足够大 集电极电阻控制Ic 基极加下拉电阻提高抗干扰 NPN管作地开关,PNP管作电源开关 典型应用

qq_60226558的博客 324

复现报告:《多回路人机控制系统仿真及II型PIO分析》方法复现与代码实现

本文复现了谭文倩硕士论文《多回路人机控制系统仿真及II型PIO分析》中的关键方法,重点实现了频域驾驶员模型辨识和参数灵敏度分析。通过数字化提取论文图表数据,构建了结构驾驶员模型传递函数,并验证了参数变化对系统特性的影响。采用MATLAB实现了描述函数计算、模型参数辨识和灵敏度分析算法,为后续神经网络模型辨识和II型PIO研究奠定了基础。由于缺乏原始实验数据,部分结果通过数值模拟获得,但仍有效重现了论文的核心分析方法。~~~~~

huanghm88的专栏 182

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

上一篇: 《童虎学习笔记》6分钟学会MySQL基于时间点的恢复(position方式)
下一篇: 《童虎学习笔记》5分钟Citus之SQL命令参考
童虎学习笔记
博客等级 码龄5年 104粉丝 39原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址