This article is half-done without your Comment! *** Please share your thoughts via Comment ***
My Problem:
In our Windows based PostgreSQL Server, We were facing Hard disk related performance issue. Later, we decided to move some of our main tables on SSD Hard Disk (Solid State Drive).
The Performance of SSD Hard drive is 10 times faster than normal HDD Disk.
The Solution:
First, We have to create new Tablespace on SSD disk. The pg_default is a default Tablespace in PostgreSQL. A Tablespace contains all Table information and data.
In PostgreSQL, We can create a new Tablespace or we can also alter Tablespace for existing Tables.
We can perform this exercise using both PGAdmin tool and Script.
In below example, I am creating and changing Tablespace using script.
The Syntax of CREATE TABLESPACE:
1 2 3 |
CREATE TABLESPACE tablespace_name OWNER user_name LOCATION directory_path; |
Create a sample Tablespace:
1 2 3 |
CREATE TABLESPACE dbrnd OWNER postgres LOCATION 'E:\temp\dbrnd'; |
Create a new table under newly created Tablespace:
1 2 3 |
CREATE TABLE tbl_Students (Rno INT, Name CHARACTER VARYING) TABLESPACE dbrnd; |
We can also change default Tablespace:
After this change, all your newly table can create under dbrnd Tablespace.
1 |
SET default_tablespace = dbrnd; |
Create one more table and test this:
1 2 |
CREATE TABLE tbl_Employee (Eno INT, Name CHARACTER VARYING); |
Change Tablespace of existing Table:
1 |
ALTER TABLE tbl_Employee SET TABLESPACE pg_default; |
Check all Tablespace of your PostgreSQL Database Server:
1 |
SELECT spcname FROM pg_tablespace; |