ClickHouse: MaterializedPostgres stuck if one of the table doesn't contain primary key, crash when attach/detach table

You have to provide the following information whenever possible.

Describe what’s wrong

CREATE DATABASE IF NOT EXISTS db1
ENGINE = MaterializedPostgreSQL('x-x-db-production.x.us-west-2.rds.amazonaws.com', 'x', 'rw_user', 'xxx');
SHOW TABLES FROM db1;

the database source is RDS, after executing those command the clickhouse-client suddenly closed.

Does it reproduce on recent release?

yes, this is the most recent release

ClickHouse client version 22.1.3.7 (official build).
Connecting to localhost:9000 as user default.
Connected to ClickHouse server version 22.1.3 revision 54455.

Enable crash reporting

If possible, change “enabled” to true in “send_crash_reports” section in config.xml:

ok done

How to reproduce

  1. create materializepostgres database from rds
  2. after few seconds it shows:
Connecting to localhost:9000 as user default.
Exception on client:
Code: 210. DB::NetException: Connection refused (localhost:9000). (NETWORK_ERROR)
  1. the server logs shows:
2022.01.26 18:31:54.861183 [ 19100 ] {} <Fatal> Application: Child process was terminated by signal 9 (KILL). If it is not done by 'forcestop' command or manually, the possible cause is OOM Killer (see 'dmesg' and look at the '/var/log/kern.log' for the details).
2022.01.26 18:32:26.943725 [ 23856 ] {} <Warning> Application: Calculated checksum of the binary: 38FD0E3944230CBD1E0C1028A9D68C83. There is no information about the reference checksum.
2022.01.26 18:32:29.034545 [ 24010 ] {} <Warning> PostgreSQLReplicationHandler: Publication solo_prod_ch_publication already exists and tables list is empty. Assuming publication is correct.
2022.01.26 18:32:29.066844 [ 24010 ] {} <Error> void DB::PostgreSQLReplicationHandler::startSynchronization(bool): Code: 60. DB::Exception: Table solo_prod.user_push_tokens doesn't exist: while loading table solofunds.user_push_tokens. (UNKNOWN_TABLE), 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) @ 0xa82d07a in /usr/bin/clickhouse
1. DB::Exception::Exception<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >(int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&&) @ 0xa89b823 in /usr/bin/clickhouse
2. void std::__1::__optional_storage_base<DB::Exception, false>::__construct<int const&, char const (&) [23], std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >(int const&, char const (&) [23], std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&&) @ 0x1352ac0f in /usr/bin/clickhouse
3. DB::DatabaseCatalog::getTableImpl(DB::StorageID const&, std::__1::shared_ptr<DB::Context const>, std::__1::optional<DB::Exception>*) const @ 0x13519082 in /usr/bin/clickhouse
4. DB::DatabaseCatalog::getTable(DB::StorageID const&, std::__1::shared_ptr<DB::Context const>) const @ 0x1352126b in /usr/bin/clickhouse
5. DB::StorageMaterializedPostgreSQL::getNested() const @ 0x132f2c25 in /usr/bin/clickhouse
6. DB::PostgreSQLReplicationHandler::startSynchronization(bool) @ 0x132d640e in /usr/bin/clickhouse
7. DB::DatabaseMaterializedPostgreSQL::startSynchronization() @ 0x132c435f in /usr/bin/clickhouse
8. DB::BackgroundSchedulePoolTaskInfo::execute() @ 0x12f8470e in /usr/bin/clickhouse
9. DB::BackgroundSchedulePool::threadFunction() @ 0x12f870a7 in /usr/bin/clickhouse
10. ? @ 0x12f88170 in /usr/bin/clickhouse
11. ThreadPoolImpl<std::__1::thread>::worker(std::__1::__list_iterator<std::__1::thread, void*>) @ 0xa86f4b7 in /usr/bin/clickhouse
12. ? @ 0xa872ebd in /usr/bin/clickhouse
13. ? @ 0x7f10e173c609 in ?
14. __clone @ 0x7f10e1663293 in ?
(version 22.1.3.7 (official build))
  1. open new clickchouse-client, it would stuck before the prompt
  2. open another clickhouse-client, then both now shows the query prompt
  • Which ClickHouse server version to use: 22.1.3.7
  • Non-default settings, if any
