PostgreSQL Tutorial

  • Home
  • Stored Procedures
  • Triggers
  • Views
  • Interfaces
    • PostgreSQL PHP
    • PostgreSQL Python
    • PostgreSQL JDBC
  • Functions
    • Aggregate Functions
    • Date / Time Functions
    • String Functions
    • Math Functions
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: Reset Forgotten Password For postgres User

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
  • Copy a Database
  • Get Database Object Sizes

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 ANY Operator
  • PostgreSQL EXISTS
  • How To Delete Duplicate Rows in PostgreSQL
  • PostgreSQL TO_CHAR Function
  • PostgreSQL TO_NUMBER Function
  • PostgreSQL TO_TIMESTAMP Function
  • PostgreSQL CEIL Function
  • PostgreSQL MOD Function
  • PostgreSQL FLOOR Function
  • PostgreSQL ABS Function

More Tutorials

  • PostgreSQL Cheat Sheet
  • PostgreSQL Administration
  • PostgreSQL PHP
  • PostgreSQL Python
  • PostgreSQL JDBC
  • PostgreSQL Resources

Site Info

  • Home
  • About Us
  • Contact Us
  • Privacy Policy

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