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
相关推荐
数据知道2 小时前
PostgreSQL实战:如何用 CTE(公用表表达式)解决复杂的查询逻辑
数据库·postgresql
MarsBighead3 小时前
PostgreSQL全文检索中文分词器配置与优化实践
ai·postgresql·rag
木风小助理12 小时前
PostgreSQL基础知识——DDL深度解析
数据库·postgresql
Linux-palpitate17 小时前
PostgreSQL单机部署
数据库·postgresql
Mr.徐大人ゞ19 小时前
2.pg工具介绍
postgresql
林九生21 小时前
【MySQL/PostgreSQL】MySQL 到 PostgreSQL 数据迁移:Docker + pgloader
mysql·docker·postgresql
Mr.徐大人ゞ1 天前
3.pg重要参数解析
postgresql
数据知道1 天前
亿级图片链接存入 PostgreSQL,URL链接字段数据类型用哪个最合适?
数据库·postgresql
l1t1 天前
净化SQL的PL/pgSQL函数
数据库·sql·postgresql