shell


git clone --depth=1 https://hub.fgit.cf/OpenTenBase/OpenTenBase.git


docker run  -itd  --name tbase --cap-add=SYS_PTRACE --privileged=true --hostname vscode --mount type=bind,source=/home/wen/OpenTenBase,target=/workspaces/OpenTenBase  runner  bash
docker exec -it -u vscode tbase bash

sudo service ssh start

ssh-keygen
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
chmod 700 ~/.ssh
chmod 644 ~/.ssh/authorized_keys

sudo chown vscode:vscode -R /workspaces/OpenTenBase


mkdir -p .build/making
mkdir .data

cd .build/making


/workspaces/OpenTenBase/configure --prefix=/home/vscode/.build --enable-user-switch --with-openssl --with-ossp-uuid --enable-alltype-distri CFLAGS="-fgnu89-inline -g -O0"

make -j64 && make install && cd contrib && make -j64 && make install 

cd ~

mkdir pgxc_ctl
# 写入下面的模板
touch pgxc_ctl/pg.conf

# ssh localhost

pgxc_ctl -c pg.conf init all

createdb -p 6011 vscode




# .bashrc 文件 此外,/home/vscode/.build/bin 需要写入到  /etc/environment

cat > /home/vscode/.bashrc <<EOF
export PATH="$PATH:/home/vscode/.build/bin"
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/home/vscode/.build/lib"
export LC_ALL=C

alias psql='psql -p 6011'
alias pstart='pgxc_ctl -c pg.conf start all'
alias pstop='pgxc_ctl -c pg.conf stop all'
alias sqps="echo 'USER         PID     PPID VSZ                  CMD' ; ps -eo user,pid,ppid,vsize,cmd | grep -E 'postgres' "

EOF

conf file (pg.conf)

pgxcInstallDir=/home/vscode/.build

pgxcOwner=vscode
pgxcUser=$pgxcOwner
defaultDatabase=postgres
tmpDir=/tmp
localTmpDir=$tmpDir

#------------------------ GTM  ---------------------
gtmName=gtm
gtmMasterServer=vscode
gtmMasterPort=6006
gtmMasterDir=/home/vscode/.data/gtm_master
gtmExtraConfig=none
gtmMasterSpecificExtraConfig=none

gtmSlave=n

#------------------------ Coordinators ---------------------
coordNames=(cn001 cn002)
coordMasterCluster=(vscode_cluster vscode_cluster)
coordPorts=(6011 6012)
poolerPorts=(6111 6112)
coordPgHbaEntries=(0.0.0.0/0)
coordMasterServers=(vscode vscode)
coordMasterDirs=(/home/vscode/.data/cn001 /home/vscode/.data/cn002)
coordMaxWALSenders=(10 10)
coordSlave=n
coordSlaveSync=n
coordArchLogDirs=(/home/vscode/.data/archlog/cn001 /home/vscode/.data/archlog/cn002)

coordExtraConfig=coordExtraConfig
cat > $coordExtraConfig <<EOF
#================================================
# Added to all the coordinator postgresql.conf
# Original: $coordExtraConfig

include_if_exists = '/home/vscode/.data/global/global_vscode.conf'

wal_level = replica
wal_keep_segments = 256
max_wal_senders = 4
archive_mode = on
archive_timeout = 1800
archive_command = 'echo 0'
log_truncate_on_rotation = on
log_filename = 'postgresql-%M.log'
log_rotation_age = 4h
log_rotation_size = 100MB
hot_standby = on
wal_sender_timeout = 30min
wal_receiver_timeout = 30min
shared_buffers = 16384MB
max_pool_size = 2000
log_statement = 'ddl'
log_destination = 'csvlog'
logging_collector = on
log_directory = 'pg_log'
listen_addresses = '*'
max_connections = 2000

EOF

coordSpecificExtraConfig=(none none)
coordExtraPgHba=coordExtraPgHba
cat > $coordExtraPgHba <<EOF

