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
相关推荐
qq_白羊座10 小时前
:: 符号(Postgres / Hologres)
postgresql
zhangjw3412 小时前
1-3 PostgreSQL 架构模型:实例、数据库、Schema 模式、表空间完整概念
数据库·postgresql·架构
周周爱喝粥呀13 小时前
详细教程:在 Docker 中部署 PostgreSQL 并使用 pgAdmin 可视化管理
docker·postgresql·容器
qq_白羊座13 小时前
Hologres / PostgreSQL jsonb 常用函数 & 操作符对照表
数据库·postgresql
kele_z15 小时前
手工修改数据库中的数据时,我会加的四道保险
mysql·postgresql
ly768916 小时前
PostgreSQL 执行计划深读:从 EXPLAIN 输出到代价模型驱动的 SQL 改写
数据库·sql·postgresql·explain·执行计划·代价模型
ss27316 小时前
AI时代首先数据库-PostgreSQL实战笔记 | 16 PostgreSQL子查询与嵌套查询(下)
数据库·笔记·postgresql
l1t18 小时前
DeepSeek总结的PostgreSQL 的 MVCC 很糟。其他所有的也一样。第1部分
数据库·postgresql
ss27320 小时前
AI时代首先数据库-PostgreSQL实战笔记 | 15 PostgreSQL子查询与嵌套查询(上)
数据库·人工智能·postgresql
ly76892 天前
PostgreSQL 备份恢复策略:pg_basebackup、WAL 归档与 PITR 在企业 Java 系统中的落地
java·数据库·postgresql·pitr·pg_basebackup·wal 归档