|
29 | 29 |
|
30 | 30 | foreachmy$node (@shards)
|
31 | 31 | {
|
32 |
| -$node->safe_psql('postgres',"CREATE EXTENSION postgres_fdw"); |
33 |
| -$node->safe_psql('postgres',"CREATE TABLE accounts(id integer primary key, amount integer)"); |
34 |
| -$node->safe_psql('postgres',"CREATE TABLE accounts_local() inherits(accounts)"); |
35 |
| -$node->safe_psql('postgres',"CREATE TABLE global_transactions(tx_time timestamp)"); |
36 |
| -$node->safe_psql('postgres',"CREATE TABLE local_transactions(tx_time timestamp)"); |
| 32 | +$node->safe_psql('postgres',qq[ |
| 33 | +CREATE EXTENSION postgres_fdw; |
| 34 | +CREATE TABLE accounts(id integer primary key, amount integer); |
| 35 | +CREATE TABLE accounts_local() inherits(accounts); |
| 36 | +CREATE TABLE global_transactions(tx_time timestamp); |
| 37 | +CREATE TABLE local_transactions(tx_time timestamp); |
| 38 | +]); |
37 | 39 |
|
38 | 40 | foreachmy$neighbor (@shards)
|
39 | 41 | {
|
|
42 | 44 | my$port =$neighbor->port;
|
43 | 45 | my$host =$neighbor->host;
|
44 | 46 |
|
45 |
| -$node->safe_psql('postgres',"CREATE SERVER shard_$port FOREIGN DATA WRAPPER postgres_fdw options(dbname 'postgres', host '$host', port '$port')"); |
46 |
| -$node->safe_psql('postgres',"CREATE FOREIGN TABLE accounts_fdw_$port() inherits (accounts) server shard_$port options(table_name 'accounts_local')"); |
47 |
| -$node->safe_psql('postgres',"CREATE USER MAPPING for stas SERVER shard_$port options (user 'stas')"); |
| 47 | +$node->safe_psql('postgres',qq[ |
| 48 | +CREATE SERVER shard_$port FOREIGN DATA WRAPPER postgres_fdw |
| 49 | +options(dbname 'postgres', host '$host', port '$port'); |
| 50 | +CREATE FOREIGN TABLE accounts_fdw_$port() inherits (accounts) |
| 51 | +server shard_$port options(table_name 'accounts_local'); |
| 52 | +CREATE USER MAPPING for stas SERVER shard_$port |
| 53 | +options (user 'stas'); |
| 54 | +]); |
48 | 55 | }
|
49 |
| - |
50 | 56 | }
|
51 | 57 |
|
52 | 58 | $shard1->psql('postgres',"insert into accounts_local select 2*id-1, 0 from generate_series(1, 10010) as id;");
|
|
73 | 79 | subcount_and_delete_rows
|
74 | 80 | {
|
75 | 81 | my ($node,$table) =@_;
|
76 |
| -my ($rc,$count,$err); |
77 |
| - |
78 |
| -($rc,$count,$err) =$node->psql('postgres',"select count(*) from$table", |
79 |
| -on_error_die=> 1); |
80 |
| - |
81 |
| -die"count_rows:$err"if ($errne''); |
82 |
| - |
83 |
| -$node->psql('postgres',"delete from$table",on_error_die=> 1); |
| 82 | +my$count; |
84 | 83 |
|
| 84 | +$count =$node->safe_psql('postgres',"select count(*) from$table"); |
| 85 | +$node->safe_psql('postgres',"delete from$table"); |
85 | 86 | diag($node->name,": completed$count transactions");
|
86 |
| - |
87 | 87 | return$count;
|
88 | 88 | }
|
89 | 89 |
|
|