Citus Tips for Postgres: How to alter distribution key, shard count, & more

Published May 03 2021 09:26 AM 3,558 Views
Microsoft

Citus is an extension to Postgres that lets you distribute your application’s workload across multiple nodes. Whether you are using Citus open source or using Citus as part of a managed Postgres service in the cloud, one of the first things you do when you start using Citus is to distribute your tables. While distributing your Postgres tables you need to decide on some properties such as distribution column, shard count, colocation. And even before you decide on your distribution column (sometimes called a distribution key, or a sharding key), when you create a Postgres table, your table is created with an access method.

 

Previously you had to decide on these table properties up front, and then you went with your decision. Or if you really wanted to change your decision, you needed to start over. The good news is that in Citus 10, we introduced 2 new user-defined functions (UDFs) to make it easier for you to make changes to your distributed Postgres tables.

 

Before Citus 9.5, if you wanted to change any of the properties of the distributed table, you would have to create a new table with the desired properties and move everything to this new table. But in Citus 9.5 we introduced a new function, undistribute_table. With the undistribute_table function you can convert your distributed Citus tables back to local Postgres tables and then distribute them again with the properties you wish. But undistributing and then distributing again is … 2 steps. In addition to the inconvenience of having to write 2 commands, undistributing and then distributing again has some more problems:

 

  1. Moving the data of a big table can take a long time, undistribution and distribution both require to move all the data of the table. So, you must move the data twice, which is much longer.
  2. Undistributing moves all the data of a table to the Citus coordinator node. If your coordinator node isn't big enough, and coordinator nodes typically don't have to be, you might not be able to fit the table into your coordinator node.


So, in Citus 10, we introduced 2 new functions to reduce the steps you need to make changes to your tables:

 

  • alter_distributed_table
  • alter_table_set_access_method

 

In this post you’ll find some tips about how to use the alter_distributed_table function to change the shard count, distribution column, and the colocation of a distributed Citus table. And we'll show how to use the alter_table_set_access_method function to change, well, the access method. An important note: you may not ever need to change your Citus table properties. We just want you to know, if you ever do, you have the flexibility. And with these Citus tips, you will know how to make the changes.

 

Dj-turntables-purple-and-pink-for-Citus-tips-blog-1920x1080.jpg

 

Altering the properties of distributed Postgres tables in Citus

 

When you distribute a Postgres table with the create_distributed_table function, you must pick a distribution column and set the distribution_column parameter. During the distribution, Citus uses a configuration variable called shard_count for deciding the shard count of the table. You can also provide colocate_with parameter to pick a table to colocate with (or colocation will be done automatically, if possible).

 

However, after the distribution if you decide you need to have a different configuration, starting from Citus 10, you can use the alter_distributed_table function.

 

alter_distributed_table has three parameters you can change:

  • distribution column
  • shard count
  • colocation properties

 

How to change the distribution column (aka the sharding key)

 

Citus divides your table into shards based on the distribution column you select while distributing. Picking the right distribution column is crucial for having a good distributed database experience. A good distribution column will help you parallelize your data and workload better by dividing your data evenly and keeping related data points close to each other. However, choosing the distribution column might be a bit tricky when you’re first getting started. Or perhaps later as you make changes in your application, you might need to pick another distribution column.

 

With the distribution_column parameter of the new alter_distributed_table function, Citus 10 gives you an easy way to change the distribution column.

 

Let’s say you have customers and orders that your customers make. You will create some Postgres tables like these:

 

CREATE TABLE customers (customer_id BIGINT, name TEXT, address TEXT);
CREATE TABLE orders (order_id BIGINT, customer_id BIGINT, products BIGINT[]);

 

When first distributing your Postgres tables with Citus, let’s say that you decided to distribute the customers table on customer_id and the orders table on order_id.

 

SELECT create_distributed_table ('customers', 'customer_id');
SELECT create_distributed_table ('orders', 'order_id');

 

Later you might realize distributing the orders table by the order_id column might not be the best idea. Even though order_id could be a good column to evenly distribute your data, it is not a good choice if you frequently need to join the orderstable with the customers table on the customer_id. When both tables are distributed by customer_id you can use colocated joins, which are very efficient compared to joins on other columns.

 

So, if you decide to change the distribution column of orders table into customer_id here is how you do it:

 

SELECT alter_distributed_table ('orders', distribution_column := 'customer_id');

 

Now the orders table is distributed by customer_id. So, the customers and the orders of the customers are in the same node and close to each other, and you can have fast joins and foreign keys that include the customer_id.

 

You can see the new distribution column on the citus_tables view:

 

SELECT distribution_column FROM citus_tables WHERE table_name::text = 'orders';

 

How to increase (or decrease) the shard count in Citus

 

Shard count of a distributed Citus table is the number of pieces the distributed table is divided into. Choosing the shard count is a balance between the flexibility of having more shards, and the overhead for query planning and execution across the shards. Like distribution column, the shard count is also set while distributing the table. If you want to pick a different shard count than the default for a table, during the distribution process you can use the citus.shard_count configuration variable, like this:

 

CREATE TABLE products (id BIGINT, name TEXT);
SET citus.shard_count TO 20;
SELECT create_distributed_table ('products', 'id');

 

After distributing your table, you might decide the shard count you set was not the best option. Or your first decision on the shard count might be good for a while but your application might grow in time, you might add new nodes to your Citus cluster, and you might need more shards. The alter_distributed_table function has you covered in the cases that you want to change the shard count too.

 

To change the shard count you just use the shard_count parameter:

 

SELECT alter_distributed_table ('products', shard_count := 30);

 

After the query above, your table will have 30 shards. You can see your table’s shard count on the citus_tables view:

 

SELECT shard_count FROM citus_tables WHERE table_name::text = 'products';

 

How to colocate with a different Citus distributed table

 

When two Postgres tables are colocated in Citus, the rows of the tables that have the same value in the distribution column will be on the same Citus node. Colocating the right tables will help you with better relational operations. Like the shard count and the distribution column, the colocation is also set while distributing your tables. You can use the colocate_with parameter to change the colocation.

 

SELECT alter_distributed_table ('products', colocate_with := 'customers');

 

