This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- Create ReplicatedMergeTree table | |
| CREATE TABLE mydb.my_test_data ON CLUSTER '{cluster}' | |
| ( | |
| event_id UUID, | |
| user_id UInt32, | |
| event_time DateTime, | |
| event_type Enum('click' = 1, 'view' = 2, 'purchase' = 3), | |
| amount Decimal(18, 2) | |
| ) | |
| ENGINE = ReplicatedMergeTree('/clickhouse/tables/{uuid}/{shard}', '{replica}') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # vim: set sw=4 sts=4 et tw=80 : | |
| _docker_list() { | |
| echo "List of container:" | |
| docker ps -a | |
| echo "List of images:" | |
| docker images ls | |
| echo "List of volumes:" | |
| docker volume ls |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Create test table | |
| CREATE TABLE mytable ( | |
| id bigint not null generated by default as identity primary key, | |
| value1 varchar, | |
| value2 varchar | |
| ); | |
| # Add data (bad!) | |
| INSERT INTO mytable(id, value1, value2) VALUES | |
| (1,'Daniele','Teti'), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CREATE EXTENSION IF NOT EXISTS postgres_fdw; | |
| CREATE SERVER IF NOT EXISTS my_server FOREIGN DATA WRAPPER postgres_fdw OPTIONS (host '1.2.3.4', dbname 'my_db', port '5432', sslmode 'disable', connect_timeout '10', application_name 'fdw'); | |
| CREATE USER MAPPING IF NOT EXISTS FOR my_user SERVER my_server OPTIONS (user 'my_user', password 'BigPa$$w0rd!'); | |
| IMPORT FOREIGN SCHEMA public LIMIT TO (table1,table2) FROM SERVER my_server INTO public; | |
| SELECT * FROM table1 LIMIT 10; | |
| SELECT * FROM table2 LIMIT 10; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CREATE TABLE test ( | |
| id BIGINT GENERATED ALWAYS AS IDENTITY NOT NULL PRIMARY KEY, | |
| data_field VARCHAR(255) NOT NULL | |
| ); | |
| INSERT INTO test(data_field) SELECT(i::text) FROM generate_series(1,10000) as t(i); | |
| -- repeat several times | |
| WITH candidate_rows AS ( | |
| SELECT id |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Prepare test data (table size: 1M rows, ~87MB) | |
| psql -t -X postgres://user:[email protected]:5432/dbname -c " | |
| CREATE TABLE customers ( | |
| id BIGINT GENERATED ALWAYS AS IDENTITY NOT NULL PRIMARY KEY, | |
| first_name VARCHAR(255) NOT NULL, | |
| last_name VARCHAR(255) NOT NULL, | |
| age INTEGER NOT NULL | |
| ); | |
| INSERT INTO customers(first_name,last_name,age) VALUES(CONCAT('FirstName',generate_series(1, 1000000)), CONCAT('LastName',round((random()*100)::integer,0)), round((random()*100)::integer,0)); | |
| " |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| WITH rel_set AS ( | |
| SELECT | |
| oid | |
| , CASE split_part( | |
| split_part(array_to_string(reloptions, ','), 'autovacuum_vacuum_threshold=', 2) | |
| , ',' | |
| , 1 | |
| ) | |
| WHEN '' THEN NULL | |
| ELSE |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| LANG=en_US.UTF-8 snap list --all | awk '/disabled/{print $1, $3}' | | |
| while read pkg revision; do | |
| sudo snap remove "$pkg" --revision="$revision" | |
| done | |
| journalctl --vacuum-size=100M |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT DISTINCT | |
| CASE | |
| WHEN b.sender=0 AND c.receiver=0 THEN | |
| 'standalone' | |
| WHEN b.sender>0 AND c.receiver=0 THEN | |
| 'primary' | |
| WHEN b.sender=0 AND c.receiver>0 THEN | |
| 'replica' | |
| WHEN b.sender>0 AND c.receiver>0 THEN | |
| 'primary+replica' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| wget -qO - $(OS=$(uname -s | tr '[:upper:]' '[:lower:]'); ARCH=$(uname -p | sed 's/x86_64/amd64/g'); wget https://api.github.com/repos/CHERTS/pgscv/releases/latest -qO - | grep -wo "https.*${OS}_${ARCH}.tar.g | |
| z") | tar xzf - -C /tmp && \ | |
| mv /tmp/pgscv.yaml /etc 2>/dev/null && \ | |
| mv /tmp/pgscv.service /etc/systemd/system 2>/dev/null && \ | |
| mv /tmp/pgscv.default /etc/default/pgscv 2>/dev/null && \ | |
| mv /tmp/pgscv /usr/sbin 2>/dev/null && \ | |
| chown postgres:postgres /etc/pgscv.yaml 2>/dev/null && \ | |
| systemctl daemon-reload && \ | |
| systemctl enable pgscv --now |
NewerOlder