【clickhouse】未解决 ClickHouse exception, code: 1002 DB::Exception: Directory already exists

这篇博客讨论了ClickHouse在后台合并数据时遇到的错误,即目录已存在导致的MergeTask执行失败。错误信息显示目录/var/lib/clickhouse/data/quant/trade_record/tmp_merge_2012_210_215_1/无法被删除,可能是由于之前的合并操作未正常完成。解决方案包括检查是否有其他进程占用,手动删除目录,重启服务或重新安装ClickHouse。建议在操作前备份数据以防止数据丢失。

在这里插入图片描述

1.概述

clickhouse 报错如下

SQL 错误 [1002]: ClickHouse exception, code: 1002, host: localhost, port: 8123; Code: 84. DB::Exception: Directory /var/lib/clickhouse/data/quant/trade_record/tmp_merge_2012_210_215_1/ already exists. (DIRECTORY_ALREADY_EXISTS) (version 21.11.4.14 (official build))

后台merge的时候报错这个怎么办?一直报这个

怀疑是 断电了 或者重启了 导致合成成功了 但是删除没成功

异常栈如下

2021.11.29 05:44:38.294340 [ 71 ] {} <Error> void DB::MergeTreeBackgroundExecutor<DB::MergeMutateRuntimeQueue>::routine(DB::TaskRuntimeDataPtr) [Queue = DB::MergeMutateRuntimeQueue]: Code: 84. DB::Exception: Directory /var/lib/clickhouse/data/quant/price_1m/tmp_merge_201403_3_45_1/ already exists. (DIRECTORY_ALREADY_EXISTS), Stack trace (when copying this message, always include the lines below):

0. DB::Exception::Exception(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int, bool) @ 0x9b605d4 in /usr/bin/clickhouse
1. DB::MergeTask::ExecuteAndFinalizeHorizontalPart::prepare() @ 0x12d388fc in /usr/bin/clickhouse
2. bool std::__1::__function::__policy_invoker<bool ()>::__call_impl<std::__1::__function::__default_alloc_func<DB::MergeTask::ExecuteAndFinalizeHorizontalPart::subtasks::'lambda'(), bool ()> >(std::__1::__function::__policy_storage const*) @ 0x12d45c89 in /usr/bin/clickhouse
3. DB::MergeTask::ExecuteAndFinalizeHorizontalPart::execute() @ 0x12d3c90b in /usr/bin/clickhouse
4. DB::MergeTask::execute() @ 0x12d415fa in /usr/bin/clickhouse
5. DB::MergePlainMergeTreeTask::executeStep() @ 0x12fbc4ac in /usr/bin/clickhouse
6. DB::MergeTreeBackgroundExecutor<DB::MergeMutateRuntimeQueue>::routine(std::__1::shared_ptr<DB::TaskRuntimeData>) @ 0x12d5005d in /usr/bin/clickhouse
7. DB::MergeTreeBackgroundExecutor<DB::MergeMutateRuntimeQueue>::threadFunction() @ 0x12d50afa in /usr/bin/clickhouse
8. ThreadPoolImpl<ThreadFromGlobalPool>::worker(std::__1::__list_iterator<ThreadFromGlobalPool, void*>) @ 0x9ba528a in /usr/bin/clickhouse
9. ThreadFromGlobalPool::ThreadFromGlobalPool<void ThreadPoolImpl<ThreadFromGlobalPool>::scheduleImpl<void>(std::__1::function<void ()>, int, std::__1::optional<unsigned long>)::'lambda0'()>(void&&, void ThreadPoolImpl<ThreadFromGlobalPool>::scheduleImpl<void>(std::__1::function<void ()>, int, std::__1::optional<unsigned long>)::'lambda0'()&&...)::'lambda'()::operator()() @ 0x9ba70a7 in /usr/bin/clickhouse
10. ThreadPoolImpl<std::__1::thread>::worker(std::__1::__list_iterator<std::__1::thread, void*>) @ 0x9ba2697 in /usr/bin/clickhouse
11. ? @ 0x9ba609d in /usr/bin/clickhouse
12. start_thread @ 0x9609 in /usr/lib/x86_64-linux-gnu/libpthread-2.31.so
13. clone @ 0x122293 in /usr/lib/x86_64-linux-gnu/libc-2.31.so
 (version 21.11.4.14 (official build))