Again, like the distribution column and shard count, you can find information about your tables’ colocation groups on the citus_tables view:

 

SELECT colocation_id FROM citus_tables WHERE table_name IN ('products', 'customers');

 

You can also use default and none keywords with colocate_with parameter to change the colocation group of the table to default, or to break any colocation your table has.

 

To colocate distributed Citus tables, the distributed tables need to have the same shard counts. But if the tables you want to colocate don’t have the same shard count, worry not, because alter_distributed_table will automatically understand this. Then your table’s shard count will also be updated to match the new colocation group’s shard count.

 

How to change more than one Citus table property at a time

 

Here is a tip! If you want to change multiple properties of your distributed Citus tables at the same time, you can simply use multiple parameters of the alter_distributed_table function.

 

For example, if you want to change both the shard count and the distribution column of a table here's how you do it:

 

SELECT alter_distributed_table ('products', distribution_column := 'name', shard_count := 35);

 

How to alter the Citus colocation group

 

If your table is colocated with some other tables and you want to change the shard count of all of the tables to keep the colocation, you might be wondering if you have to alter them one by one... which is multiple steps.

 

Yes (you can see a pattern here) the Citus tip is that you can use the alter_distributed_table function to change the properties of all of the colocation group.

 

If you decide the change you make with the alter_distributed_table function needs to be done to all the tables that are colocated with the table you are changing, you can use the cascade_to_colocated parameter:

 

SET citus.shard_count TO 10;
SELECT create_distributed_table ('customers', 'customer_id');
SELECT create_distributed_table ('orders', 'customer_id', colocate_with := 'customers');
-- when you decide to change the shard count 
-- of all of the colocation group
SELECT alter_distributed_table ('customers', shard_count := 20, cascade_to_colocated := true);

 

You can see the updated shard count of both tables on the citus_tables view:

 

SELECT shard_count FROM citus_tables WHERE table_name IN ('customers', 'orders');

 

How to change your Postgres table’s access method in Citus

 

Another amazing feature introduced in Citus 10 is columnar storage. This Citus 10 columnar blog post walks you through how it works and how to use columnar tables (or partitions) with Citus—complete with a Quickstart. Oh, and Jeff made a short video demo about the new Citus 10 columnar functionality too—it’s worth the 13 minutes to watch IMHO.

 

With Citus columnar, you can optionally choose to store your tables grouped by columns—which gives you the benefits of compression, too. Of course, you don’t have to use the new columnar access method—the default access method is “heap” and if you don’t specify an access method, then your tables will be row-based tables (with the heap access method.)


It would not be fair to introduce this cool new Citus columnar access method without also giving you a way to convert your tables to columnar. So Citus 10 also introduced a way to change the access method of tables.

 

SELECT alter_table_set_access_method('orders', 'columnar');

 

You can use alter_table_set_access_method to convert your table to any other access method too, such as heap, Postgres’s default access method. Also, your table doesn’t even need to be a distributed Citus table. You can also use alter_table_set_access_method with Citus reference tables as well as regular Postgres tables. You can even change the access method of a Postgres partition with alter_table_set_access_method.

 

Under the hood: How do these new Citus functions work?

 

If you’ve read the blog post about undistribute_table, the function Citus 9.5 introduced for turning distributed Citus tables back to local Postgres tables, you mostly know how the alter_distributed_table and alter_table_set_access_method functions work. Because we use the same underlying methodology as the undistribute_table function. Well, we improved upon it.

 

The alter_distributed_table and alter_table_set_access_method functions:

 

  1. Create a new table in the way you want (with the new shard count or access method etc.)
  2. Move everything from your old table to the new table
  3. Drop the old table and rename the new one

 

Dropping a table for the purpose of re-creating the same table with different properties is not a simple task. Dropping the table will also drop many things that depend on the table.

 

Just like the undistribute_table function, the alter_distributed_table and alter_table_set_access_method functions do a lot to preserve the properties of the table you didn’t want to change. The functions will handle indexes, sequences, views, constraints, table owner, partitions and more—just like undistribute_table.

 

alter_distributed_table and alter_table_set_access_method will also recreate the foreign keys on your tables whenever possible. For example, if you change the shard count of a table with the alter_distributed_table function and use cascade_to_colocated := true to change the shard count of all the colocated tables, then foreign keys within the colocation group and foreign keys from the distributed tables of the colocation group to Citus reference tables will be recreated.

 

Making it easier to experiment with Citus—and to adapt as your needs change

 

If you want to learn more about our previous work which we build on for alter_distributed_table and alter_table_set_access_method functions go check out our blog post on undistribute_table.

 

In Citus 10 we worked to give you more tools and more capabilities for making changes to your distributed database. When you’re just starting to use Citus, the new alter_distributed_table and alter_table_set_access_method functions—along with the undistribute_table function—are all here to help you experiment and find the database configuration that works the best for your application. And in the future, if and when your application evolves, these three Citus functions will be ready to help you evolve your Citus database, too.

