PG tablespace相关命令

复制代码
--<https://www.postgresql.org/docs/18/sql-createtablespace.html>
--create tablespace
CREATE TABLESPACE tablespace_name
    [ OWNER { new_owner | CURRENT_ROLE | CURRENT_USER | SESSION_USER } ]
    LOCATION 'directory'
    [ WITH ( tablespace_option = value [, ... ] ) ]

示例: To create a tablespace db3_space at file system location /data/pg/db3_space, first create the directory using operating system facilities and set the correct ownership:

复制代码
mkdir -p /data/pg/db3_space
chown postgres:postgres /data/pg/db3_space

Then issue the tablespace creation command inside PostgreSQL:

复制代码
postgres=# create tablespace db3_space location '/data/pg/db3_space';
CREATE TABLESPACE
postgres=# \\db
            List of tablespaces
    Name    |  Owner   |      Location      
------------+----------+--------------------
 db3_space  | postgres | /data/pg/db3_space
 pg_default | postgres | 
 pg_global  | postgres | 
(3 rows)

postgres=#

To create a tablespace owned by a different database user, use a command like this:

复制代码
CREATE TABLESPACE indexspace OWNER genevieve LOCATION '/data/indexes';

--<https://www.postgresql.org/docs/18/sql-altertablespace.html>
--alter tablesapce
ALTER TABLESPACE name RENAME TO new_name
ALTER TABLESPACE name OWNER TO { new_owner | CURRENT_ROLE | CURRENT_USER | SESSION_USER }
ALTER TABLESPACE name SET ( tablespace_option = value [, ... ] )
ALTER TABLESPACE name RESET ( tablespace_option [, ... ] )

--<https://www.postgresql.org/docs/18/sql-droptablespace.html>
--drop tablespace
DROP TABLESPACE [ IF EXISTS ] name
相关推荐
资深web全栈开发39 分钟前
PostgreSQL Schema 最佳实践:架构师的命名与组织艺术
数据库·postgresql
l1t9 小时前
DeepSeek总结的为 pg_dumpall 添加非文本输出格式
postgresql
無法複制13 小时前
debian安装Postgresql-14.x
运维·postgresql·debian
IvorySQL13 小时前
IvorySQL v5 发布后,我们想听听大家的使用体验
数据库·postgresql·开源
IvorySQL13 小时前
PostgreSQL 技术日报 (3月20日)|PGConf.dev 2026 日程公布
数据库·postgresql·开源
赵渝强老师14 小时前
【赵渝强老师】高斯数据库(openGauss)的逻辑存储结构
数据库·postgresql·opengauss·gaussdb·国产数据库·高斯数据库
逍遥德1 天前
Postgresql explain执行计划详解
数据库·后端·sql·postgresql·数据分析
空空潍1 天前
PostgreSQL保姆级下载安装指南(win版)
数据库·postgresql