0

I am using postgres-xl in ubuntu. I have a table with 9 row. I want to divide that table into 3 parts. Any idea how i do this?

postgres=# SELECT * FROM cities;
 name | location 
------+----------
 a    |        1
 a    |        2
 a    |        4
 a    |        3
 a    |        4
 a    |        5
 a    |        6
 a    |       11
 a    |       14
(9 rows)
Muhammad Raza
  • 847
  • 1
  • 8
  • 22

2 Answers2

2

Not sure how to do it with Postgres-XL, but with the pg_shard extension you could hash-partition the table into 3 (or more) pieces:

CREATE TABLE cities (name text, location int);
SELECT master_create_distributed_table('cities', 'location');
SELECT master_create_worker_shards('cities', 3, 2);

To get started with pg_shard you can find documentation at: https://github.com/citusdata/pg_shard

Marco Slot
  • 401
  • 3
  • 5
1

You would need to specify your distribution strategy upon table creation:

CREATE TABLE cities (
    name VARCHAR,
    location VARCHAR,
    PRIMARY KEY (location)
)
DISTRIBUTE BY HASH(location);

Note that there are several pitfalls with respect to constraints, see also PostgresXL CREATE TABLE documentation.

mdh
  • 5,355
  • 5
  • 26
  • 33