<allow_experimental_database_materialized_postgresql>1</allow_experimental_database_materialized_postgresql>
  • CREATE TABLE statements for all tables involved
CREATE DATABASE IF NOT EXISTS db1
ENGINE = MaterializedPostgreSQL('x-x-db-production.x.us-west-2.rds.amazonaws.com', 'x', 'rw_user', 'xxx');
  • Queries to run that lead to unexpected result that create table, after crash it would only shows 5-10 tables (first crash only show 10, i drop table and create again, it only show 5 tables):
5 rows in set. Elapsed: 0.002 sec.

Expected behavior

  1. not crashing
  2. if crash it would resume
  3. if table has no replica identity it should keep going with other tables

A clear and concise description of what you expected to happen.

Error message and/or stacktrace

If applicable, add screenshots to help explain your problem.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 16 (5 by maintainers)

Most upvoted comments

ok, I ll close this issue for now, the crash is fixed and there was a warning in documentation that if tables do not have primary key, then replica identity index needs to be added, otherwise it will not work. And for better usability I’ll make a change soon to allow to silently skip tables without primary key and no replica identity index.

another proof, after dropping database and recreate database with 1 table that crashed above it works (materialized_postgresql_tables_list = 'collection_fees'), but crash if attaching table that previously doesn’t crash (initial table on previous step):

SHOW TABLES FROM solo_prod

Query id: f499c5d9-3147-44be-bc62-6d954bf6ddce

┌─name─────────────┐
│ collections_fees │
└──────────────────┘

ATTACH TABLE collections;

ATTACH TABLE collections

Query id: a816477e-2a5c-480b-adde-3a98d4e5498c

