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
相关推荐
曲幽42 分钟前
我用了FastApiAdmin后,连夜把踩过的坑都整理出来了
redis·python·postgresql·vue3·fastapi·web·sqlalchemy·admin·fastapiadmin
Muscleheng5 小时前
Navicat连接postgresql时出现‘datlastsysoid does not exist‘报错
数据库·postgresql
Gauss松鼠会8 小时前
GaussDB(DWS) 日常维护命令
服务器·数据库·postgresql·性能优化·gaussdb·经验总结
IvorySQL10 小时前
开源共建分论坛圆桌讨论:如何真正融入 PostgreSQL 社区?
postgresql·开源·区块链
l1t11 小时前
DeepSeek总结的postgresql 数据分析师 vs width_bucket()
数据库·postgresql
l1t15 小时前
DeepSeek总结的PostgreSQL 表访问方法
数据库·postgresql
星星也在雾里1 天前
PgBouncer 解决 PostgreSQL 连接数超限 + 可视化监控
数据库·postgresql
zhojiew1 天前
在本地PostgreSQL使用pgvector构建生成式 AI 应用的实践
数据库·人工智能·postgresql
snowfoootball1 天前
解决低版本navicat连接PostgreSQl的不兼容报错问题
数据库·postgresql
csdn小瓯1 天前
PostgreSQL迁移实战:从SQLite到生产级数据库的平滑演进
数据库·postgresql·sqlite