前言
- 近期学习了分布式数据库的工作原理,计划分两期分享单机版分布式数据库部署方案、以及多主机分布式数据库部署方案,今天先分享单机版部署方案。
一、Citus介绍
1.1、什么是Citus?
Citus 数据库是 Postgres 的一个开源扩展,它为您提供了 Postgres 的所有优点,无论规模如何 - 从单个节点到大型分布式数据库集群。由于 Citus 是 Postgres 的一个扩展(而不是分支),因此当您使用 Citus 时,您也在使用 Postgres。
您可以利用最新的 Postgres 功能、工具和生态系统。使用 Citus,您可以获得分布式 Postgres 功能,如分片、分布式表、引用表、分布式查询引擎、列式存储 - 并且从 Citus 11.0 开始,可以从任何节点进行查询。
Citus 结合了并行性、在内存中保留更多数据和更高的 I/O 带宽,可以显著提高多租户 SaaS 应用程序、面向客户的实时分析仪表板和时间序列工作负载的性能。
1.2、获取 Citus 的两种方法:
1、开源:Citus 是 100% 开源的。您可以下载 Citus 开源版,或者要查看源代码并自行构建,请访问 GitHub 上的 Citus 存储库。
2、托管服务:Citus 数据库作为托管服务在云中提供,并附带 Azure Cosmos DB for PostgreSQL,以前称为 Azure Database for PostgreSQL 中的 Hyperscale (Citus)。
- 备注:
1、Citus操作文档官网:https://docs.citusdata.com
2、Citus安装包官网:https://github.com/citusdata/citus/releases/tag/v12.1.5
1.3、Citus 为您提供任意规模的 Postgres
您可以开始在单个节点上使用 Citus,从一开始就使用分布式数据模型,这样您就可以“随时进行扩展”。当您的 Postgres 工作负载需要扩展时,可以轻松地将工作节点添加到 Citus 数据库集群,和/或扩展集群中的协调器和工作节点。
有时人们会问“Citus 可以扩展到多大?”以下是一些大型客户的示例——但请记住,还有很多 2 节点和 3 节点 Citus 集群。
- Algolia :每天提取 5-100 亿行数据
- Heap :7000 多亿个事件
- 100 节点 Citus 数据库集群上的 1.4PB 数据
- Pex : 每天更新 800 亿行数据
- 20 节点 Citus 数据库集群
- 2.4TB 内存、1280 个核心和 80TB 数据 …计划扩展到 45 个节点
- MixRank :10 PB 时间序列数据
1.4、何时使用 Citus
1、多租户 SaaS 数据库
大多数 B2B 应用程序已将租户、客户或帐户的概念内置于其数据模型中。在此模型中,数据库为许多租户提供服务,每个租户的数据都与其他租户分开。 Citus 为该工作负载提供全面的 SQL 覆盖,并支持将关系数据库扩展到 10 万多个租户。Citus 还为多租户添加了新功能。例如,Citus 支持租户隔离,为大型租户提供性能保证,并具有引用表的概念,以减少租户之间的数据重复。 这些功能可让您将租户数据扩展到多台机器,并轻松添加更多 CPU、内存和磁盘资源。此外,在多个租户之间共享相同的数据库架构可有效利用硬件资源并简化数据库管理。
2、Citus 对于多租户应用程序的一些优势:
-
为所有租户提供快速查询
-
在数据库中(而不是应用程序中)分片逻辑
-
在单节点 PostgreSQL 中保存比可能更多的数据
-
无需放弃 SQL 即可进行横向扩展
-
在高并发下保持性能
-
跨客户群进行快速指标分析
-
轻松扩展以处理新客户注册
-
隔离大客户和小客户的资源使用情况
3、实时分析
Citus 支持对大型数据集进行实时查询。这些查询通常发生在快速增长的事件系统或具有时间序列数据的系统中。示例用例包括:
-
具有亚秒级响应时间的分析仪表板
-
对正在发生的事件进行探索性询问
-
大型数据集存档和报告
-
使用漏斗、分段和群组查询分析会话
4、Citus 的优势在于它能够并行执行查询,并随着集群中的工作数据库数量线性扩展。Citus 对于实时应用程序的一些优势:
-
随着数据集的增长,保持亚秒级响应
-
实时分析新事件和新数据
-
并行化 SQL 查询
-
无需放弃 SQL
-
高并发下保持性能
-
快速响应仪表板查询
-
使用一个数据库,而不是拼凑的数据库
-
丰富的 PostgreSQL 数据类型和扩展
1.5、使用注意事项
Citus 扩展了 PostgreSQL 的分布式功能,但它并不是一个可以扩展所有工作负载的嵌入式替代品。高性能 Citus 集群需要考虑数据模型、工具和所使用的 SQL 功能的选择。
当 Citus不适合的场景
有些工作负载不需要强大的分布式数据库,而有些则需要工作节点之间有大量的信息流。在第一种情况下,Citus 是不必要的,在第二种情况下,Citus 通常性能不佳。以下是一些示例:
-
当您不希望您的工作负载超出单个 Postgres 节点时
-
离线分析,无需实时采集或实时查询
-
不需要支持大量并发用户的分析应用程序
-
返回数据密集型 ETL 结果而非摘要的查询
二、PostgreSQL部署
2.1、环境规划
| 主机名称 | IP地址 | PostgreSQL版本 | Citus版本 |
|---|---|---|---|
| CitusServer | 192.168.1.92 | 16.2 | 12.1-1 |
2.2、安装插件
yum -y install readline readline-devel zlib zlib-devel gettext gettext-devel openssl openssl-devel pam pam-devel libxml2 libxml2-devel libxslt libxslt-devel perl perl-devel tcl-devel uuid-devel gcc gcc-c++ make flex bison perl-ExtUtils* libicu libicu-devel libcurl-devell libevent-devel lz4-devel
2.3、创建用户
- 注:在主机点上创建DBA用户
groupadd postgres -g 4000
useradd postgres -g 4000 -u 4000
echo "postgres"|passwd --stdin postgres
2.4、所有节点配置sudo
sed -i.bak '100apostgres ALL=(ALL) NOPASSWD:ALL' /etc/sudoers
2.5、创建目录
| 目录编号 | 目录名称 | 备注 |
|---|---|---|
| 1 | /postgres | postgres根目录 |
| 2 | /postgres/server | 软件安装目录 |
| 3 | /postgres/data/citus/5000 | CN数据目录 |
| 4 | /postgres/data/citus/6000 | Work1数据目录 |
| 5 | /postgres/data/citus/7000 | Work2数据目录 |
| 6 | /postgres/data/citus/5000/log | CN日志目录 |
| 7 | /postgres/data/citus/6000/log | Work1日志目录 |
| 8 | /postgres/data/citus/7000/log | Work2日志目录 |
| 9 | insstall | /安装包上传目录 |
代码如下:
mkdir /install
chmod -R 777 /install
mkdir /postgres
mkdir -p /postgres/server /postgres/data/citus/5000 /postgres/data/citus/6000 /postgres/data/citus/7000
chown -R postgres:postgres /postgres /install
chmod 0775 /postgres
chmod 0700 /postgres/data
2.6、下载安装包
[root@CitusServer ~]$ su postgres
[postgres@CitusServer ~]$ cd /install
[postgres@CitusServer install]$ wget https://ftp.postgresql.org/pub/source/v16.2/postgresql-16.2.tar.gz
bash: wget: command not found
[postgres@CitusServer install]$ wget https://ftp.postgresql.org/pub/source/v16.2/postgresql-16.2.tar.gz
--2024-08-11 22:15:08-- https://ftp.postgresql.org/pub/source/v16.2/postgresql-16.2.tar.gz
Resolving ftp.postgresql.org (ftp.postgresql.org)... 72.32.157.246, 147.75.85.69, 87.238.57.227, ...
Connecting to ftp.postgresql.org (ftp.postgresql.org)|72.32.157.246|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 32558575 (31M) [application/octet-stream]
Saving to: ‘postgresql-16.2.tar.gz’
100%[==============================================================================>] 32,558,575 1.03MB/s in 21s
2024-08-11 22:15:30 (1.51 MB/s) - ‘postgresql-16.2.tar.gz’ saved [32558575/32558575]
[postgres@CitusServer install]$
2.7、编译安装PostgreSQL
[postgres@CitusServer install]$ cd postgresql-16.2
[postgres@CitusServer postgresql-16.2]$
[postgres@CitusServer postgresql-16.2]$ ./configure --prefix=/postgres/server --with-openssl
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking which template to use... linux
checking whether NLS is wanted... no
checking for default port number... 5432
checking for block size... 8kB
checking for segment size... 1GB
checking for WAL block size... 8kB
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
......................................................
config.status: creating GNUmakefile
config.status: creating src/Makefile.global
config.status: creating src/include/pg_config.h
config.status: creating src/include/pg_config_ext.h
config.status: creating src/interfaces/ecpg/include/ecpg_config.h
config.status: linking src/backend/port/tas/dummy.s to src/backend/port/tas.s
config.status: linking src/backend/port/posix_sema.c to src/backend/port/pg_sema.c
config.status: linking src/backend/port/sysv_shmem.c to src/backend/port/pg_shmem.c
config.status: linking src/include/port/linux.h to src/include/pg_config_os.h
config.status: linking src/makefiles/Makefile.linux to src/Makefile.port
[postgres@CitusServer postgresql-16.2]$
[postgres@CitusServer postgresql-16.2]$
2.8、安装编译文件
[postgres@CitusServer postgresql-16.2]$
[postgres@CitusServer postgresql-16.2]$ make && make install
2.9、创建超链接
su root
mkdir /postgresql
chmod -R 777 /postgresql
chown -R postgres:postgres /postgresql
cd /postgres
ln -s /postgres/server /postgresql
2.10、设置环境变量
vi /home/postgres/.bashrc
export PGHOME=/postgres/server
export PATH=$PGHOME/bin:$PATH
export LD_LIBRARY_PATH=$PGHOME/lib:$LD_LIBRARY_PATH
export PGDATA=/postgres/data/citus/7000
export PGPORT=7000
export PG_SERVER_NAME=worker01
export PS1='[\u@\h:\[\e[35m\]$PG_SERVER_NAME\[\e[m\]:\[\e[32m\]$PGPORT\[\e[m\] \w]\$'
source /home/postgres/.bashrc
2.11、初始化数据库
- CN节点:
[postgres@CitusServer ~]$ /postgres/server/bin/initdb -D /postgres/data/citus/5000
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
Data page checksums are disabled.
fixing permissions on existing directory /postgres/data/citus/5000 ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Asia/Shanghai
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok
initdb: warning: enabling "trust" authentication for local connections
initdb: hint: You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb.
Success. You can now start the database server using:
/postgres/server/bin/pg_ctl -D /postgres/data/citus/5000 -l logfile start
[postgres@CitusServer ~]$
- Work1节点:
[postgres@CitusServer ~]$
[postgres@CitusServer ~]$ /postgres/server/bin/initdb -D /postgres/data/citus/6000
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
Data page checksums are disabled.
fixing permissions on existing directory /postgres/data/citus/6000 ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Asia/Shanghai
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok
initdb: warning: enabling "trust" authentication for local connections
initdb: hint: You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb.
Success. You can now start the database server using:
/postgres/server/bin/pg_ctl -D /postgres/data/citus/6000 -l logfile start
[postgres@CitusServer ~]$
- Work2节点:
[postgres@CitusServer ~]$
[postgres@CitusServer ~]$ /postgres/server/bin/initdb -D /postgres/data/citus/7000
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
Data page checksums are disabled.
fixing permissions on existing directory /postgres/data/citus/7000 ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Asia/Shanghai
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok
initdb: warning: enabling "trust" authentication for local connections
initdb: hint: You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb.
Success. You can now start the database server using:
/postgres/server/bin/pg_ctl -D /postgres/data/citus/7000 -l logfile start
[postgres@CitusServer ~]$
2.12、修改3个实例的listen_addresses、port:
echo "PORT=5000">> /postgres/data/citus/5000/postgresql.conf
echo "PORT=6000">> /postgres/data/citus/6000/postgresql.conf
echo "PORT=7000">> /postgres/data/citus/7000/postgresql.conf
echo "listen_addresses='*'">> /postgres/data/citus/5000/postgresql.conf
echo "listen_addresses='*'">> /postgres/data/citus/6000/postgresql.conf
echo "listen_addresses='*'">> /postgres/data/citus/7000/postgresql.conf
[postgres@CitusServer ~]$ echo "PORT=5000">> /postgres/data/citus/5000/postgresql.conf
[postgres@CitusServer ~]$ echo "PORT=6000">> /postgres/data/citus/6000/postgresql.conf
[postgres@CitusServer ~]$ echo "PORT=7000">> /postgres/data/citus/7000/postgresql.conf
[postgres@CitusServer ~]$ echo "listen_addresses='*'">> /postgres/data/citus/5000/postgresql.conf
[postgres@CitusServer ~]$ echo "listen_addresses='*'">> /postgres/data/citus/6000/postgresql.conf
[postgres@CitusServer ~]$ echo "listen_addresses='*'">> /postgres/data/citus/7000/postgresql.conf
[postgres@CitusServer ~]$
2.13、创建日志存储目录
mkdir -p /postgres/data/citus/5000/log /postgres/data/citus/6000/log /postgres/data/citus/7000/log
chown -R postgres:postgres /postgres/data/citus/
chmod -R 777 /postgres/data/citus/5000/log /postgres/data/citus/6000/log /postgres/data/citus/7000/log
[postgres@CitusServer ~]$ sudo mkdir -p /postgres/data/citus/5000/log
[postgres@CitusServer ~]$ sudo mkdir -p /postgres/data/citus/6000/log
[postgres@CitusServer ~]$ sudo mkdir -p /postgres/data/citus/7000/log
[postgres@CitusServer ~]$
[postgres@CitusServer ~]$ sudo chown -R postgres:postgres /postgres/data/citus/
[postgres@CitusServer ~]$ sudo chmod -R 777 /postgres/data/citus/5000/log
[postgres@CitusServer ~]$ sudo chmod -R 777 /postgres/data/citus/6000/log
[postgres@CitusServer ~]$ sudo chmod -R 777 /postgres/data/citus/7000/log
[postgres@CitusServer ~]$
2.14、重启服务(CN、Work1、Work2)
[postgres@CitusServer ~]$
[postgres@CitusServer ~]$ /postgres/server/bin/pg_ctl start -D /postgres/data/citus/5000 -l /postgres/data/citus/5000/log/cnlog
waiting for server to start.... done
server started
[postgres@CitusServer ~]$ /postgres/server/bin/pg_ctl start -D /postgres/data/citus/6000 -l /postgres/data/citus/6000/log/work1log
waiting for server to start.... done
server started
[postgres@CitusServer ~]$
[postgres@CitusServer ~]$ /postgres/server/bin/pg_ctl start -D /postgres/data/citus/7000 -l /postgres/data/citus/7000/log/work2log
waiting for server to start.... done
server started
三、Citus部署
3.1、下载Citus
[postgres@CitusServer ~]$ cd /install/
[postgres@CitusServer install]$ wget https://github.com/citusdata/citus/archive/refs/tags/v12.1.5.tar.gz
--2024-08-11 22:30:40-- https://github.com/citusdata/citus/archive/refs/tags/v12.1.5.tar.gz
Resolving github.com (github.com)... 20.205.243.166
Connecting to github.com (github.com)|20.205.243.166|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://codeload.github.com/citusdata/citus/tar.gz/refs/tags/v12.1.5 [following]
--2024-08-11 22:30:47-- https://codeload.github.com/citusdata/citus/tar.gz/refs/tags/v12.1.5
Resolving codeload.github.com (codeload.github.com)... 20.205.243.165
Connecting to codeload.github.com (codeload.github.com)|20.205.243.165|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [application/x-gzip]
Saving to: ‘v12.1.5.tar.gz’
[ <=> ] 6,912,425 24.7KB/s in 4m 31s
2024-08-11 22:31:20 (24.9 KB/s) - ‘v12.1.5.tar.gz’ saved [6912425]
[postgres@CitusServer install]$
3.2、编译安装Citus
[postgres@CitusServer citus-12.1.5]$ ./autogen.sh
[postgres@CitusServer citus-12.1.5]$ ./configure --prefix=/postgres/citus
checking for a sed that does not truncate output... /usr/bin/sed
checking for gawk... gawk
checking for flex... /usr/bin/flex
checking for pg_config... /postgres/server/bin/pg_config
configure: building against PostgreSQL 16
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking size of void *... 8
checking whether gcc supports -std=gnu99... yes
checking whether gcc supports -Wall... yes
checking whether gcc supports -Wextra... yes
checking whether gcc supports -Wno-unused-parameter... yes
checking whether gcc supports -Wno-sign-compare... yes
checking whether gcc supports -Wno-missing-field-initializers... yes
checking whether gcc supports -Wno-clobbered... yes
checking whether gcc supports -Wno-gnu-variable-sized-type-not-at-end... no
checking whether gcc supports -Wno-declaration-after-statement... yes
checking whether gcc supports -Wendif-labels... yes
checking whether gcc supports -Wmissing-format-attribute... yes
checking whether gcc supports -Wmissing-declarations... yes
checking whether gcc supports -Wmissing-prototypes... yes
checking whether gcc supports -Wshadow... yes
checking whether gcc supports -Werror=vla... yes
checking whether gcc supports -Werror=implicit-int... yes
checking whether gcc supports -Werror=implicit-function-declaration... yes
checking whether gcc supports -Werror=return-type... yes
checking whether gcc supports -fstack-clash-protection... yes
checking for curl_global_init in -lcurl... yes
checking curl/curl.h usability... yes
checking curl/curl.h presence... yes
checking for curl/curl.h... yes
checking for LZ4_compress_default in -llz4... yes
checking lz4.h usability... yes
checking lz4.h presence... yes
checking for lz4.h... yes
checking for ZSTD_decompress in -lzstd... no
configure: error: zstd library not found
If you have zstd installed, see config.log for details on the
failure. It is possible the compiler isn't looking in the proper directory.
Use --without-zstd to disable zstd support.
[postgres@CitusServer citus-12.1.5]$
3.3、修改pg_hba.conf
- 增加:host all 0.0.0.0/0 SCRAM-SHA-256
[postgres@CitusServer citus-12.1.5]$ vi /postgres/data/citus/5000/pg_hba.conf
[postgres@CitusServer citus-12.1.5]$
[postgres@CitusServer citus-12.1.5]$ vi /postgres/data/citus/6000/pg_hba.conf
[postgres@CitusServer citus-12.1.5]$
[postgres@CitusServer citus-12.1.5]$ vi /postgres/data/citus/7000/pg_hba.conf
[postgres@CitusServer citus-12.1.5]$
3.4、重启服务(CN节点、Work1节点、Work2节点)
- CN节点:
[postgres@CitusServer citus-12.1.5]$
[postgres@CitusServer citus-12.1.5]$ pg_ctl -D /postgres/data/citus/5000 restart
waiting for server to shut down.... done
server stopped
waiting for server to start....2024-08-11 22:45:13.400 CST [24393] LOG: starting PostgreSQL 16.2 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44), 64-bit
2024-08-11 22:45:13.401 CST [24393] LOG: listening on IPv4 address "0.0.0.0", port 5000
2024-08-11 22:45:13.401 CST [24393] LOG: listening on IPv6 address "::", port 5000
2024-08-11 22:45:13.405 CST [24393] LOG: listening on Unix socket "/tmp/.s.PGSQL.5000"
2024-08-11 22:45:13.409 CST [24396] LOG: database system was shut down at 2024-08-11 22:45:13 CST
2024-08-11 22:45:13.413 CST [24393] LOG: database system is ready to accept connections
done
server started
[postgres@CitusServer citus-12.1.5]$
- Work1节点:
[postgres@CitusServer citus-12.1.5]$
[postgres@CitusServer citus-12.1.5]$ pg_ctl -D /postgres/data/citus/6000 restart
waiting for server to shut down.... done
server stopped
waiting for server to start....2024-08-11 22:50:18.152 CST [24402] LOG: starting PostgreSQL 16.2 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44), 64-bit
2024-08-11 22:50:18.153 CST [24402] LOG: listening on IPv4 address "0.0.0.0", port 6000
2024-08-11 22:50:18.153 CST [24402] LOG: listening on IPv6 address "::", port 6000
2024-08-11 22:50:18.156 CST [24402] LOG: listening on Unix socket "/tmp/.s.PGSQL.6000"
2024-08-11 22:50:18.159 CST [24405] LOG: database system was shut down at 2024-08-11 22:50:18 CST
2024-08-11 22:50:18.163 CST [24402] LOG: database system is ready to accept connections
done
server started
[postgres@CitusServer citus-12.1.5]$
- Work2节点:
[postgres@CitusServer citus-12.1.5]$
[postgres@CitusServer citus-12.1.5]$ pg_ctl -D /postgres/data/citus/7000 restart
waiting for server to shut down.... done
server stopped
waiting for server to start....2024-08-11 22:50:21.632 CST [24410] LOG: starting PostgreSQL 16.2 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44), 64-bit
2024-08-11 22:50:21.633 CST [24410] LOG: listening on IPv4 address "0.0.0.0", port 7000
2024-08-11 22:50:21.633 CST [24410] LOG: listening on IPv6 address "::", port 7000
2024-08-11 22:50:21.637 CST [24410] LOG: listening on Unix socket "/tmp/.s.PGSQL.7000"
2024-08-11 22:50:21.640 CST [24413] LOG: database system was shut down at 2024-08-11 22:50:21 CST
2024-08-11 22:50:21.643 CST [24410] LOG: database system is ready to accept connections
done
server started
[postgres@CitusServer citus-12.1.5]$
3.5、修改扩展
[postgres@CitusServer citus-12.1.5]$ psql -p 5000
psql (16.2)
Type "help" for help.
postgres=#
postgres=# create extension citus;
2024-08-11 22:52:24.675 CST [26362] LOG: received SIGHUP, reloading configuration files
2024-08-11 22:52:24.675 CST [26362] LOG: parameter "ssl" changed to "on"
2024-08-11 22:52:24.675 CST [26362] LOG: parameter "ssl_ciphers" changed to "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA384"
CREATE EXTENSION
postgres=#
postgres=#
[postgres@CitusServer ~]$ psql -p 6000
psql (16.2)
Type "help" for help.
postgres=#
postgres=# create extension citus;
2024-08-11 22:53:13.938 CST [26404] LOG: citus extension created on postgres without ssl enabled, turning it on during creation of the extension
2024-08-11 22:53:13.938 CST [26404] CONTEXT: SQL statement "SELECT citus_setup_ssl()"
PL/pgSQL function inline_code_block line 5 at PERFORM
2024-08-11 22:53:13.938 CST [26404] STATEMENT: create extension citus;
2024-08-11 22:53:13.942 CST [26404] LOG: no certificate present, generating self signed certificate
2024-08-11 22:53:13.942 CST [26404] CONTEXT: SQL statement "SELECT citus_setup_ssl()"
PL/pgSQL function inline_code_block line 5 at PERFORM
2024-08-11 22:53:13.942 CST [26404] STATEMENT: create extension citus;
2024-08-11 22:53:13.992 CST [26381] LOG: received SIGHUP, reloading configuration files
2024-08-11 22:53:13.992 CST [26381] LOG: parameter "ssl" changed to "on"
2024-08-11 22:53:13.992 CST [26381] LOG: parameter "ssl_ciphers" changed to "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA384"
CREATE EXTENSION
postgres=#
postgres=# \q
[postgres@CitusServer ~]$ psql -p 7000
psql (16.2)
Type "help" for help.
postgres=#
postgres=# create extension citus;
2024-08-11 22:55:35.724 CST [26406] LOG: citus extension created on postgres without ssl enabled, turning it on during creation of the extension
2024-08-11 22:55:35.724 CST [26406] CONTEXT: SQL statement "SELECT citus_setup_ssl()"
PL/pgSQL function inline_code_block line 5 at PERFORM
2024-08-11 22:55:35.724 CST [26406] STATEMENT: create extension citus;
2024-08-11 22:55:35.730 CST [26406] LOG: no certificate present, generating self signed certificate
2024-08-11 22:55:35.730 CST [26406] CONTEXT: SQL statement "SELECT citus_setup_ssl()"
PL/pgSQL function inline_code_block line 5 at PERFORM
2024-08-11 22:55:35.730 CST [26406] STATEMENT: create extension citus;
2024-08-11 22:55:36.149 CST [26393] LOG: received SIGHUP, reloading configuration files
2024-08-11 22:55:36.150 CST [26393] LOG: parameter "ssl" changed to "on"
2024-08-11 22:55:36.150 CST [26393] LOG: parameter "ssl_ciphers" changed to "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA384"
CREATE EXTENSION
postgres=#
postgres=#
3.6、查看插件
postgres=# \dx
List of installed extensions
Name | Version | Schema | Description
----------------+---------+------------+------------------------------
citus | 12.1-1 | pg_catalog | Citus distributed database
citus_columnar | 11.3-1 | pg_catalog | Citus Columnar extension
plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language
(3 rows)
postgres=#
3.7、查看Citus支持的函数
postgres=#
postgres=# \dx+ citus
Objects in extension "citus"
Object description
----------------------------------------------------------------------------------------------------------
---------------
event trigger citus_cascade_to_partition
function alter_distributed_table(regclass,text,integer,text,boolean)
function alter_old_partitions_set_access_method(regclass,timestamp with time zone,name)
function alter_role_if_exists(text,text)
function alter_table_set_access_method(regclass,text)
function array_cat_agg(anycompatiblearray)
function assign_distributed_transaction_id(integer,bigint,timestamp with time zone)
function authinfo_valid(text)
function broadcast_intermediate_result(text,text)
function check_distributed_deadlocks()
function citus_activate_node(text,integer)
function citus_add_inactive_node(text,integer,integer,noderole,name)
function citus_add_local_table_to_metadata(regclass,boolean)
function citus_add_node(text,integer,integer,noderole,name)
function citus_add_rebalance_strategy(name,regproc,regproc,regproc,real,real,real)
function citus_add_secondary_node(text,integer,text,integer,name)
function citus_backend_gpid()
function citus_blocking_pids(integer)
function citus_calculate_gpid(integer,integer)
function citus_check_cluster_node_health()
function citus_check_connection_to_node(text,integer)
function citus_cleanup_orphaned_resources()
function citus_cleanup_orphaned_shards()
function citus_conninfo_cache_invalidate()
function citus_coordinator_nodeid()
function citus_copy_shard_placement(bigint,integer,integer,citus.shard_transfer_mode)
function citus_copy_shard_placement(bigint,text,integer,text,integer,citus.shard_transfer_mode)
function citus_create_restore_point(text)
function citus_disable_node(text,integer,boolean)
function citus_dist_local_group_cache_invalidate()
function citus_dist_node_cache_invalidate()
function citus_dist_object_cache_invalidate()
function citus_dist_partition_cache_invalidate()
function citus_dist_placement_cache_invalidate()
function citus_dist_shard_cache_invalidate()
function citus_drain_node(text,integer,citus.shard_transfer_mode,name)
function citus_drop_all_shards(regclass,text,text,boolean)
function citus_drop_trigger()
function citus_executor_name(integer)
function citus_extradata_container(internal)
function citus_finalize_upgrade_to_citus11(boolean)
function citus_finish_citus_upgrade()
function citus_finish_pg_upgrade()
function citus_get_active_worker_nodes()
function citus_get_node_clock()
function citus_get_transaction_clock()
function citus_internal_add_colocation_metadata(integer,integer,integer,regtype,oid)
function citus_internal_add_object_metadata(text,text[],text[],integer,integer,boolean)
function citus_internal_add_partition_metadata(regclass,"char",text,integer,"char")
function citus_internal_add_placement_metadata(bigint,bigint,integer,bigint)
function citus_internal_add_placement_metadata(bigint,integer,bigint,integer,bigint)
function citus_internal_add_shard_metadata(regclass,bigint,"char",text,text)
function citus_internal_add_tenant_schema(oid,integer)
function citus_internal_adjust_local_clock_to_remote(cluster_clock)
function citus_internal_delete_colocation_metadata(integer)
function citus_internal_delete_partition_metadata(regclass)
function citus_internal_delete_placement_metadata(bigint)
function citus_internal_delete_shard_metadata(bigint)
function citus_internal_delete_tenant_schema(oid)
function citus_internal.find_groupid_for_node(text,integer)
function citus_internal_global_blocked_processes()
function citus_internal_is_replication_origin_tracking_active()
function citus_internal_local_blocked_processes()
function citus_internal_mark_node_not_synced(integer,integer)
function citus_internal.pg_dist_node_trigger_func()
function citus_internal.pg_dist_rebalance_strategy_trigger_func()
function citus_internal.pg_dist_shard_placement_trigger_func()
function citus_internal.refresh_isolation_tester_prepared_statement()
function citus_internal.replace_isolation_tester_func()
function citus_internal.restore_isolation_tester_func()
function citus_internal_start_replication_origin_tracking()
function citus_internal_stop_replication_origin_tracking()
function citus_internal_unregister_tenant_schema_globally(oid,text)
function citus_internal_update_none_dist_table_metadata(oid,"char",bigint,boolean)
function citus_internal_update_placement_metadata(bigint,integer,integer)
function citus_internal_update_relation_colocation(oid,integer)
function citus_is_clock_after(cluster_clock,cluster_clock)
function citus_is_coordinator()
function citus_isolation_test_session_is_blocked(integer,integer[])
function citus_job_cancel(bigint)
function citus_job_list()
function citus_job_status(bigint,boolean)
function citus_job_wait(bigint,citus_job_status)
function citus_jsonb_concatenate_final(jsonb)
function citus_jsonb_concatenate(jsonb,jsonb)
function citus_json_concatenate_final(json)
function citus_json_concatenate(json,json)
function citus_local_disk_space_stats()
function citus_locks()
function citus_move_shard_placement(bigint,integer,integer,citus.shard_transfer_mode)
function citus_move_shard_placement(bigint,text,integer,text,integer,citus.shard_transfer_mode)
function citus_node_capacity_1(integer)
function citus_nodeid_for_gpid(bigint)
function citus_nodename_for_nodeid(integer)
function citus_nodeport_for_nodeid(integer)
function citus_pause_node_within_txn(integer,boolean,integer)
function citus_pid_for_gpid(bigint)
function citus_prepare_pg_upgrade()
function citus_query_stats()
function citus_rebalance_start(name,boolean,citus.shard_transfer_mode)
function citus_rebalance_status(boolean)
function citus_rebalance_stop()
function citus_rebalance_wait()
function citus_relation_size(regclass)
function citus_remote_connection_stats()
function citus_remove_node(text,integer)
function citus_run_local_command(text)
function citus_schema_distribute(regnamespace)
function citus_schema_move(regnamespace,integer,citus.shard_transfer_mode)
function citus_schema_move(regnamespace,text,integer,citus.shard_transfer_mode)
function citus_schema_undistribute(regnamespace)
function citus_server_id()
function citus_set_coordinator_host(text,integer,noderole,name)
function citus_set_default_rebalance_strategy(text)
function citus_set_node_property(text,integer,text,boolean)
function citus_shard_allowed_on_node_true(bigint,integer)
function citus_shard_cost_1(bigint)
function citus_shard_cost_by_disk_size(bigint)
function citus_shard_indexes_on_worker()
function citus_shard_sizes()
function citus_shards_on_worker()
function citus_split_shard_by_split_points(bigint,text[],integer[],citus.shard_transfer_mode)
function citus_stat_activity()
function citus_stat_statements()
function citus_stat_statements_reset()
function citus_stat_tenants(boolean)
function citus_stat_tenants_local(boolean)
function citus_stat_tenants_local_internal(boolean)
function citus_stat_tenants_local_reset()
function citus_stat_tenants_reset()
function citus_table_is_visible(oid)
function citus_table_size(regclass)
function citus_task_wait(bigint,citus_task_status)
function citus_text_send_as_jsonb(text)
function citus_total_relation_size(regclass,boolean)
function citus_truncate_trigger()
function citus_unmark_object_distributed(oid,oid,integer)
function citus_update_node(integer,text,integer,boolean,integer)
function citus_update_shard_statistics(bigint)
function citus_update_table_statistics(regclass)
function citus_validate_rebalance_strategy_functions(regproc,regproc,regproc)
function citus_version()
function cluster_clock_cmp(cluster_clock,cluster_clock)
function cluster_clock_eq(cluster_clock,cluster_clock)
function cluster_clock_ge(cluster_clock,cluster_clock)
function cluster_clock_gt(cluster_clock,cluster_clock)
function cluster_clock_in(cstring)
function cluster_clock_le(cluster_clock,cluster_clock)
function cluster_clock_logical(cluster_clock)
function cluster_clock_lt(cluster_clock,cluster_clock)
function cluster_clock_ne(cluster_clock,cluster_clock)
function cluster_clock_out(cluster_clock)
function cluster_clock_recv(internal)
function cluster_clock_send(cluster_clock)
function column_name_to_column(regclass,text)
function column_to_column_name(regclass,text)
function coord_combine_agg_ffunc(internal,oid,cstring,anyelement)
function coord_combine_agg(oid,cstring,anyelement)
function coord_combine_agg_sfunc(internal,oid,cstring,anyelement)
function create_distributed_function(regprocedure,text,text,boolean)
function create_distributed_table_concurrently(regclass,text,citus.distribution_type,text,integer)
function create_distributed_table(regclass,text,citus.distribution_type,text,integer)
function create_intermediate_result(text,text)
function create_reference_table(regclass)
function create_time_partitions(regclass,interval,timestamp with time zone,timestamp with time zone)
function distributed_tables_colocated(regclass,regclass)
function drop_old_time_partitions(regclass,timestamp with time zone)
function dump_global_wait_edges()
function dump_local_wait_edges()
function fetch_intermediate_results(text[],text,integer)
function fix_all_partition_shard_index_names()
function fix_partition_shard_index_names(regclass)
function fix_pre_citus10_partitioned_table_constraint_names()
function fix_pre_citus10_partitioned_table_constraint_names(regclass)
function get_all_active_transactions()
function get_colocated_shard_array(bigint)
function get_colocated_table_array(regclass)
function get_current_transaction_id()
function get_global_active_transactions()
function get_missing_time_partition_ranges(regclass,interval,timestamp with time zone,timestamp with time
zone)
function get_nodeid_for_groupid(integer)
function get_rebalance_progress()
function get_rebalance_table_shards_plan(regclass,real,integer,bigint[],boolean,name,real)
function get_shard_id_for_distribution_column(regclass,"any")
function isolate_tenant_to_new_shard(regclass,"any",text,citus.shard_transfer_mode)
function jsonb_cat_agg(jsonb)
function json_cat_agg(json)
function lock_relation_if_exists(text,text)
function lock_shard_metadata(integer,bigint[])
function lock_shard_resources(integer,bigint[])
function master_activate_node(text,integer)
function master_add_inactive_node(text,integer,integer,noderole,name)
function master_add_node(text,integer,integer,noderole,name)
function master_add_secondary_node(text,integer,text,integer,name)
function master_copy_shard_placement(bigint,text,integer,text,integer,boolean,citus.shard_transfer_mode)
function master_create_empty_shard(text)
function master_disable_node(text,integer)
function master_drain_node(text,integer,citus.shard_transfer_mode,name)
function master_get_active_worker_nodes()
function master_get_new_placementid()
function master_get_new_shardid()
function master_get_table_ddl_events(text)
function master_move_shard_placement(bigint,text,integer,text,integer,citus.shard_transfer_mode)
function master_remove_distributed_table_metadata_from_workers(regclass,text,text)
function master_remove_node(text,integer)
function master_remove_partition_metadata(regclass,text,text)
function master_run_on_worker(text[],integer[],text[],boolean)
function master_set_node_property(text,integer,text,boolean)
function master_unmark_object_distributed(oid,oid,integer)
function master_update_node(integer,text,integer,boolean,integer)
function master_update_shard_statistics(bigint)
function master_update_table_statistics(regclass)
function notify_constraint_dropped()
function pg_cancel_backend(bigint)
function pg_terminate_backend(bigint,bigint)
function poolinfo_valid(text)
function read_intermediate_results(text[],citus_copy_format)
function read_intermediate_result(text,citus_copy_format)
function rebalance_table_shards(regclass,real,integer,bigint[],citus.shard_transfer_mode,boolean,name)
function recover_prepared_transactions()
function relation_is_a_known_shard(regclass)
function remove_local_tables_from_metadata()
function replicate_reference_tables(citus.shard_transfer_mode)
function replicate_table_shards(regclass,integer,integer,bigint[],citus.shard_transfer_mode)
function role_exists(name)
function run_command_on_all_nodes(text,boolean,boolean)
function run_command_on_colocated_placements(regclass,regclass,text,boolean)
function run_command_on_coordinator(text,boolean)
function run_command_on_placements(regclass,text,boolean)
function run_command_on_shards(regclass,text,boolean)
function run_command_on_workers(text,boolean)
function shard_name(regclass,bigint)
function start_metadata_sync_to_all_nodes()
function start_metadata_sync_to_node(text,integer)
function stop_metadata_sync_to_node(text,integer,boolean)
function time_partition_range(regclass)
function truncate_local_data_after_distributing_table(regclass)
function undistribute_table(regclass,boolean)
function update_distributed_table_colocation(regclass,text)
function worker_adjust_identity_column_seq_ranges(regclass)
function worker_apply_inter_shard_ddl_command(bigint,text,bigint,text,text)
function worker_apply_sequence_command(text)
function worker_apply_sequence_command(text,regtype)
function worker_apply_shard_ddl_command(bigint,text)
function worker_apply_shard_ddl_command(bigint,text,text)
function worker_change_sequence_dependency(regclass,regclass,regclass)
function worker_copy_table_to_node(regclass,integer)
function worker_create_or_alter_role(text,text,text)
function worker_create_or_replace_object(text)
function worker_create_or_replace_object(text[])
function worker_create_truncate_trigger(regclass)
function worker_drop_all_shell_tables(boolean)
function worker_drop_distributed_table(text)
function worker_drop_sequence_dependency(text)
function worker_drop_shell_table(text)
function worker_fix_partition_shard_index_names(regclass,text,text)
function worker_fix_pre_citus10_partitioned_table_constraint_names(regclass,bigint,text)
function worker_hash("any")
function worker_last_saved_explain_analyze()
function worker_nextval(regclass)
function worker_partial_agg_ffunc(internal)
function worker_partial_agg(oid,anyelement)
function worker_partial_agg_sfunc(internal,oid,anyelement)
function worker_partitioned_relation_size(regclass)
function worker_partitioned_relation_total_size(regclass)
function worker_partitioned_table_size(regclass)
function worker_partition_query_result(text,text,integer,citus.distribution_type,text[],text[],boolean,bo
olean,boolean)
function worker_record_sequence_dependency(regclass,regclass,name)
function worker_save_query_explain_analyze(text,jsonb)
function worker_split_copy(bigint,text,split_copy_info[])
function worker_split_shard_release_dsm()
function worker_split_shard_replication_setup(split_shard_info[],bigint)
operator class cluster_clock_ops for access method btree
operator <=(cluster_clock,cluster_clock)
operator <>(cluster_clock,cluster_clock)
operator <(cluster_clock,cluster_clock)
operator =(cluster_clock,cluster_clock)
operator >=(cluster_clock,cluster_clock)
operator >(cluster_clock,cluster_clock)
operator family cluster_clock_ops for access method btree
schema citus
schema citus_internal
sequence pg_dist_background_job_job_id_seq
sequence pg_dist_background_task_task_id_seq
sequence pg_dist_cleanup_recordid_seq
sequence pg_dist_clock_logical_seq
sequence pg_dist_colocationid_seq
sequence pg_dist_groupid_seq
sequence pg_dist_node_nodeid_seq
sequence pg_dist_operationid_seq
sequence pg_dist_placement_placementid_seq
sequence pg_dist_shardid_seq
table pg_dist_authinfo
table pg_dist_background_job
table pg_dist_background_task
table pg_dist_background_task_depend
table pg_dist_cleanup
table pg_dist_colocation
table pg_dist_local_group
table pg_dist_node
table pg_dist_node_metadata
table pg_dist_object
table pg_dist_partition
table pg_dist_placement
table pg_dist_poolinfo
table pg_dist_rebalance_strategy
table pg_dist_schema
table pg_dist_shard
table pg_dist_transaction
type citus_copy_format
type citus.distribution_type
type citus_job_status
type citus.shard_transfer_mode
type citus_task_status
type cluster_clock
type noderole
type replication_slot_info
type split_copy_info
type split_shard_info
view citus_dist_stat_activity
view citus_locks
view citus_lock_waits
view citus_schemas
view citus_shard_indexes_on_worker
view citus_shards
view citus_shards_on_worker
view citus_stat_activity
view citus_stat_statements
view citus_stat_tenants
view citus_stat_tenants_local
view citus_tables
view pg_dist_shard_placement
view time_partitions
(333 rows)
Objects in extension "citus_columnar"
Object description
-------------------------------------------------------------------------------
access method columnar
function alter_columnar_table_reset(regclass,boolean,boolean,boolean,boolean)
function alter_columnar_table_set(regclass,integer,integer,name,integer)
function columnar.get_storage_id(regclass)
function columnar_internal.columnar_ensure_am_depends_catalog()
function columnar_internal.columnar_handler(internal)
function columnar_internal.downgrade_columnar_storage(regclass)
function columnar_internal.upgrade_columnar_storage(regclass)
schema columnar
schema columnar_internal
sequence columnar_internal.storageid_seq
table columnar_internal.chunk
table columnar_internal.chunk_group
table columnar_internal.options
table columnar_internal.stripe
view columnar.chunk
view columnar.chunk_group
view columnar.options
view columnar.storage
view columnar.stripe
(20 rows)
Objects in extension "plpgsql"
Object description
-------------------------------------------
function plpgsql_call_handler()
function plpgsql_inline_handler(internal)
function plpgsql_validator(oid)
language plpgsql
(4 rows)
postgres=#
3.8、 登录CN节点,分别添加Work1、Work2
[postgres@CitusServer ~]$ psql -p 5000
postgres=#
postgres=# select * from master_add_node('192.168.1.92' ,6000);
2024-08-11 22:58:49.855 CST [26542] LOG: starting maintenance daemon on database 5 user 10
2024-08-11 22:58:49.855 CST [26542] CONTEXT: Citus maintenance daemon for database 5 user 10
postgres=# select * from master_add_node('192.168.1.92' ,7000);
2024-08-11 22:58:49.855 CST [26542] LOG: starting maintenance daemon on database 5 user 10
2024-08-11 22:58:49.855 CST [26542] CONTEXT: Citus maintenance daemon for database 5 user 10
3.9、查看分片主机
postgres=#
postgres=# SELECT * FROM master_get_active_worker_nodes();
192.168.1.92 | 6000
192.168.1.92 | 7000
postgres=#
四、查看分片情况
4.1、登录CN节点,创建分布表
说明:创建分布式测试表example_table,主键ID是id,批量创建 50000000条记录,分片数量(citus.shard_count)是2,副本数量(citus.shard_replication_factor)是2
[postgres@CitusServer ~]$ psql -p 5000
CREATE TABLE example_table (
id INT UNIQUE NOT NULL,
name VARCHAR(100));
ALTER TABLE example_table ADD PRIMARY KEY (id);
set citus.shard_count =2;
set citus.shard_replication_factor =2;
select create_distributed_table('example_table','id','hash');
insert into example_table select id,md5(random()::text) from generate_series(1,50000000) as id;
4.2、登录CN节点,查询分布表信息
说明:example_table分片数量是2,表大小是21GB,主键是id。
postgres=# select * from citus_tables ;
table_name | citus_table_type | distribution_column | colocation_id | table_size | shard_count | table_owner | acces
s_method
---------------+------------------+---------------------+---------------+------------+-------------+-------------+------
---------
example_table | distributed | id | 1 | 21 GB | 2 | postgres | heap
(1 row)
4.2、查看分片情况
postgres=#
postgres=# select * from pg_dist_shard_placement;
shardid | shardstate | shardlength | nodename | nodeport | placementid
---------+------------+-------------+--------------+----------+-------------
102008 | 1 | 0 | 192.168.1.92 | 6000 | 1
102009 | 1 | 0 | 192.168.1.92 | 6000 | 4
102008 | 1 | 0 | 192.168.1.92 | 7000 | 2
102009 | 1 | 0 | 192.168.1.92 | 7000 | 3
(4 rows)
postgres=#
4.3、通过执行计划查看分布表
postgres=#
postgres=# EXPLAIN select * from example_table;
QUERY PLAN
-----------------------------------------------------------------------------------------------------------
Custom Scan (Citus Adaptive) (cost=0.00..0.00 rows=100000 width=222)
Task Count: 2
Tasks Shown: One of 2
-> Task
Node: host=192.168.1.92 port=6000 dbname=postgres
-> Seq Scan on example_table_102008 example_table (cost=0.00..916786.80 rows=50004280 width=37)
(6 rows)
postgres=#
五、总结
5.1、 Citus还提供了多种优化性能的功能
-
列式存储:Citus支持列式存储模式,这种存储方式特别适合于分析型查询,因为它可以减少I/O操作的数量。
-
内存缓存:为了提高查询速度,Citus可以在内存中缓存经常访问的数据集。
-
自定义函数与聚合:用户可以为Citus编写自定义函数和聚合方法,以实现特定的业务逻辑。
5.2、功能强大
Citus分布式数据库是一个功能强大且易于扩展的数据库解决方案,尤其适合用于处理大规模的数据分析工作负载。随着微软的收购,我们可以预见Citus将在未来的云数据服务领域扮演更加重要的角色。