[ip-172-31-27-232] 2022.01.26 19:17:17.769222 [ 81341 ] <Fatal> BaseDaemon: ########################################
[ip-172-31-27-232] 2022.01.26 19:17:17.769515 [ 81341 ] <Fatal> BaseDaemon: (version 22.1.3.7 (official build), build id: D11BC54A7FE20E44) (from thread 78316) (query_id: a816477e-2a5c-480b-adde-3a98d4e5498c) Received signal Segmentation fault (11)
[ip-172-31-27-232] 2022.01.26 19:17:17.769624 [ 81341 ] <Fatal> BaseDaemon: Address: 0xe8 Access: read. Address not mapped to object.
[ip-172-31-27-232] 2022.01.26 19:17:17.769720 [ 81341 ] <Fatal> BaseDaemon: Stack trace: 0x1331521a 0x132e937f 0x132c71c1 0x132c6677 0x139d421c 0x139cec0d 0x139d64ab 0x13d1434c 0x13d11e55 0x147f050f 0x14804259 0x1745e52f 0x17460981 0x17611609 0x1760ed00 0x7f8e6d650609 0x7f8e6d577293
[ip-172-31-27-232] 2022.01.26 19:17:17.769887 [ 81341 ] <Fatal> BaseDaemon: 2. std::__1::pair<std::__1::__hash_iterator<std::__1::__hash_node<std::__1::__hash_value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, DB::MaterializedPostgreSQLConsumer::StorageData>, void*>*>, bool> std::__1::__hash_table<std::__1::__hash_value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, DB::MaterializedPostgreSQLConsumer::StorageData>, std::__1::__unordered_map_hasher<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::__hash_value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, DB::MaterializedPostgreSQLConsumer::StorageData>, std::__1::hash<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::equal_to<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, true>, std::__1::__unordered_map_equal<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::__hash_value_type<std::__1::basic_string<char,std::__1::char_traits<char>, std::__1::allocator<char> >, DB::MaterializedPostgreSQLConsumer::StorageData>, std::__1::equal_to<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::hash<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, true>, std::__1::allocator<std::__1::__hash_value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, DB::MaterializedPostgreSQLConsumer::StorageData> > >::__emplace_unique_key_args<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, DB::StorageInfo&>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, DB::StorageInfo&) @ 0x1331521a in /usr/bin/clickhouse
[ip-172-31-27-232] 2022.01.26 19:17:17.770121 [ 81341 ] <Fatal> BaseDaemon: 3. DB::PostgreSQLReplicationHandler::addTableToReplication(DB::StorageMaterializedPostgreSQL*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) @ 0x132e937f in /usr/bin/clickhouse
[ip-172-31-27-232] 2022.01.26 19:17:17.770220 [ 81341 ] <Fatal> BaseDaemon: 4. DB::DatabaseMaterializedPostgreSQL::attachTable(std::__1::shared_ptr<DB::Context const>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::shared_ptr<DB::IStorage> const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) @ 0x132c71c1 in /usr/bin/clickhouse
[ip-172-31-27-232] 2022.01.26 19:17:17.770346 [ 81341 ] <Fatal> BaseDaemon: 5. DB::DatabaseMaterializedPostgreSQL::createTable(std::__1::shared_ptr<DB::Context const>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::shared_ptr<DB::IStorage> const&, std::__1::shared_ptr<DB::IAST> const&) @ 0x132c6677 in /usr/bin/clickhouse
[ip-172-31-27-232] 2022.01.26 19:17:17.770457 [ 81341 ] <Fatal> BaseDaemon: 6. DB::InterpreterCreateQuery::doCreateTable(DB::ASTCreateQuery&, DB::InterpreterCreateQuery::TableProperties const&) @ 0x139d421c in /usr/bin/clickhouse
[ip-172-31-27-232] 2022.01.26 19:17:17.770564 [ 81341 ] <Fatal> BaseDaemon: 7. DB::InterpreterCreateQuery::createTable(DB::ASTCreateQuery&) @ 0x139cec0d in /usr/bin/clickhouse
[ip-172-31-27-232] 2022.01.26 19:17:17.770662 [ 81341 ] <Fatal> BaseDaemon: 8. DB::InterpreterCreateQuery::execute() @ 0x139d64ab in /usr/bin/clickhouse
[ip-172-31-27-232] 2022.01.26 19:17:17.770746 [ 81341 ] <Fatal> BaseDaemon: 9. ? @ 0x13d1434c in /usr/bin/clickhouse
[ip-172-31-27-232] 2022.01.26 19:17:17.770844 [ 81341 ] <Fatal> BaseDaemon: 10. DB::executeQuery(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::shared_ptr<DB::Context>, bool, DB::QueryProcessingStage::Enum) @ 0x13d11e55 in /usr/bin/clickhouse
[ip-172-31-27-232] 2022.01.26 19:17:17.770948 [ 81341 ] <Fatal> BaseDaemon: 11. DB::TCPHandler::runImpl() @ 0x147f050f in /usr/bin/clickhouse
[ip-172-31-27-232] 2022.01.26 19:17:17.771777 [ 81341 ] <Fatal> BaseDaemon: 12. DB::TCPHandler::run() @ 0x14804259 in /usr/bin/clickhouse
[ip-172-31-27-232] 2022.01.26 19:17:17.772375 [ 81341 ] <Fatal> BaseDaemon: 13. Poco::Net::TCPServerConnection::start() @ 0x1745e52f in /usr/bin/clickhouse
[ip-172-31-27-232] 2022.01.26 19:17:17.772471 [ 81341 ] <Fatal> BaseDaemon: 14. Poco::Net::TCPServerDispatcher::run() @ 0x17460981 in /usr/bin/clickhouse
[ip-172-31-27-232] 2022.01.26 19:17:17.772567 [ 81341 ] <Fatal> BaseDaemon: 15. Poco::PooledThread::run() @ 0x17611609 in /usr/bin/clickhouse
[ip-172-31-27-232] 2022.01.26 19:17:17.772678 [ 81341 ] <Fatal> BaseDaemon: 16. Poco::ThreadImpl::runnableEntry(void*) @ 0x1760ed00 in /usr/bin/clickhouse
[ip-172-31-27-232] 2022.01.26 19:17:17.772784 [ 81341 ] <Fatal> BaseDaemon: 17. ? @ 0x7f8e6d650609 in ?
[ip-172-31-27-232] 2022.01.26 19:17:17.772874 [ 81341 ] <Fatal> BaseDaemon: 18. __clone @ 0x7f8e6d577293 in ?
[ip-172-31-27-232] 2022.01.26 19:17:17.932486 [ 81341 ] <Fatal> BaseDaemon: Calculated checksum of the binary: 38FD0E3944230CBD1E0C1028A9D68C83. There is no information about the reference checksum.

