Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postgres distributing data across multiple disks

Tags:

I need your help to solve a problem as I am fairly new to Postgres and reading the manuals didn’t help.

We have a server with 4 internal hard disks. We have created a Postgres database with a few tables. We want to be able to spread our data across these 4 disks.

We want to specify somewhere (eg table space creation stage) that the data loaded into a set of tables should be distributed across the 4 disks.

Can you kindly give us the syntax or point us in the right direction?

like image 541
kannan Avatar asked Jun 27 '12 14:06

kannan


People also ask

Can a tablespace spread across multiple hard disks?

A table space is a logical unit of storage in a database. Generally speaking, spreading database table spaces across multiple disks improves performance. A table space can be System Managed Space (SMS) or Database Managed Space (DMS).

Can Postgres be distributed?

Citus is a PostgreSQL extension that transforms Postgres into a distributed database—so you can achieve high performance at any scale.

Can Postgres handle multiple connections?

No, you can only have a single statement executing at the same time on a PostgreSQL connections.


2 Answers

  1. Create four tablespaces each one on a different disk (see: http://www.postgresql.org/docs/current/static/sql-createtablespace.html)
  2. Move the content of the tables to the tablespaces so that the data is distributed as you intend it to be using ALTER TABLE foobar SET tablespace = foospace, see here: http://www.postgresql.org/docs/current/static/sql-altertable.html
  3. Move the content of the tables' indexes to the tablespaces using alter index idx_foo set tablespace = spacefoo, see here: http://www.postgresql.org/docs/current/static/sql-alterindex.html
like image 185
a_horse_with_no_name Avatar answered Sep 19 '22 20:09

a_horse_with_no_name


The best way is to create a RAID-0 or RAID-10 array and let the OS handle this for you. RAID-0 has no redundancy so any single drive failure is catastrophic. RAID-10 allows for any one disk to fail and keep right on working with good performance. Avoid RAID-5 or RAID-6 due to very poor write performance.

like image 32
Scott Marlowe Avatar answered Sep 19 '22 20:09

Scott Marlowe