Clickhouse: How to select/insert between different tables stored in different database on different machine?

Created on 10 Mar 2020  Â·  2Comments  Â·  Source: ClickHouse/ClickHouse

Hello all,

I have two machines each with a database named 'default' and a table named 'Demo'.

The step I am using to backup data from machine 1 to machine 2 is as follows:

1> dump data from machine1.default.Demo to a local file
2> copy the dumped file to machine2
3> import the dumped file into machine2.default.Demo

Question> Is there a better way that I could directly dump the data from machine1.default.Demo and directly insert into the machine2.default.Demo without using the intermediate file?

Thank you

question question-answered

Most helpful comment

https://clickhouse.tech/docs/en/query_language/table_functions/remote/

insert into xxx select * from remote('addresses_expr', db, xxx, 'user', 'password')
or
insert into function remote('addresses_expr', db, xxx, 'user', 'password') select * from xxx

or unix pipe
clickhouse-client -h remotehost -u user .... -q 'select * from xxx format Native' | clickhouse-client -q 'insert into xxx format Native'

https://clickhouse.tech/docs/en/operations/utils/clickhouse-copier/

All 2 comments

https://clickhouse.tech/docs/en/query_language/table_functions/remote/

insert into xxx select * from remote('addresses_expr', db, xxx, 'user', 'password')
or
insert into function remote('addresses_expr', db, xxx, 'user', 'password') select * from xxx

or unix pipe
clickhouse-client -h remotehost -u user .... -q 'select * from xxx format Native' | clickhouse-client -q 'insert into xxx format Native'

https://clickhouse.tech/docs/en/operations/utils/clickhouse-copier/

Hello den-crane,

It works for me.
Thank you very much!

Was this page helpful?
0 / 5 - 0 ratings