PostgreSQL Tutorial

  • Home
  • Administration
  • Views
  • Triggers
  • Stored Procedures
  • Interfaces
    • PostgreSQL PHP
    • PostgreSQL Python
    • PostgreSQL JDBC
Home / PostgreSQL Administration / PostgreSQL ALTER TABLESPACE

PostgreSQL ALTER TABLESPACE

Summary: in this tutorial, you will learn how to change the definition of a tablespace by using the PostgreSQL ALTER TABLESPACE statement.

Introduction to ALTER TABLESPACE statement

Once a tablespace is created, you can change its definition by using the ALTER TABLESPACE as shown below:

1
ALTER TABLESPACE action;

PostgreSQL provides some actions such as renaming tablespace name, changing the owner and setting tablespace’s parameters.

To change the name of the tablespace, use the following statement:

1
ALTER TABLESPACE tablespace_name RENAME TO new_name;

To change the owner of the tablespace, use the following statement:

1
ALTER TABLESPACE tablespace_name OWNER TO new_owner;

You can also change the tablespace’s parameters including seq_page_cost and random_page_cost, which specify the cost of reading pages from tables in the tablespace.

1
ALTER TABLESPACE tablespace_name SET parameter = value;

To execute the ALTER TABLESPACE statement, you must be a superuser or the owner of the tablespace.

Currently, PostgreSQL does not support change the location of the tablespace.

Notice that ALTER TABLESPACE statement is a PostgreSQL extension.

PostgreSQL ALTER TABLESPACE examples

The following statement renames dvdrentaltablespace to dvdrental_raid:

1
ALTER TABLESPACE dvdrental RENAME TO dvdrental_raid;

To change the owner of the  dvdrental_raid from postgresto hr, use the following statement:

1
ALTER TABLESPACE dvdrental_raid OWNER to hr;

In this tutorial, you have learned how to change the tablespace’s definition by using the PostgreSQL ALTER TABLESPACE statement.

Previous Tutorial: PostgreSQL Creating Tablespaces
Next Tutorial: Deleting Tablespaces Using PostgreSQL DROP TABLESPACE Statement

PostgreSQL Quick Start

  • What is PostgreSQL?
  • Install PostgreSQL
  • Connect to Database
  • Download PostgreSQL Sample Database
  • Load Sample Database
  • Explore Server and Database Objects

Databases Management

  • Create New Databases
  • Modify Databases
  • Delete Databases

PostgreSQL Roles Administration

  • Introduction to PostgresQL Roles

PostgreSQL Backup & Restore

  • PostgreSQL Backup Databases
  • PostgreSQL Restore Databases

Tablespaces Management

  • Creating Tablespaces
  • Changing Tablespaces
  • Deleting Tablespaces

About PostgreSQL Tutorial

PostgreSQLTutorial.com is a website dedicated to developers and database administrators who are working on PostgreSQL database management system.

We constantly publish useful PostgreSQL tutorials to keep you up-to-date with the latest PostgreSQL features and technologies. All PostgreSQL tutorials are simple, easy-to-follow and practical.

Recent PostgreSQL Tutorials

  • PostgreSQL Recursive View
  • Learn PostgreSQL Recursive Query By Example
  • Creating Updatable Views Using the WITH CHECK OPTION Clause
  • PostgreSQL Upsert Using INSERT ON CONFLICT statement
  • How to Generate a Random Number in A Range
  • Using PostgreSQL ADD COLUMN to Add One or More Columns To a Table
  • PostgreSQL Character Types: CHAR, VARCHAR, and TEXT
  • Using PostgreSQL SERIAL To Create Auto-increment Column
  • PostgreSQL Boolean Data Type with Practical Examples
  • Understanding PostgreSQL Timestamp Data Types

More Tutorials

  • PostgreSQL PHP
  • PostgreSQL Python
  • PostgreSQL JDBC
  • PostgreSQL Functions
  • PostgreSQL Resources

Site Info

  • Home
  • About Us
  • Contact Us
  • Privacy Policy

Copyright © 2016 by PostgreSQL Tutorial Website. All Rights Reserved.