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
相关推荐
Vd7H20A71 天前
TencentOS Server 3.3 安装 PostgreSQL 18 完整指南
数据库·postgresql
IvorySQL2 天前
PostgreSQL 技术日报 (6月8日)|索引预取迭代,AI 安全功能上新
数据库·人工智能·sql·安全·postgresql
睡不醒男孩0308232 天前
CLup篇之PostgreSQL管理
数据库·postgresql
瀚高PG实验室2 天前
数据库启动报错:42501: 无法打开共享内存段 “/PostgreSQL.******“: 权限不够
数据库·postgresql·瀚高数据库
睡不醒男孩0308232 天前
第十篇:PostgreSQL 生产环境高可用选型:CLUP 与 Patroni 深度架构对比与踩坑实录
数据库·postgresql·架构
花间相见2 天前
【AI工作流搭建n8n】—— Docker + PostgreSQL 生产环境部署全攻略:MCP 集成与 Skills 技能实战
人工智能·docker·postgresql
小二·2 天前
PostgreSQL 高级特性与性能调优
数据库·postgresql
_未闻花名_2 天前
PostgreSQL的若干扩展安装和使用
spring boot·postgresql·postgis·timescaledb·pg_cron·pgmq·zhparser
取名好樊2 天前
Windows Docker PostgreSQL 端口绑定失败问题记录
windows·docker·postgresql
逍遥德2 天前
PostgreSQL --- 二进制数使用详解
数据库·sql·postgresql