no error after attach

this one after drop database and only attach 1 on create database materializepostgres (materialized_postgresql_tables_list = 'collections'):

SHOW TABLES;
┌─name────────┐
│ collections │
└─────────────┘
1 rows in set. Elapsed: 0.003 sec.

ATTACH TABLE collections_fees;

[ip-172-31-27-232] 2022.01.26 19:08:42.898185 [ 70147 ] <Fatal> BaseDaemon: ########################################
[ip-172-31-27-232] 2022.01.26 19:08:42.898383 [ 70147 ] <Fatal> BaseDaemon: (version 22.1.3.7 (official build), build id: D11BC54A7FE20E44) (from thread 62162) (query_id: 02e48c3b-cf52-4275-96a1-59811c422ac0) Received signal Segmentation fault (11)
[ip-172-31-27-232] 2022.01.26 19:08:42.898487 [ 70147 ] <Fatal> BaseDaemon: Address: 0xe8 Access: read. Address not mapped to object.
[ip-172-31-27-232] 2022.01.26 19:08:42.898585 [ 70147 ] <Fatal> BaseDaemon: Stack trace: 0x1331521a 0x132e937f 0x132c71c1 0x132c6677 0x139d421c 0x139cec0d 0x139d64ab 0x13d1434c 0x13d11e55 0x147f050f 0x14804259 0x1745e52f 0x17460981 0x17611609 0x1760ed00 0x7f075d0a9609 0x7f075cfd0293
[ip-172-31-27-232] 2022.01.26 19:08:42.898771 [ 70147 ] <Fatal> BaseDaemon: 2. std::__1::pair<std::__1::__hash_iterator<std::__1::__hash_node<std::__1::__hash_value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, DB::MaterializedPostgreSQLConsumer::StorageData>, void*>*>, bool> std::__1::__hash_table<std::__1::__hash_value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, DB::MaterializedPostgreSQLConsumer::StorageData>, std::__1::__unordered_map_hasher<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::__hash_value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, DB::MaterializedPostgreSQLConsumer::StorageData>, std::__1::hash<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::equal_to<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, true>, std::__1::__unordered_map_equal<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::__hash_value_type<std::__1::basic_string<char,std::__1::char_traits<char>, std::__1::allocator<char> >, DB::MaterializedPostgreSQLConsumer::StorageData>, std::__1::equal_to<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::hash<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, true>, std::__1::allocator<std::__1::__hash_value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, DB::MaterializedPostgreSQLConsumer::StorageData> > >::__emplace_unique_key_args<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, DB::StorageInfo&>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, DB::StorageInfo&) @ 0x1331521a in /usr/bin/clickhouse
[ip-172-31-27-232] 2022.01.26 19:08:42.899173 [ 70147 ] <Fatal> BaseDaemon: 3. DB::PostgreSQLReplicationHandler::addTableToReplication(DB::StorageMaterializedPostgreSQL*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) @ 0x132e937f in /usr/bin/clickhouse
[ip-172-31-27-232] 2022.01.26 19:08:42.899282 [ 70147 ] <Fatal> BaseDaemon: 4. DB::DatabaseMaterializedPostgreSQL::attachTable(std::__1::shared_ptr<DB::Context const>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::shared_ptr<DB::IStorage> const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) @ 0x132c71c1 in /usr/bin/clickhouse
[ip-172-31-27-232] 2022.01.26 19:08:42.899406 [ 70147 ] <Fatal> BaseDaemon: 5. DB::DatabaseMaterializedPostgreSQL::createTable(std::__1::shared_ptr<DB::Context const>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::shared_ptr<DB::IStorage> const&, std::__1::shared_ptr<DB::IAST> const&) @ 0x132c6677 in /usr/bin/clickhouse
[ip-172-31-27-232] 2022.01.26 19:08:42.899524 [ 70147 ] <Fatal> BaseDaemon: 6. DB::InterpreterCreateQuery::doCreateTable(DB::ASTCreateQuery&, DB::InterpreterCreateQuery::TableProperties const&) @ 0x139d421c in /usr/bin/clickhouse
[ip-172-31-27-232] 2022.01.26 19:08:42.899631 [ 70147 ] <Fatal> BaseDaemon: 7. DB::InterpreterCreateQuery::createTable(DB::ASTCreateQuery&) @ 0x139cec0d in /usr/bin/clickhouse
[ip-172-31-27-232] 2022.01.26 19:08:42.900717 [ 70147 ] <Fatal> BaseDaemon: 8. DB::InterpreterCreateQuery::execute() @ 0x139d64ab in /usr/bin/clickhouse
[ip-172-31-27-232] 2022.01.26 19:08:42.900813 [ 70147 ] <Fatal> BaseDaemon: 9. ? @ 0x13d1434c in /usr/bin/clickhouse
[ip-172-31-27-232] 2022.01.26 19:08:42.900909 [ 70147 ] <Fatal> BaseDaemon: 10. DB::executeQuery(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::shared_ptr<DB::Context>, bool, DB::QueryProcessingStage::Enum) @ 0x13d11e55 in /usr/bin/clickhouse
[ip-172-31-27-232] 2022.01.26 19:08:42.903322 [ 70147 ] <Fatal> BaseDaemon: 11. DB::TCPHandler::runImpl() @ 0x147f050f in /usr/bin/clickhouse
[ip-172-31-27-232] 2022.01.26 19:08:42.903437 [ 70147 ] <Fatal> BaseDaemon: 12. DB::TCPHandler::run() @ 0x14804259 in /usr/bin/clickhouse
[ip-172-31-27-232] 2022.01.26 19:08:42.903547 [ 70147 ] <Fatal> BaseDaemon: 13. Poco::Net::TCPServerConnection::start() @ 0x1745e52f in /usr/bin/clickhouse
[ip-172-31-27-232] 2022.01.26 19:08:42.903643 [ 70147 ] <Fatal> BaseDaemon: 14. Poco::Net::TCPServerDispatcher::run() @ 0x17460981 in /usr/bin/clickhouse
[ip-172-31-27-232] 2022.01.26 19:08:42.903747 [ 70147 ] <Fatal> BaseDaemon: 15. Poco::PooledThread::run() @ 0x17611609 in /usr/bin/clickhouse
[ip-172-31-27-232] 2022.01.26 19:08:42.903859 [ 70147 ] <Fatal> BaseDaemon: 16. Poco::ThreadImpl::runnableEntry(void*) @ 0x1760ed00 in /usr/bin/clickhouse
[ip-172-31-27-232] 2022.01.26 19:08:42.903964 [ 70147 ] <Fatal> BaseDaemon: 17. ? @ 0x7f075d0a9609 in ?
[ip-172-31-27-232] 2022.01.26 19:08:42.904068 [ 70147 ] <Fatal> BaseDaemon: 18. __clone @ 0x7f075cfd0293 in ?
[ip-172-31-27-232] 2022.01.26 19:08:43.123177 [ 70147 ] <Fatal> BaseDaemon: Calculated checksum of the binary: 38FD0E3944230CBD1E0C1028A9D68C83. There is no information about the reference checksum.