这个错误提示是因为目录/var/lib/clickhouse/data/quant/trade_record/tmp_merge_2012_210_215_1/已经存在,导致合并操作无法继续进行。可能的原因是在之前执行的合并操作中出现了异常,未能成功删除该目录。

解决方法如下:

  1. 首先,确认是否有其他进程正在使用ClickHouse,如果有,请等待其他操作完成后再尝试。

  2. 进入ClickHouse的数据存储目录/var/lib/clickhouse/data/quant/trade_record/,查看是否有名为tmp_merge_2012_210_215_1的目录。如果存在,可以尝试手动删除该目录。

  3. 如果无法删除该目录,可以尝试重启ClickHouse服务,然后再次尝试删除该目录。

  4. 如果仍然无法解决问题,建议备份数据后,卸载并重新安装ClickHouse,然后将备份数据恢复到新安装的ClickHouse中。

[omm@ogserver ~]$ cd /opt/openGauss/script/ [omm@ogserver script]$ ./gs_install -X /home/omm/cluster_config.xml Parsing the configuration file. Check preinstall on every node. Successfully checked preinstall on every node. Creating the backup directory. Successfully created the backup directory. begin deploy.. Installing the cluster. begin prepare Install Cluster.. Checking the installation environment on all nodes. begin install Cluster.. Installing applications on all nodes. Successfully installed APP. begin init Instance.. encrypt cipher and rand files for database. Please enter password for database: Please repeat for database: begin to create CA cert files The sslcert will be generated in /opt/openGauss/app/share/sslcert/om NO cm_server instance, no need to create CA for CM. Non-dss_ssl_enable, no need to create CA for DSS Cluster installation is completed. Configuring. Deleting instances from all nodes. Successfully deleted instances from all nodes. Checking node configuration on all nodes. Initializing instances on all nodes. Updating instance configuration on all nodes. Check consistence of memCheck and coresCheck on database nodes. Configuring pg_hba on all nodes. Configuration is completed. Using omm:dbgrp to install database. Using installation program path : /opt/openGauss/app_48a25b11 $GAUSSHOME points to /opt/openGauss/app_48a25b11, no need to create symbolic link. Traceback (most recent call last): File "/opt/openGauss/install/om/script/local/Install.py", line 812, in <module> functionDict[g_opts.action]() File "/opt/openGauss/install/om/script/local/Install.py", line 743, in startCluster dn.start(self.time_out) File "/opt/openGauss/install/om/script/local/../gspylib/component/Kernel/Kernel.py", line 104, in start raise Exception(ErrorCode.GAUSS_516["GAUSS_51607"] % "instance" Exception: [GAUSS-51607] : Failed to start instance. Error: Please check the gs_ctl log for failure details. [2025-11-14 10:39:29.779][21269][][gs_ctl]: gs_ctl started,datadir is /data/openGauss [2025-11-14 10:39:29.805][21269][][gs_ctl]: waiting for server to start... .0 LOG: [Alarm Module]can not read GAUSS_WARNING_TYPE env. 0 LOG: [Alarm Module]Host Name: ogserver 0 LOG: [Alarm Module]Host IP: ogserver. Copy hostname directly in case of taking 10s to use 'gethostbyname' when /etc/hosts does not contain <HOST IP> 0 LOG: [Alarm Module]Cluster Name: openGauss 0 LOG: [Alarm Module]Invalid data in AlarmItem file! Read alarm English name failed! line: 58 0 WARNING: failed to open feature control file, please check whether it exists: FileName=gaussdb.version, Errno=2, Errmessage=No such file or directory. 0 WARNING: failed to parse feature control file: gaussdb.version. 0 WARNING: Failed to load the product control file, so gaussdb cannot distinguish product version. 0 LOG: bbox_dump_path is set to /opt/openGauss/corefile/ 2025-11-14 10:39:29.865 69169661.1 [unknown] 22564786671680 [unknown] 0 dn_6001 DB010 0 [REDO] LOG: Recovery parallelism, cpu count = 22, max = 4, actual = 4 2025-11-14 10:39:29.865 69169661.1 [unknown] 22564786671680 [unknown] 0 dn_6001 DB010 0 [REDO] LOG: ConfigRecoveryParallelism, true_max_recovery_parallelism:4, max_recovery_parallelism:4 gaussdb.state does not exist, and skipt setting since it is optional.2025-11-14 10:39:29.881 69169661.1 [unknown] 22564786671680 [unknown] 0 dn_6001 00000 0 [BACKEND] LOG: [Alarm Module]can not read GAUSS_WARNING_TYPE env. 2025-11-14 10:39:29.881 69169661.1 [unknown] 22564786671680 [unknown] 0 dn_6001 00000 0 [BACKEND] LOG: [Alarm Module]Host Name: ogserver 2025-11-14 10:39:29.881 69169661.1 [unknown] 22564786671680 [unknown] 0 dn_6001 00000 0 [BACKEND] LOG: [Alarm Module]Host IP: ogserver. Copy hostname directly in case of taking 10s to use 'gethostbyname' when /etc/hosts does not contain <HOST IP> 2025-11-14 10:39:29.881 69169661.1 [unknown] 22564786671680 [unknown] 0 dn_6001 00000 0 [BACKEND] LOG: [Alarm Module]Cluster Name: openGauss 2025-11-14 10:39:29.881 69169661.1 [unknown] 22564786671680 [unknown] 0 dn_6001 00000 0 [BACKEND] LOG: [Alarm Module]Invalid data in AlarmItem file! Read alarm English name failed! line: 58 2025-11-14 10:39:29.915 69169661.1 [unknown] 22564786671680 [unknown] 0 dn_6001 00000 0 [BACKEND] LOG: loaded library "security_plugin" 2025-11-14 10:39:29.939 69169661.1 [unknown] 22564786671680 [unknown] 0 dn_6001 01000 0 [BACKEND] WARNING: could not create any HA TCP/IP sockets 2025-11-14 10:39:29.939 69169661.1 [unknown] 22564786671680 [unknown] 0 dn_6001 01000 0 [BACKEND] WARNING: could not create any HA TCP/IP sockets 2025-11-14 10:39:29.990 69169661.1 [unknown] 22564786671680 [unknown] 0 dn_6001 00000 0 [BACKEND] LOG: InitNuma numaNodeNum: 1 numa_distribute_mode: none inheritThreadPool: 0. 2025-11-14 10:39:29.991 69169661.1 [unknown] 22564786671680 [unknown] 0 dn_6001 01000 0 [BACKEND] WARNING: Failed to initialize the memory protect for g_instance.attr.attr_storage.cstore_buffers (1024 Mbytes) or shared memory (4477 Mbytes) is larger. 2025-11-14 10:39:29.991 69169661.1 [unknown] 22564786671680 [unknown] 0 dn_6001 00000 0 [BACKEND] LOG: shared memory that key is 15400001 is owned by pid 5620 2025-11-14 10:39:30.275 69169661.1 [unknown] 22564786671680 [unknown] 0 dn_6001 00000 0 [CACHE] LOG: set data cache size(805306368) 2025-11-14 10:39:30.706 69169661.1 [unknown] 22564786671680 [unknown] 0 dn_6001 00000 0 [SEGMENT_PAGE] LOG: Segment-page constants: DF_MAP_SIZE: 8156, DF_MAP_BIT_CNT: 65248, DF_MAP_GROUP_EXTENTS: 4175872, IPBLOCK_SIZE: 8168, EXTENTS_PER_IPBLOCK: 1021, IPBLOCK_GROUP_SIZE: 4090, BMT_HEADER_LEVEL0_TOTAL_PAGES: 8323072, BktMapEntryNumberPerBlock: 2038, BktMapBlockNumber: 25, BktBitMaxMapCnt: 512 2025-11-14 10:39:30.774 69169661.1 [unknown] 22564786671680 [unknown] 0 dn_6001 00000 0 [BACKEND] LOG: gaussdb: fsync file "/data/openGauss/gaussdb.state.temp" success 2025-11-14 10:39:30.774 69169661.1 [unknown] 22564786671680 [unknown] 0 dn_6001 00000 0 [BACKEND] LOG: create gaussdb state file success: db state(STARTING_STATE), server mode(Normal), connection index(1) 2025-11-14 10:39:30.800 69169661.1 [unknown] 22564786671680 [unknown] 0 dn_6001 00000 0 [BACKEND] LOG: max_safe_fds = 974, usable_fds = 1000, already_open = 16 bbox_dump_path is set to /opt/openGauss/corefile/ 2025-11-14 10:39:30.802 69169661.1 [unknown] 22564786671680 [unknown] 0 dn_6001 00000 0 [BACKEND] LOG: user configure file is not found, it will be created. [2025-11-14 10:39:35.812][21269][][gs_ctl]: gaussDB state is Coredump [2025-11-14 10:39:35.812][21269][][gs_ctl]: stopped waiting [2025-11-14 10:39:35.812][21269][][gs_ctl]: could not start server Examine the log output. [GAUSS-51607] : Failed to start instance. Error: Please check the gs_ctl log for failure details. [2025-11-14 10:39:29.779][21269][][gs_ctl]: gs_ctl started,datadir is /data/openGauss [2025-11-14 10:39:29.805][21269][][gs_ctl]: waiting for server to start... .0 LOG: [Alarm Module]can not read GAUSS_WARNING_TYPE env. 0 LOG: [Alarm Module]Host Name: ogserver 0 LOG: [Alarm Module]Host IP: ogserver. Copy hostname directly in case of taking 10s to use 'gethostbyname' when /etc/hosts does not contain <HOST IP> 0 LOG: [Alarm Module]Cluster Name: openGauss 0 LOG: [Alarm Module]Invalid data in AlarmItem file! Read alarm English name failed! line: 58 0 WARNING: failed to open feature control file, please check whether it exists: FileName=gaussdb.version, Errno=2, Errmessage=No such file or directory. 0 WARNING: failed to parse feature control file: gaussdb.version. 0 WARNING: Failed to load the product control file, so gaussdb cannot distinguish product version. 0 LOG: bbox_dump_path is set to /opt/openGauss/corefile/ 2025-11-14 10:39:29.865 69169661.1 [unknown] 22564786671680 [unknown] 0 dn_6001 DB010 0 [REDO] LOG: Recovery parallelism, cpu count = 22, max = 4, actual = 4 2025-11-14 10:39:29.865 69169661.1 [unknown] 22564786671680 [unknown] 0 dn_6001 DB010 0 [REDO] LOG: ConfigRecoveryParallelism, true_max_recovery_parallelism:4, max_recovery_parallelism:4 gaussdb.state does not exist, and skipt setting since it is optional.2025-11-14 10:39:29.881 69169661.1 [unknown] 22564786671680 [unknown] 0 dn_6001 00000 0 [BACKEND] LOG: [Alarm Module]can not read GAUSS_WARNING_TYPE env. 2025-11-14 10:39:29.881 69169661.1 [unknown] 22564786671680 [unknown] 0 dn_6001 00000 0 [BACKEND] LOG: [Alarm Module]Host Name: ogserver 2025-11-14 10:39:29.881 69169661.1 [unknown] 22564786671680 [unknown] 0 dn_6001 00000 0 [BACKEND] LOG: [Alarm Module]Host IP: ogserver. Copy hostname directly in case of taking 10s to use 'gethostbyname' when /etc/hosts does not contain <HOST IP> 2025-11-14 10:39:29.881 69169661.1 [unknown] 22564786671680 [unknown] 0 dn_6001 00000 0 [BACKEND] LOG: [Alarm Module]Cluster Name: openGauss 2025-11-14 10:39:29.881 69169661.1 [unknown] 22564786671680 [unknown] 0 dn_6001 00000 0 [BACKEND] LOG: [Alarm Module]Invalid data in AlarmItem file! Read alarm English name failed! line: 58 2025-11-14 10:39:29.915 69169661.1 [unknown] 22564786671680 [unknown] 0 dn_6001 00000 0 [BACKEND] LOG: loaded library "security_plugin" 2025-11-14 10:39:29.939 69169661.1 [unknown] 22564786671680 [unknown] 0 dn_6001 01000 0 [BACKEND] WARNING: could not create any HA TCP/IP sockets 2025-11-14 10:39:29.939 69169661.1 [unknown] 22564786671680 [unknown] 0 dn_6001 01000 0 [BACKEND] WARNING: could not create any HA TCP/IP sockets 2025-11-14 10:39:29.990 69169661.1 [unknown] 22564786671680 [unknown] 0 dn_6001 00000 0 [BACKEND] LOG: InitNuma numaNodeNum: 1 numa_distribute_mode: none inheritThreadPool: 0. 2025-11-14 10:39:29.991 69169661.1 [unknown] 22564786671680 [unknown] 0 dn_6001 01000 0 [BACKEND] WARNING: Failed to initialize the memory protect for g_instance.attr.attr_storage.cstore_buffers (1024 Mbytes) or shared memory (4477 Mbytes) is larger. 2025-11-14 10:39:29.991 69169661.1 [unknown] 22564786671680 [unknown] 0 dn_6001 00000 0 [BACKEND] LOG: shared memory that key is 15400001 is owned by pid 5620 2025-11-14 10:39:30.275 69169661.1 [unknown] 22564786671680 [unknown] 0 dn_6001 00000 0 [CACHE] LOG: set data cache size(805306368) 2025-11-14 10:39:30.706 69169661.1 [unknown] 22564786671680 [unknown] 0 dn_6001 00000 0 [SEGMENT_PAGE] LOG: Segment-page constants: DF_MAP_SIZE: 8156, DF_MAP_BIT_CNT: 65248, DF_MAP_GROUP_EXTENTS: 4175872, IPBLOCK_SIZE: 8168, EXTENTS_PER_IPBLOCK: 1021, IPBLOCK_GROUP_SIZE: 4090, BMT_HEADER_LEVEL0_TOTAL_PAGES: 8323072, BktMapEntryNumberPerBlock: 2038, BktMapBlockNumber: 25, BktBitMaxMapCnt: 512 2025-11-14 10:39:30.774 69169661.1 [unknown] 22564786671680 [unknown] 0 dn_6001 00000 0 [BACKEND] LOG: gaussdb: fsync file "/data/openGauss/gaussdb.state.temp" success 2025-11-14 10:39:30.774 69169661.1 [unknown] 22564786671680 [unknown] 0 dn_6001 00000 0 [BACKEND] LOG: create gaussdb state file success: db state(STARTING_STATE), server mode(Normal), connection index(1) 2025-11-14 10:39:30.800 69169661.1 [unknown] 22564786671680 [unknown] 0 dn_6001 00000 0 [BACKEND] LOG: max_safe_fds = 974, usable_fds = 1000, already_open = 16 bbox_dump_path is set to /opt/openGauss/corefile/ 2025-11-14 10:39:30.802 69169661.1 [unknown] 22564786671680 [unknown] 0 dn_6001 00000 0 [BACKEND] LOG: user configure file is not found, it will be created. [2025-11-14 10:39:35.812][21269][][gs_ctl]: gaussDB state is Coredump [2025-11-14 10:39:35.812][21269][][gs_ctl]: stopped waiting [2025-11-14 10:39:35.812][21269][][gs_ctl]: could not start server Examine the log output. [omm@ogserver script]$
最新发布
11-15
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

九师兄

你的鼓励是我做大写作的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值