Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

About clustered index in postgres

I'm using psql to access a postgres database. When viewing the metadata of a table, is there any way to see whether an index of a table is a clustered index?

I heard that the PRIMARY KEY of a table is automatically associated with a clustered index, is it true?

like image 457
twimo Avatar asked Jan 25 '11 17:01

twimo


People also ask

Does Postgres use clustered index?

PostgreSQL does not have a clustered index, so you won't be able to see them.

What is the purpose of the clustered index?

Clustered indexes sort and store the data rows in the table or view based on their key values. These are the columns included in the index definition. There can be only one clustered index per table, because the data rows themselves can be stored in only one order.

What is clustered and non clustered index in PostgreSQL?

Clustered Index – Index data gets stored along with other part of data and data gets sorted based on index key. At most there can be only one index in this category for a specified table. Non-Clustered Index – Index data gets stored separately and it has a pointer to the storage where other part of data is stored.

What is clustering in Postgres?

A database cluster is a collection of databases that is managed by a single instance of a running database server. After initialization, a database cluster will contain a database named postgres , which is meant as a default database for use by utilities, users and third party applications.


1 Answers

Note that PostgreSQL uses the term "clustered index" to use something vaguely similar and yet very different to SQL Server.

If a particular index has been nominated as the clustering index for a table, then psql's \d command will indicate the clustered index, e.g.,

Indexes:     "timezone_description_pkey" PRIMARY KEY, btree (timezone) CLUSTER 

PostgreSQL does not nominate indices as clustering indices by default. Nor does it automatically arrange table data to correlate with the clustered index even when so nominated: the CLUSTER command has to be used to reorganise the table data.

like image 59
araqnid Avatar answered Oct 01 '22 05:10

araqnid