%3CLINGO-SUB%20id%3D%22lingo-sub-2311470%22%20slang%3D%22en-US%22%3ECitus%20Tips%20for%20Postgres%3A%20How%20to%20alter%20distribution%20key%2C%20shard%20count%2C%20%26amp%3B%20more%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2311470%22%20slang%3D%22en-US%22%3E%3CP%3ECitus%20is%20an%20extension%20to%20Postgres%20that%20lets%20you%20distribute%20your%20application%E2%80%99s%20workload%20across%20multiple%20nodes.%20Whether%20you%20are%20using%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fcitusdata%2Fcitus%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3ECitus%20open%20source%3C%2FA%3E%20or%20using%20Citus%20as%20part%20of%20a%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Fpostgresql%2Fhyperscale%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Emanaged%20Postgres%20service%3C%2FA%3E%20in%20the%20cloud%2C%20one%20of%20the%20first%20things%20you%20do%20when%20you%20start%20using%20Citus%20is%20to%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Fpostgresql%2Fhowto-hyperscale-modify-distributed-tables%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Edistribute%20your%20tables%3C%2FA%3E.%20While%20distributing%20your%20Postgres%20tables%20you%20need%20to%20decide%20on%20some%20properties%20such%20as%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Fpostgresql%2Fconcepts-hyperscale-choose-distribution-column%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Edistribution%20column%3C%2FA%3E%2C%20%3CA%20href%3D%22https%3A%2F%2Fdocs.citusdata.com%2Fen%2Fstable%2Fadmin_guide%2Fcluster_management.html%23shard-count%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Eshard%20count%3C%2FA%3E%2C%20%3CA%20href%3D%22https%3A%2F%2Fdocs.citusdata.com%2Fen%2Fstable%2Fsharding%2Fdata_modeling.html%23table-co-location%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Ecolocation%3C%2FA%3E.%20And%20even%20before%20you%20decide%20on%20your%20distribution%20column%20(sometimes%20called%20a%20distribution%20key%2C%20or%20a%20sharding%20key)%2C%20when%20you%20create%20a%20Postgres%20table%2C%20your%20table%20is%20created%20with%20an%20%3CA%20href%3D%22https%3A%2F%2Fwww.postgresql.org%2Fdocs%2Fcurrent%2Ftableam.html%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Eaccess%20method%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EPreviously%20you%20had%20to%20decide%20on%20these%20table%20properties%20up%20front%2C%20and%20then%20you%20went%20with%20your%20decision.%20Or%20if%20you%20really%20wanted%20to%20change%20your%20decision%2C%20you%20needed%20to%20start%20over.%20The%20good%20news%20is%20that%20%3CA%20href%3D%22https%3A%2F%2Fwww.citusdata.com%2Fblog%2F2021%2F03%2F05%2Fcitus-10-release-open-source-rebalancer-and-columnar-for-postgres%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Ein%20Citus%2010%3C%2FA%3E%2C%20we%20introduced%202%20new%20user-defined%20functions%20(UDFs)%20to%20make%20it%20easier%20for%20you%20to%20make%20changes%20to%20your%20distributed%20Postgres%20tables.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fwww.citusdata.com%2Fblog%2F2020%2F11%2F14%2Fcitus-9-5-whats-new%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3EBefore%20Citus%209.5%3C%2FA%3E%2C%20if%20you%20wanted%20to%20change%20any%20of%20the%20properties%20of%20the%20distributed%20table%2C%20you%20would%20have%20to%20create%20a%20new%20table%20with%20the%20desired%20properties%20and%20move%20everything%20to%20this%20new%20table.%20But%20in%20Citus%209.5%20we%20introduced%20a%20new%20function%2C%20%3CA%20href%3D%22https%3A%2F%2Fwww.citusdata.com%2Fblog%2F2021%2F02%2F06%2Fcitus-tips-how-to-undistribute-a-distributed-postgres-table%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Eundistribute_table%3C%2FA%3E.%20With%20the%3CCODE%20style%3D%22color%3A%20black%3B%22%3Eundistribute_table%3C%2FCODE%3Efunction%20you%20can%20convert%20your%20distributed%20Citus%20tables%20back%20to%20local%20Postgres%20tables%20and%20then%20distribute%20them%20again%20with%20the%20properties%20you%20wish.%20But%20undistributing%20and%20then%20distributing%20again%20is%20%E2%80%A6%202%20steps.%20In%20addition%20to%20the%20inconvenience%20of%20having%20to%20write%202%20commands%2C%20undistributing%20and%20then%20distributing%20again%20has%20some%20more%20problems%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3COL%3E%0A%3CLI%20data-leveltext%3D%22%251.%22%20data-listid%3D%225%22%20aria-setsize%3D%22-1%22%20data-aria-posinset%3D%221%22%20data-aria-level%3D%221%22%3EMoving%20the%20data%20of%20a%20big%20table%20can%20take%20a%20long%20time%2C%20undistribution%20and%20distribution%20both%20require%20to%20move%20all%20the%20data%20of%20the%20table.%20So%2C%20you%20must%20move%20the%20data%20twice%2C%20which%20is%20much%20longer.%3C%2FLI%3E%0A%3CLI%20data-leveltext%3D%22%251.%22%20data-listid%3D%225%22%20aria-setsize%3D%22-1%22%20data-aria-posinset%3D%221%22%20data-aria-level%3D%221%22%3EUndistributing%20moves%20all%20the%20data%20of%20a%20table%20to%20the%20Citus%20coordinator%20node.%20If%20your%20coordinator%20node%20isn't%20big%20enough%2C%20and%20coordinator%20nodes%20typically%20don't%20have%20to%20be%2C%20you%20might%20not%20be%20able%20to%20fit%20the%20table%20into%20your%20coordinator%20node.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%3CBR%20%2F%3ESo%2C%20in%20Citus%2010%2C%20we%20introduced%202%20new%20functions%20to%20reduce%20the%20steps%20you%20need%20to%20make%20changes%20to%20your%20tables%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%20data-leveltext%3D%22%EF%82%B7%22%20data-font%3D%22Symbol%22%20data-listid%3D%224%22%20aria-setsize%3D%22-1%22%20data-aria-posinset%3D%221%22%20data-aria-level%3D%221%22%3E%3CCODE%20style%3D%22color%3A%20black%3B%22%3Ealter_distributed_table%3C%2FCODE%3E%3C%2FLI%3E%0A%3CLI%20data-leveltext%3D%22%EF%82%B7%22%20data-font%3D%22Symbol%22%20data-listid%3D%224%22%20aria-setsize%3D%22-1%22%20data-aria-posinset%3D%221%22%20data-aria-level%3D%221%22%3E%3CCODE%20style%3D%22color%3A%20black%3B%22%3Ealter_table_set_access_method%3C%2FCODE%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20this%20post%20you%E2%80%99ll%20find%20some%20tips%20about%20how%20to%20use%20the%3CCODE%20style%3D%22color%3A%20black%3B%22%3Ealter_distributed_table%3C%2FCODE%3Efunction%20to%20change%20the%20shard%20count%2C%20distribution%20column%2C%20and%20the%20colocation%20of%20a%20distributed%20Citus%20table.%20And%20we'll%20show%20how%20to%20use%20the%3CCODE%20style%3D%22color%3A%20black%3B%22%3Ealter_table_set_access_method%3C%2FCODE%3Efunction%20to%20change%2C%20well%2C%20the%20access%20method.%20%3CSTRONG%3EAn%20important%20note%3A%20you%20may%20not%20ever%20need%20to%20change%20your%20Citus%20table%20properties.%3C%2FSTRONG%3E%20We%20just%20want%20you%20to%20know%2C%20if%20you%20ever%20do%2C%20you%20have%20the%20flexibility.%20And%20with%20these%20Citus%20tips%2C%20you%20will%20know%20how%20to%20make%20the%20changes.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Dj-turntables-purple-and-pink-for-Citus-tips-blog-1920x1080.jpg%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F277198i6C85BF7045CECC82%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Dj-turntables-purple-and-pink-for-Citus-tips-blog-1920x1080.jpg%22%20alt%3D%22Dj-turntables-purple-and-pink-for-Citus-tips-blog-1920x1080.jpg%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--470747028%22%20id%3D%22toc-hId--470563475%22%3EAltering%20the%20properties%20of%20distributed%20Postgres%20tables%20in%20Citus%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWhen%20you%20distribute%20a%20Postgres%20table%20with%20the%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Fpostgresql%2Freference-hyperscale-functions%23create_distributed_table%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ecreate_distributed_table%3C%2FA%3E%20function%2C%20you%20must%20pick%20a%20distribution%20column%20and%20set%20the%3CCODE%20style%3D%22color%3A%20black%3B%22%3Edistribution_column%3C%2FCODE%3Eparameter.%20During%20the%20distribution%2C%20Citus%20uses%20a%20configuration%20variable%20called%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Fpostgresql%2Freference-hyperscale-parameters%23citusshard_count-integer%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Eshard_count%3C%2FA%3E%20for%20deciding%20the%20shard%20count%20of%20the%20table.%20You%20can%20also%20provide%3CCODE%20style%3D%22color%3A%20black%3B%22%3Ecolocate_with%3C%2FCODE%3Eparameter%20to%20pick%20a%20table%20to%20colocate%20with%20(or%20colocation%20will%20be%20done%20automatically%2C%20if%20possible).%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EHowever%2C%20after%20the%20distribution%20if%20you%20decide%20you%20need%20to%20have%20a%20different%20configuration%2C%20starting%20from%20Citus%2010%2C%20you%20can%20use%20the%20%3CA%20href%3D%22https%3A%2F%2Fdocs.citusdata.com%2Fen%2Fstable%2Fdevelop%2Fapi_udf.html%23alter-distributed-table%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Ealter_distributed_table%3C%2FA%3E%20function.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CCODE%20style%3D%22color%3A%20black%3B%22%3Ealter_distributed_table%3C%2FCODE%3Ehas%20three%20parameters%20you%20can%20change%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%20data-leveltext%3D%22%EF%82%B7%22%20data-font%3D%22Symbol%22%20data-listid%3D%2210%22%20aria-setsize%3D%22-1%22%20data-aria-posinset%3D%221%22%20data-aria-level%3D%221%22%3Edistribution%20column%3C%2FLI%3E%0A%3CLI%20data-leveltext%3D%22%EF%82%B7%22%20data-font%3D%22Symbol%22%20data-listid%3D%2210%22%20aria-setsize%3D%22-1%22%20data-aria-posinset%3D%221%22%20data-aria-level%3D%221%22%3Eshard%20count%3C%2FLI%3E%0A%3CLI%20data-leveltext%3D%22%EF%82%B7%22%20data-font%3D%22Symbol%22%20data-listid%3D%2210%22%20aria-setsize%3D%22-1%22%20data-aria-posinset%3D%221%22%20data-aria-level%3D%221%22%3Ecolocation%20properties%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-2016765805%22%20id%3D%22toc-hId-2016949358%22%3EHow%20to%20change%20the%20distribution%20column%20(aka%20the%20sharding%20key)%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ECitus%20divides%20your%20table%20into%20shards%20based%20on%20the%20distribution%20column%20you%20select%20while%20distributing.%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Fpostgresql%2Fconcepts-hyperscale-choose-distribution-column%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EPicking%20the%20right%20distribution%20column%3C%2FA%3E%20is%20crucial%20for%20having%20a%20good%20distributed%20database%20experience.%20A%20good%20distribution%20column%20will%20help%20you%20parallelize%20your%20data%20and%20workload%20better%20by%20dividing%20your%20data%20evenly%20and%20keeping%20related%20data%20points%20close%20to%20each%20other.%20However%2C%20choosing%20the%20distribution%20column%20might%20be%20a%20bit%20tricky%20when%20you%E2%80%99re%20first%20getting%20started.%20Or%20perhaps%20later%20as%20you%20make%20changes%20in%20your%20application%2C%20you%20might%20need%20to%20pick%20another%20distribution%20column.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWith%20the%3CCODE%20style%3D%22color%3A%20black%3B%22%3Edistribution_column%3C%2FCODE%3Eparameter%20of%20the%20new%3CCODE%20style%3D%22color%3A%20black%3B%22%3Ealter_distributed_table%3C%2FCODE%3Efunction%2C%20Citus%2010%20gives%20you%20an%20easy%20way%20to%20change%20the%20distribution%20column.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ELet%E2%80%99s%20say%20you%20have%20customers%20and%20orders%20that%20your%20customers%20make.%20You%20will%20create%20some%20Postgres%20tables%20like%20these%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-sql%22%3E%3CCODE%3ECREATE%20TABLE%20customers%20(customer_id%20BIGINT%2C%20name%20TEXT%2C%20address%20TEXT)%3B%0ACREATE%20TABLE%20orders%20(order_id%20BIGINT%2C%20customer_id%20BIGINT%2C%20products%20BIGINT%5B%5D)%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWhen%20first%20distributing%20your%20Postgres%20tables%20with%20Citus%2C%20let%E2%80%99s%20say%20that%20you%20decided%20to%20distribute%20the%3CCODE%20style%3D%22color%3A%20black%3B%22%3Ecustomers%3C%2FCODE%3Etable%20on%3CCODE%20style%3D%22color%3A%20black%3B%22%3Ecustomer_id%3C%2FCODE%3Eand%20the%3CCODE%20style%3D%22color%3A%20black%3B%22%3Eorders%3C%2FCODE%3Etable%20on%3CCODE%20style%3D%22color%3A%20black%3B%22%3Eorder_id%3C%2FCODE%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-sql%22%3E%3CCODE%3ESELECT%20create_distributed_table%20('customers'%2C%20'customer_id')%3B%0ASELECT%20create_distributed_table%20('orders'%2C%20'order_id')%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ELater%20you%20might%20realize%20distributing%20the%3CCODE%20style%3D%22color%3A%20black%3B%22%3Eorders%3C%2FCODE%3Etable%20by%20the%3CCODE%20style%3D%22color%3A%20black%3B%22%3Eorder_id%3C%2FCODE%3Ecolumn%20might%20not%20be%20the%20best%20idea.%20Even%20though%3CCODE%20style%3D%22color%3A%20black%3B%22%3Eorder_id%3C%2FCODE%3Ecould%20be%20a%20good%20column%20to%20evenly%20distribute%20your%20data%2C%20it%20is%20not%20a%20good%20choice%20if%20you%20frequently%20need%20to%20join%20the%3CCODE%20style%3D%22color%3A%20black%3B%22%3Eorders%3C%2FCODE%3Etable%20with%20the%3CCODE%20style%3D%22color%3A%20black%3B%22%3Ecustomers%3C%2FCODE%3Etable%20on%20the%3CCODE%20style%3D%22color%3A%20black%3B%22%3Ecustomer_id%3C%2FCODE%3E.%20When%20both%20tables%20are%20distributed%20by%3CCODE%20style%3D%22color%3A%20black%3B%22%3Ecustomer_id%3C%2FCODE%3Eyou%20can%20use%20%3CA%20href%3D%22https%3A%2F%2Fdocs.citusdata.com%2Fen%2Fstable%2Fsharding%2Fdata_modeling.html%23table-co-location%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Ecolocated%20joins%3C%2FA%3E%2C%20which%20are%20very%20efficient%20compared%20to%20joins%20on%20other%20columns.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESo%2C%20if%20you%20decide%20to%20change%20the%20distribution%20column%20of%3CCODE%20style%3D%22color%3A%20black%3B%22%3Eorders%3C%2FCODE%3Etable%20into%3CCODE%20style%3D%22color%3A%20black%3B%22%3Ecustomer_id%3C%2FCODE%3Ehere%20is%20how%20you%20do%20it%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-sql%22%3E%3CCODE%3ESELECT%20alter_distributed_table%20('orders'%2C%20distribution_column%20%3A%3D%20'customer_id')%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENow%20the%3CCODE%20style%3D%22color%3A%20black%3B%22%3Eorders%3C%2FCODE%3Etable%20is%20distributed%20by%3CCODE%20style%3D%22color%3A%20black%3B%22%3Ecustomer_id%3C%2FCODE%3E.%20So%2C%20the%20customers%20and%20the%20orders%20of%20the%20customers%20are%20in%20the%20same%20node%20and%20close%20to%20each%20other%2C%20and%20you%20can%20have%20fast%20joins%20and%20foreign%20keys%20that%20include%20the%3CCODE%20style%3D%22color%3A%20black%3B%22%3Ecustomer_id%3C%2FCODE%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20can%20see%20the%20new%20distribution%20column%20on%20the%20%3CA%20href%3D%22https%3A%2F%2Fdocs.citusdata.com%2Fen%2Fstable%2Fdevelop%2Fapi_metadata.html%23citus-tables-view%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Ecitus_tables%20view%3C%2FA%3E%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-sql%22%3E%3CCODE%3ESELECT%20distribution_column%20FROM%20citus_tables%20WHERE%20table_name%3A%3Atext%20%3D%20'orders'%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-209311342%22%20id%3D%22toc-hId-209494895%22%3EHow%20to%20increase%20(or%20decrease)%20the%20shard%20count%20in%20Citus%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EShard%20count%20of%20a%20distributed%20Citus%20table%20is%20the%20number%20of%20pieces%20the%20distributed%20table%20is%20divided%20into.%20%3CA%20href%3D%22https%3A%2F%2Fdocs.citusdata.com%2Fen%2Fstable%2Fadmin_guide%2Fcluster_management.html%23shard-count%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3EChoosing%20the%20shard%20count%3C%2FA%3E%20is%20a%20balance%20between%20the%20flexibility%20of%20having%20more%20shards%2C%20and%20the%20overhead%20for%20query%20planning%20and%20execution%20across%20the%20shards.%20Like%20distribution%20column%2C%20the%20shard%20count%20is%20also%20set%20while%20distributing%20the%20table.%20If%20you%20want%20to%20pick%20a%20different%20shard%20count%20than%20the%20default%20for%20a%20table%2C%20during%20the%20distribution%20process%20you%20can%20use%20the%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Fpostgresql%2Freference-hyperscale-parameters%23citusshard_count-integer%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ecitus.shard_count%3C%2FA%3E%20configuration%20variable%2C%20like%20this%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-sql%22%3E%3CCODE%3ECREATE%20TABLE%20products%20(id%20BIGINT%2C%20name%20TEXT)%3B%0ASET%20citus.shard_count%20TO%2020%3B%0ASELECT%20create_distributed_table%20('products'%2C%20'id')%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAfter%20distributing%20your%20table%2C%20you%20might%20decide%20the%20shard%20count%20you%20set%20was%20not%20the%20best%20option.%20Or%20your%20first%20decision%20on%20the%20shard%20count%20might%20be%20good%20for%20a%20while%20but%20your%20application%20might%20grow%20in%20time%2C%20you%20might%20add%20new%20nodes%20to%20your%20Citus%20cluster%2C%20and%20you%20might%20need%20more%20shards.%20The%3CCODE%20style%3D%22color%3A%20black%3B%22%3Ealter_distributed_table%3C%2FCODE%3Efunction%20has%20you%20covered%20in%20the%20cases%20that%20you%20want%20to%20change%20the%20shard%20count%20too.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETo%20change%20the%20shard%20count%20you%20just%20use%20the%3CCODE%20style%3D%22color%3A%20black%3B%22%3Eshard_count%3C%2FCODE%3Eparameter%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-sql%22%3E%3CCODE%3ESELECT%20alter_distributed_table%20('products'%2C%20shard_count%20%3A%3D%2030)%3B%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAfter%20the%20query%20above%2C%20your%20table%20will%20have%2030%20shards.%20You%20can%20see%20your%20table%E2%80%99s%20shard%20count%20on%20the%3CCODE%20style%3D%22color%3A%20black%3B%22%3Ecitus_tables%3C%2FCODE%3Eview%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-sql%22%3E%3CCODE%3ESELECT%20shard_count%20FROM%20citus_tables%20WHERE%20table_name%3A%3Atext%20%3D%20'products'%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--1598143121%22%20id%3D%22toc-hId--1597959568%22%3EHow%20to%20colocate%20with%20a%20different%20Citus%20distributed%20table%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWhen%20two%20Postgres%20tables%20are%20colocated%20in%20Citus%2C%20the%20rows%20of%20the%20tables%20that%20have%20the%20same%20value%20in%20the%20distribution%20column%20will%20be%20on%20the%20same%20Citus%20node.%20%3CA%20href%3D%22https%3A%2F%2Fdocs.citusdata.com%2Fen%2Fstable%2Fdevelop%2Freference_ddl.html%23co-locating-tables%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3EColocating%20the%20right%20tables%3C%2FA%3E%20will%20help%20you%20with%20better%20relational%20operations.%20Like%20the%20shard%20count%20and%20the%20distribution%20column%2C%20the%20colocation%20is%20also%20set%20while%20distributing%20your%20tables.%20You%20can%20use%20the%3CCODE%20style%3D%22color%3A%20black%3B%22%3Ecolocate_with%3C%2FCODE%3Eparameter%20to%20change%20the%20colocation.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-sql%22%3E%3CCODE%3ESELECT%20alter_distributed_table%20('products'%2C%20colocate_with%20%3A%3D%20'customers')%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAgain%2C%20like%20the%20distribution%20column%20and%20shard%20count%2C%20you%20can%20find%20information%20about%20your%20tables%E2%80%99%20colocation%20groups%20on%20the%3CCODE%20style%3D%22color%3A%20black%3B%22%3Ecitus_tables%3C%2FCODE%3Eview%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-sql%22%3E%3CCODE%3ESELECT%20colocation_id%20FROM%20citus_tables%20WHERE%20table_name%20IN%20('products'%2C%20'customers')%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20can%20also%20use%3CCODE%20style%3D%22color%3A%20black%3B%22%3Edefault%3C%2FCODE%3Eand%3CCODE%20style%3D%22color%3A%20black%3B%22%3Enone%3C%2FCODE%3Ekeywords%20with%3CCODE%20style%3D%22color%3A%20black%3B%22%3Ecolocate_with%3C%2FCODE%3Eparameter%20to%20change%20the%20colocation%20group%20of%20the%20table%20to%20default%2C%20or%20to%20break%20any%20colocation%20your%20table%20has.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETo%20colocate%20distributed%20Citus%20tables%2C%20the%20distributed%20tables%20need%20to%20have%20the%20same%20shard%20counts.%20But%20if%20the%20tables%20you%20want%20to%20colocate%20don%E2%80%99t%20have%20the%20same%20shard%20count%2C%20worry%20not%2C%20because%3CCODE%20style%3D%22color%3A%20black%3B%22%3Ealter_distributed_table%3C%2FCODE%3Ewill%20automatically%20understand%20this.%20Then%20your%20table%E2%80%99s%20shard%20count%20will%20also%20be%20updated%20to%20match%20the%20new%20colocation%20group%E2%80%99s%20shard%20count.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-889369712%22%20id%3D%22toc-hId-889553265%22%3EHow%20to%20change%20more%20than%20one%20Citus%20table%20property%20at%20a%20time%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EHere%20is%20a%20tip!%20If%20you%20want%20to%20change%20multiple%20properties%20of%20your%20distributed%20Citus%20tables%20at%20the%20same%20time%2C%20you%20can%20simply%20use%20multiple%20parameters%20of%20the%3CCODE%20style%3D%22color%3A%20black%3B%22%3Ealter_distributed_table%3C%2FCODE%3Efunction.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFor%20example%2C%20if%20you%20want%20to%20change%20both%20the%20shard%20count%20and%20the%20distribution%20column%20of%20a%20table%20here's%20how%20you%20do%20it%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-sql%22%3E%3CCODE%3ESELECT%20alter_distributed_table%20('products'%2C%20distribution_column%20%3A%3D%20'name'%2C%20shard_count%20%3A%3D%2035)%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--918084751%22%20id%3D%22toc-hId--917901198%22%3EHow%20to%20alter%20the%20Citus%20colocation%20group%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20your%20table%20is%20colocated%20with%20some%20other%20tables%20and%20you%20want%20to%20change%20the%20shard%20count%20of%20all%20of%20the%20tables%20to%20keep%20the%20colocation%2C%20you%20might%20be%20wondering%20if%20you%20have%20to%20alter%20them%20one%20by%20one...%20which%20is%20multiple%20steps.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYes%20(you%20can%20see%20a%20pattern%20here)%20the%20Citus%20tip%20is%20that%20you%20can%20use%20the%3CCODE%20style%3D%22color%3A%20black%3B%22%3Ealter_distributed_table%3C%2FCODE%3Efunction%20to%20change%20the%20properties%20of%20all%20of%20the%20colocation%20group.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20you%20decide%20the%20change%20you%20make%20with%20the%3CCODE%20style%3D%22color%3A%20black%3B%22%3Ealter_distributed_table%3C%2FCODE%3Efunction%20needs%20to%20be%20done%20to%20all%20the%20tables%20that%20are%20colocated%20with%20the%20table%20you%20are%20changing%2C%20you%20can%20use%20the%3CCODE%20style%3D%22color%3A%20black%3B%22%3Ecascade_to_colocated%3C%2FCODE%3Eparameter%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-sql%22%3E%3CCODE%3ESET%20citus.shard_count%20TO%2010%3B%0ASELECT%20create_distributed_table%20('customers'%2C%20'customer_id')%3B%0ASELECT%20create_distributed_table%20('orders'%2C%20'customer_id'%2C%20colocate_with%20%3A%3D%20'customers')%3B%0A--%20when%20you%20decide%20to%20change%20the%20shard%20count%20%0A--%20of%20all%20of%20the%20colocation%20group%0ASELECT%20alter_distributed_table%20('customers'%2C%20shard_count%20%3A%3D%2020%2C%20cascade_to_colocated%20%3A%3D%20true)%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20can%20see%20the%20updated%20shard%20count%20of%20both%20tables%20on%20the%3CCODE%20style%3D%22color%3A%20black%3B%22%3Ecitus_tables%3C%2FCODE%3Eview%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-sql%22%3E%3CCODE%3ESELECT%20shard_count%20FROM%20citus_tables%20WHERE%20table_name%20IN%20('customers'%2C%20'orders')%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1569428082%22%20id%3D%22toc-hId-1569611635%22%3EHow%20to%20change%20your%20Postgres%20table%E2%80%99s%20access%20method%20in%20Citus%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAnother%20amazing%20feature%20introduced%20in%20Citus%2010%20is%20%3CA%20href%3D%22https%3A%2F%2Fdocs.citusdata.com%2Fen%2Fstable%2Fadmin_guide%2Ftable_management.html%23columnar-storage%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Ecolumnar%3C%2FA%3E%20storage.%20This%20%3CA%20href%3D%22https%3A%2F%2Fwww.citusdata.com%2Fblog%2F2021%2F03%2F06%2Fcitus-10-columnar-compression-for-postgres%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3ECitus%2010%20columnar%20blog%20post%3C%2FA%3E%20walks%20you%20through%20how%20it%20works%20and%20how%20to%20use%20columnar%20tables%20(or%20partitions)%20with%20Citus%E2%80%94complete%20with%20a%20Quickstart.%20Oh%2C%20and%20Jeff%20made%20a%20short%20%3CA%20href%3D%22https%3A%2F%2Fyoutu.be%2FSS7jcq9fTnw%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Evideo%20demo%20about%20the%20new%20Citus%2010%20columnar%20functionality%3C%2FA%3E%20too%E2%80%94it%E2%80%99s%20worth%20the%2013%20minutes%20to%20watch%20IMHO.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWith%20Citus%20columnar%2C%20you%20can%20optionally%20choose%20to%20store%20your%20tables%20grouped%20by%20columns%E2%80%94which%20gives%20you%20the%20benefits%20of%20compression%2C%20too.%20Of%20course%2C%20you%20don%E2%80%99t%20have%20to%20use%20the%20new%20columnar%20access%20method%E2%80%94the%20default%20access%20method%20is%20%E2%80%9Cheap%E2%80%9D%20and%20if%20you%20don%E2%80%99t%20specify%20an%20access%20method%2C%20then%20your%20tables%20will%20be%20row-based%20tables%20(with%20the%20heap%20access%20method.)%3C%2FP%3E%0A%3CP%3E%3CBR%20%2F%3EIt%20would%20not%20be%20fair%20to%20introduce%20this%20cool%20new%20Citus%20columnar%20access%20method%20without%20also%20giving%20you%20a%20way%20to%20convert%20your%20tables%20to%20columnar.%20So%20Citus%2010%20also%20introduced%20a%20way%20to%20change%20the%20access%20method%20of%20tables.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-sql%22%3E%3CCODE%3ESELECT%20alter_table_set_access_method('orders'%2C%20'columnar')%3B%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20can%20use%20%3CA%20href%3D%22https%3A%2F%2Fdocs.citusdata.com%2Fen%2Fstable%2Fdevelop%2Fapi_udf.html%23alter-table-set-access-method%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Ealter_table_set_access_method%3C%2FA%3E%20to%20convert%20your%20table%20to%20any%20other%20access%20method%20too%2C%20such%20as%3CCODE%20style%3D%22color%3A%20black%3B%22%3Eheap%3C%2FCODE%3E%2C%20Postgres%E2%80%99s%20default%20access%20method.%20Also%2C%20your%20table%20doesn%E2%80%99t%20even%20need%20to%20be%20a%20distributed%20Citus%20table.%20You%20can%20also%20use%3CCODE%20style%3D%22color%3A%20black%3B%22%3Ealter_table_set_access_method%3C%2FCODE%3Ewith%20Citus%20reference%20tables%20as%20well%20as%20regular%20Postgres%20tables.%20You%20can%20even%20change%20the%20access%20method%20of%20a%20Postgres%20partition%20with%3CCODE%20style%3D%22color%3A%20black%3B%22%3Ealter_table_set_access_method%3C%2FCODE%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--238026381%22%20id%3D%22toc-hId--237842828%22%3EUnder%20the%20hood%3A%20How%20do%20these%20new%20Citus%20functions%20work%3F%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20you%E2%80%99ve%20read%20the%20%3CA%20href%3D%22https%3A%2F%2Fwww.citusdata.com%2Fblog%2F2021%2F02%2F06%2Fcitus-tips-how-to-undistribute-a-distributed-postgres-table%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Eblog%20post%20about%20undistribute_table%3C%2FA%3E%2C%20the%20function%20Citus%209.5%20introduced%20for%20turning%20distributed%20Citus%20tables%20back%20to%20local%20Postgres%20tables%2C%20you%20mostly%20know%20how%20the%3CCODE%20style%3D%22color%3A%20black%3B%22%3Ealter_distributed_table%3C%2FCODE%3Eand%3CCODE%20style%3D%22color%3A%20black%3B%22%3Ealter_table_set_access_method%3C%2FCODE%3Efunctions%20work.%20Because%20we%20use%20the%20same%20underlying%20methodology%20as%20the%3CCODE%20style%3D%22color%3A%20black%3B%22%3Eundistribute_table%3C%2FCODE%3Efunction.%20Well%2C%20we%20improved%20upon%20it.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%3CCODE%20style%3D%22color%3A%20black%3B%22%3Ealter_distributed_table%3C%2FCODE%3Eand%3CCODE%20style%3D%22color%3A%20black%3B%22%3Ealter_table_set_access_method%3C%2FCODE%3Efunctions%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3COL%3E%0A%3CLI%20data-leveltext%3D%22%251.%22%20data-listid%3D%222%22%20aria-setsize%3D%22-1%22%20data-aria-posinset%3D%221%22%20data-aria-level%3D%221%22%3ECreate%20a%20new%20table%20in%20the%20way%20you%20want%20(with%20the%20new%20shard%20count%20or%20access%20method%20etc.)%3C%2FLI%3E%0A%3CLI%20data-leveltext%3D%22%251.%22%20data-listid%3D%222%22%20aria-setsize%3D%22-1%22%20data-aria-posinset%3D%221%22%20data-aria-level%3D%221%22%3EMove%20everything%20from%20your%20old%20table%20to%20the%20new%20table%3C%2FLI%3E%0A%3CLI%20data-leveltext%3D%22%251.%22%20data-listid%3D%222%22%20aria-setsize%3D%22-1%22%20data-aria-posinset%3D%221%22%20data-aria-level%3D%221%22%3EDrop%20the%20old%20table%20and%20rename%20the%20new%20one%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EDropping%20a%20table%20for%20the%20purpose%20of%20re-creating%20the%20same%20table%20with%20different%20properties%20is%20not%20a%20simple%20task.%20Dropping%20the%20table%20will%20also%20drop%20many%20things%20that%20depend%20on%20the%20table.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EJust%20like%20the%3CCODE%20style%3D%22color%3A%20black%3B%22%3Eundistribute_table%3C%2FCODE%3Efunction%2C%20the%3CCODE%20style%3D%22color%3A%20black%3B%22%3Ealter_distributed_table%3C%2FCODE%3Eand%3CCODE%20style%3D%22color%3A%20black%3B%22%3Ealter_table_set_access_method%3C%2FCODE%3Efunctions%20do%20a%20lot%20to%20preserve%20the%20properties%20of%20the%20table%20you%20didn%E2%80%99t%20want%20to%20change.%20The%20functions%20will%20handle%20indexes%2C%20sequences%2C%20views%2C%20constraints%2C%20table%20owner%2C%20partitions%20and%20more%E2%80%94just%20like%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fdocs.citusdata.com%2Fen%2Fstable%2Fdevelop%2Fapi_udf.html%23undistribute-table%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Eundistribute_table%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CCODE%20style%3D%22color%3A%20black%3B%22%3Ealter_distributed_table%3C%2FCODE%3Eand%3CCODE%20style%3D%22color%3A%20black%3B%22%3Ealter_table_set_access_method%3C%2FCODE%3Ewill%20also%20recreate%20the%20foreign%20keys%20on%20your%20tables%20whenever%20possible.%20For%20example%2C%20if%20you%20change%20the%20shard%20count%20of%20a%20table%20with%20the%3CCODE%20style%3D%22color%3A%20black%3B%22%3Ealter_distributed_table%3C%2FCODE%3Efunction%20and%20use%3CCODE%20style%3D%22color%3A%20black%3B%22%3Ecascade_to_colocated%20%3A%3D%20true%3C%2FCODE%3Eto%20change%20the%20shard%20count%20of%20all%20the%20colocated%20tables%2C%20then%20foreign%20keys%20within%20the%20colocation%20group%20%3CEM%3Eand%3C%2FEM%3E%20foreign%20keys%20from%20the%20distributed%20tables%20of%20the%20colocation%20group%20to%20Citus%20reference%20tables%20will%20be%20recreated.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--2045480844%22%20id%3D%22toc-hId--2045297291%22%3EMaking%20it%20easier%20to%20experiment%20with%20Citus%E2%80%94and%20to%20adapt%20as%20your%20needs%20change%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20you%20want%20to%20learn%20more%20about%20our%20previous%20work%20which%20we%20build%20on%20for%3CCODE%20style%3D%22color%3A%20black%3B%22%3Ealter_distributed_table%3C%2FCODE%3Eand%3CCODE%20style%3D%22color%3A%20black%3B%22%3Ealter_table_set_access_method%3C%2FCODE%3Efunctions%20go%20check%20out%20%3CA%20href%3D%22https%3A%2F%2Fwww.citusdata.com%2Fblog%2F2021%2F02%2F06%2Fcitus-tips-how-to-undistribute-a-distributed-postgres-table%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Eour%20blog%20post%20on%20undistribute_table%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20Citus%2010%20we%20worked%20to%20give%20you%20more%20tools%20and%20more%20capabilities%20for%20making%20changes%20to%20your%20distributed%20database.%20When%20you%E2%80%99re%20just%20starting%20to%20use%20Citus%2C%20the%20new%3CCODE%20style%3D%22color%3A%20black%3B%22%3Ealter_distributed_table%3C%2FCODE%3Eand%3CCODE%20style%3D%22color%3A%20black%3B%22%3Ealter_table_set_access_method%3C%2FCODE%3Efunctions%E2%80%94along%20with%20the%3CCODE%20style%3D%22color%3A%20black%3B%22%3Eundistribute_table%3C%2FCODE%3Efunction%E2%80%94are%20all%20here%20to%20help%20you%20experiment%20and%20find%20the%20database%20configuration%20that%20works%20the%20best%20for%20your%20application.%20And%20in%20the%20future%2C%20if%20and%20when%20your%20application%20evolves%2C%20these%20three%20Citus%20functions%20will%20be%20ready%20to%20help%20you%20evolve%20your%20Citus%20database%2C%20too.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-2311470%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Dj-turntables-purple-and-pink-for-Citus-tips-blog-1200x630.jpg%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F277169iC56F2B1197945453%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Dj-turntables-purple-and-pink-for-Citus-tips-blog-1200x630.jpg%22%20alt%3D%22Dj-turntables-purple-and-pink-for-Citus-tips-blog-1200x630.jpg%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EHow%20to%20change%20your%20distribution%20column%2C%20shard%20count%2C%20colocation%2C%20%26amp%3B%20access%20method%20with%20Hyperscale%20(Citus)%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2311470%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%20Database%20for%20PostgreSQL%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ECitus%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EOpen%20Source%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Epostgres%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPostgres%20extensions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Co-Authors
Version history
Last update:
‎May 03 2021 09:26 AM
Updated by: