Truncate table on cluster in Clickhouse - truncate

I am using Clickhouse version 20.1.5 and set up a cluster with a number of Clickhouse replicas. I also set insert_quorum = 2.
When I do truncate table [table_name] on cluster [cluster_name], it completes normally. But when I execute this query SELECT COUNT(*) FROM table_name, I got this error
Code: 289. DB::Exception: Received from localhost:9000. DB::Exception: Received from 10.33.179.126:9000. DB::Exception: Replica doesn't have part all_56_56_0 which was successfully written to quorum of other replicas. Send query to another replica or disable 'select_sequential_consistency' setting..
Do you know what is the reason and how can I resolve it?
Thanks.

Related

TimescaleDB multinode cluster & replication factor

I have been working on timescaleDB multi-node concept, In my case I have an access node, and four data node. When I created the distributed hyper table I have set replication factor to four.
adding data node
SELECT add_data_node('dn1', host => '192.168.5.119', port => 5432, password => 'pass');
CREATE USER MAPPING FOR bennison SERVER dn1 OPTIONS (user 'pass', password 'pass');
For example, first data node name is dn1, and the second data node name is dn3, third, and fourth one is d3, d4.
SELECT create_distributed_hypertable('sensor_data', 'time', 'sensor_id', replication_factor => 4);
As I have set the replication factor to four, all data node chunk data will be stored in other data nodes. In my all data node I have installed the timescaledb-tune also.
After the all configuration, I just run the insert query it works fine.
INSERT INTO sensor_data VALUES ('2020-12-09',1,32.2,0.45);
If I down the data node 2 or three, I can run the read-only query (select query) on the access node that get the response back.
select * from sensor_data;
Here the thing is, If I down the data node one (dn1), I could not run the any query especially read only query. Here the error looks like
test=# select * from sensor_data ;
ERROR: [dn1]: FATAL: terminating connection due to administrator command
SSL connection has been closed unexpectedly
test=#
I want to know about, Why this error happens when the first data node is down, why this error is not happening other data node is down.
Is this possible run the query successfully, while the either one of the data node is in down. If not what will be the solution for this. If not any other way to implement the cluster in timescaleDB?

Synchronous Postgres Replication to Clickhouse

I have a problem replicating postgres to clickhouse. I can easily create materialized postgresql engine and it works fine. But we need to have synchronous commits work so that any write to our main postgres db should wait for the same writes to be written to clickhouse before the transaction is completed.
I tried adding the following setting to postgresql config. But this prevents clickhouse from replicating.
synchronous_commit: "on"
synchronous_standby_names: "'*'"

PostgreSQL replication slot - how to see standby nodes

I am using PostgreSQL 11.2. I have replication slots setup. I am able to commit to a table and see it on the standby. I have few more standbys. How can I see from the master what other standbys I have?
By selecting from pg_stat_replication. client_addr will be the IP address of a standby.
You can use the following query and check for client_addr, client_port, and client_hostname.
SELECT * FROM pg_stat_replication;

Re-add lost Clickhouse replica in Zookeeper cluster

We previously had three Clickhouse nodes perfectly synced within Zookeeper until one of them was lost.
The Clickhouse node was rebuilt exactly as it was before (with Ansible) and the same create table command was run which resulted in the following error.
Command:
CREATE TABLE ontime_replica ( ... )
ENGINE = ReplicatedMergeTree('/clickhouse/tables/{shard}/ontime_replica', '{replica}', FlightDate, (Year, FlightDate), 8192)
The error is:
Received exception from server:
Code: 253. DB::Exception: Received from localhost:9000, 127.0.0.1. DB::Exception: Replica /clickhouse/tables/01/ontime_replica/replicas/clickhouse1 already exists..
We're currently using Zookeeper version 3.4.10 and I would like to know if there's a way to remove the existing replica within Zookeeper, or simple let Zookeeper know that this is the new version of the existing replica.
Thank you in advance!
My approach to the solution was incorrect. Originally, I thought I needed to remove the replica within Zookeeper. Instead, the following commands within the Clickhouse server solve this problem.
Copy the SQL file from another, working node. The file is in /var/lib/clickhouse/metadata/default
chown clickhouse:clickhouse <database>.sql
chmod 0640 <database>.sql
sudo -u clickhouse touch /var/lib/clickhouse/flags/force_restore_data
service clickhouse-server start

postgres slony-i master node tables can't be written after running for few days

I set up slony to replicate 3 tables from one opensuse pc (master node) to another opensuse pc (slave node). It works well at first. After running for few days, it suddenly come out the error message of -
ERROR: Slony-I: Table euprofiles is replicated and cannot be modified on a subscriber node - role=0
euprofiles is one of the tables being replicated by slony.
I know that this message may occur if you are trying to write to the table of slave node. But here I am writing to master node only.
Does anyone see similar problem?
Never had this happen. Are you certain you're connecting to the db you think you're connecting to? Slony may be a bit difficult to setup and such, but it doesn't just randomly decide a master is now a slave.
If you psql into the two databasesand do \d euprofiles on each what do they say? The source table should have something like this at the end:
Triggers:
_slony_www_logtrigger_228 AFTER INSERT OR DELETE OR UPDATE ON users FOR EACH ROW EXECUTE PROCEDURE _slony_www.logtrigger('_slony_www', '228', 'kvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv')
and the destination table should have something like this:
Triggers:
_slony_www_denyaccess_228 BEFORE INSERT OR DELETE OR UPDATE ON users FOR EACH ROW EXECUTE PROCEDURE _slony_www.denyaccess('_slony_www')
If they both look like this last trigger there's some problem. But I'm betting you're just connecting to the wrong server. Let's hope it's that simple.