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
相关推荐
smallyoung1 天前
数据库乐观锁深度解析:MySQL、PostgreSQL 实战 + Spring Boot 集成指南
数据库·mysql·postgresql
秉承初心16 天前
PostgreSQL 数据性能瓶颈突破实战
数据库·postgresql·oracle
IvorySQL17 天前
PostgreSQL 技术日报 (6月15日)|PG19 性能优化推进,POSETTE 大会倒计时 2 天
数据库·人工智能·postgresql·开源
IvorySQL17 天前
PostgreSQL 技术日报 (6月16日)|Neon 自动化再进一步,逻辑复制冲突日志迎来 v50 更新
数据库·postgresql·自动化
倒流时光三十年17 天前
PostgreSQL 聊一下索引和排序规则
postgresql
睡不醒男孩03082318 天前
PostgreSQL 数据库运维转型:从传统模式到 CLup 平台的 25 个核心 FAQ
运维·数据库·postgresql
JOJO数据科学18 天前
pgAdmin4 Electron 鸿蒙 PC 适配全记录:从白屏到连接 PostgreSQL
postgresql·electron·harmonyos
日取其半万世不竭18 天前
PostgreSQL 跑在 Docker 里怎么备份?恢复成功才算备份成功
数据库·docker·postgresql
倒流时光三十年18 天前
PostgreSQL LEAST 表达式函数详解
数据库·postgresql
Rain50918 天前
2.4. PostgreSQL 数据库连接与实战指南
前端·数据库·人工智能·后端·postgresql·数据分析