local   all             all                                     trust
host    all             all             0.0.0.0/0               trust
host    replication     all             0.0.0.0/0               trust
host    all             all             ::1/128                 trust
host    replication     all             ::1/128                 trust

EOF

coordSpecificExtraPgHba=(none none)
coordAdditionalSlaves=n
cad1_Sync=n

#------------------------ Datanodes ---------------------
primaryDatanode=dn001
datanodeNames=(dn001 dn002 dn003)
datanodePorts=(6021 6022 6023)
datanodePoolerPorts=(6121 6122 6123)
datanodeMasterCluster=(vscode_cluster vscode_cluster vscode_cluster)
datanodePgHbaEntries=(0.0.0.0/0)
datanodeMasterServers=(vscode vscode vscode)
datanodeMasterDirs=(/home/vscode/.data/dn001 /home/vscode/.data/dn002 /home/vscode/.data/dn003)
datanodeMaxWALSenders=(10 10 10)
datanodeArchLogDirs=(/home/vscode/.data/archlog/dn001 /home/vscode/.data/archlog/dn002 /home/vscode/.data/archlog/dn003)

datanodeSlave=n

datanodeExtraConfig=datanodeExtraConfig
cat > $datanodeExtraConfig <<EOF
#================================================
# Added to all the coordinator postgresql.conf
# Original: $datanodeExtraConfig

include_if_exists = '/home/vscode/.data/global/global_vscode.conf'
listen_addresses = '*'
wal_level = replica
wal_keep_segments = 256
max_wal_senders = 4
archive_mode = on
archive_timeout = 1800
archive_command = 'echo 0'
log_directory = 'pg_log'
logging_collector = on
log_truncate_on_rotation = on
log_filename = 'postgresql-%M.log'
log_rotation_age = 4h
log_rotation_size = 100MB
hot_standby = on
wal_sender_timeout = 30min
wal_receiver_timeout = 30min
shared_buffers = 16384MB
max_connections = 4000
max_pool_size = 4000
log_statement = 'ddl'
log_destination = 'csvlog'
wal_buffers = 1GB

EOF

datanodeSpecificExtraConfig=(none none)
datanodeExtraPgHba=datanodeExtraPgHba
cat > $datanodeExtraPgHba <<EOF

local   all             all                                     trust
host    all             all             0.0.0.0/0               trust
host    replication     all             0.0.0.0/0               trust
host    all             all             ::1/128                 trust
host    replication     all             ::1/128                 trust


EOF

datanodeSpecificExtraPgHba=(none none)
datanodeAdditionalSlaves=n
walArchive=n

demo sql


select '
drop table if exists t0;
drop table if exists t0_2357_hash;                drop table if exists t1_2357_hash;                  drop table if exists t2_2357_hash;
drop table if exists t0_2357_mod;                 drop table if exists t1_2357_mod;                   drop table if exists t2_2357_mod;
drop table if exists t0_2357_repl;                drop table if exists t1_2357_repl;                  drop table if exists t2_2357_repl;
drop table if exists t0_2357_round;               drop table if exists t1_2357_round;                 drop table if exists t2_2357_round;
drop table if exists t0_2357_random;              drop table if exists t1_2357_random;                drop table if exists t2_2357_random;
' droptable \gset

select '
create table t0(a int, b int, c char(10), d timestamp);
insert into t0 values
(1,  1,  ''1'',  ''2021-12-29 20:10:01''),(2,  2,  ''2'',  ''2022-12-29 20:10:01''),(3,  3,  ''3'',  ''2023-12-29 20:10:01''),(4,  4,  ''4'',  ''2024-12-29 20:10:01''),
(5,  5,  ''5'',  ''2025-12-29 20:10:01''),(6,  6,  ''6'',  ''2026-12-29 20:10:01''),(7,  7,  ''7'',  ''2027-12-29 20:10:01''),(8,  8,  ''8'',  ''2028-12-29 20:10:01''),
(9,  9,  ''9'',  ''2029-12-29 20:10:01''),(10, 10, ''10'', ''2010-12-29 20:10:01''),(11, 11, ''11'', ''2011-12-29 20:10:01''),(12, 12, ''12'', ''2012-12-29 20:10:01''),
(13, 13, ''13'', ''2013-12-29 20:10:01''),(14, 14, ''14'', ''2014-12-29 20:10:01''),(15, 15, ''15'', ''2015-12-29 20:10:01''),(16, 16, ''16'', ''2016-12-29 20:10:01''),
(17, 17, ''17'', ''2017-12-29 20:10:01''),(18, 18, ''18'', ''2018-12-29 20:10:01''),(19, 19, ''19'', ''2019-12-29 20:10:01''),(20, 20, ''20'', ''2020-12-29 20:10:01'');

create table t0_2357_hash   (a int, b int, c char(10), d timestamp) DISTRIBUTE by hash (a);
create table t0_2357_mod    (a int, b int, c char(10), d timestamp) DISTRIBUTE by modulo(a);
create table t0_2357_repl   (a int, b int, c char(10), d timestamp) DISTRIBUTE by REPLICATION;
create table t0_2357_round  (a int, b int, c char(10), d timestamp) DISTRIBUTE by roundrobin;
create table t0_2357_random (a int, b int, c char(10), d timestamp) DISTRIBUTED RANDOMLY;

create table t1_2357_hash   (a int, b int, c char(10), d timestamp) DISTRIBUTE by hash (a);
create table t1_2357_mod    (a int, b int, c char(10), d timestamp) DISTRIBUTE by modulo(a);
create table t1_2357_repl   (a int, b int, c char(10), d timestamp) DISTRIBUTE by REPLICATION;
create table t1_2357_round  (a int, b int, c char(10), d timestamp) DISTRIBUTE by roundrobin;
create table t1_2357_random (a int, b int, c char(10), d timestamp) DISTRIBUTED RANDOMLY;

create table t2_2357_hash   (a int, b int, c char(10), d timestamp) DISTRIBUTE by hash (a);
create table t2_2357_mod    (a int, b int, c char(10), d timestamp) DISTRIBUTE by modulo(a);
create table t2_2357_repl   (a int, b int, c char(10), d timestamp) DISTRIBUTE by REPLICATION;
create table t2_2357_round  (a int, b int, c char(10), d timestamp) DISTRIBUTE by roundrobin;
create table t2_2357_random (a int, b int, c char(10), d timestamp) DISTRIBUTED RANDOMLY;

insert into t0_2357_hash select * from t0;
insert into t0_2357_mod select * from t0;
insert into t0_2357_repl select * from t0;
insert into t0_2357_round select * from t0;
insert into t0_2357_random select * from t0;
insert into t1_2357_hash select * from t0;
insert into t1_2357_mod select * from t0;
insert into t1_2357_repl select * from t0;
insert into t1_2357_round select * from t0;
insert into t1_2357_random select * from t0;
insert into t2_2357_hash select * from t0;
insert into t2_2357_mod select * from t0;
insert into t2_2357_repl select * from t0;
insert into t2_2357_round select * from t0;
insert into t2_2357_random select * from t0;


vacuum analyze t0_2357_hash;                vacuum analyze t1_2357_hash;                vacuum analyze t2_2357_hash;
vacuum analyze t0_2357_mod;                 vacuum analyze t1_2357_mod;                 vacuum analyze t2_2357_mod;
vacuum analyze t0_2357_repl;                vacuum analyze t1_2357_repl;                vacuum analyze t2_2357_repl;
vacuum analyze t0_2357_round;               vacuum analyze t1_2357_round;               vacuum analyze t2_2357_round;
vacuum analyze t0_2357_random;              vacuum analyze t1_2357_random;              vacuum analyze t2_2357_random;

' createtable \gset