首页 > 数据库 >postgresql迁移表空间

postgresql迁移表空间

时间:2022-10-26 17:49:12浏览次数:47  
标签:opt 26 postgresql postgres pg13 pg 空间 迁移 Oct

环境:

OS:Centos 7

DB:13.8

 

1.创建新表空间自定义目录
su - postgres
[postgres@host134 pg13]$ mkdir -p /opt/pg13/mytps01

2.创建表空间
postgres=# create tablespace hxltps01 location '/opt/pg13/mytps01';
CREATE TABLESPACE

3.将数据库迁移到新的表空间(迁移期间不能对表有dml ddl操作)
postgres=# alter database db_test set tablespace hxltps01;
ERROR: database "db_test" is being accessed by other users
DETAIL: There is 1 other session using the database.

杀掉会话:
SELECT pg_terminate_backend(pg_stat_activity.pid)
FROM pg_stat_activity
WHERE pg_stat_activity.datname = 'db_test';

select datname from pg_stat_activity;

这个时候pg_tblspc目录会生成一个新的链接符,指向mytps01的
[postgres@host134 pg_tblspc]$ ls -al
total 4
drwx------ 2 postgres postgres 32 Oct 26 16:42 .
drwx------ 19 postgres postgres 4096 Oct 26 10:25 ..
lrwxrwxrwx 1 postgres postgres 15 Oct 26 10:25 32780 -> /opt/pg13/mytps
lrwxrwxrwx 1 postgres postgres 17 Oct 26 16:42 40973 -> /opt/pg13/mytps01


4.删除旧的表空间
postgres=# drop tablespace hxltps;
DROP TABLESPACE

这个时候旧的链接也删除了
[postgres@host134 pg_tblspc]$ ls -al
total 4
drwx------ 2 postgres postgres 19 Oct 26 16:49 .
drwx------ 19 postgres postgres 4096 Oct 26 10:25 ..
lrwxrwxrwx 1 postgres postgres 17 Oct 26 16:42 40973 -> /opt/pg13/mytps01

标签:opt,26,postgresql,postgres,pg13,pg,空间,迁移,Oct
From: https://www.cnblogs.com/hxlasky/p/16829259.html

相关文章

  • pg_basebackup备份恢复(带自定义表空间)
    环境:OS:Centos7DB:13.8#####################################创建自定义表空间##############################1.创建表空间自定义目录su-postgresmkdir-p/opt/pg1......
  • 转 python 自动监控表空间,并自动添加数据文件
    侯志清-江西南昌 python自动监控表空间,并自动添加数据文件#!/usr/bin/pythonimportosimporttimeimportlinecache#定义记录日志文件defrlog(log)......
  • Docker 数据迁移到数据盘
     systemctlstopdocker  找到新的、空间较达的磁盘路径,然后创建任意目录。例如:mkdir/data/docker mv/var/lib/docker /data/docker  #如果数据非常重要,建议......
  • Windows 环境搭建 PostgreSQL 逻辑复制高可用架构数据库服务
    本文主要介绍Windows环境下搭建PostgreSQL的主从逻辑复制,关于PostgreSQl的相关运维文章,网络上大多都是Linux环境下的操作,鲜有在Windows环境下配置的教程,所以本文......
  • 线性空间
    高斯消元以前只会贺板子,理解了但不深刻,很快就忘了,现在再看高斯消元,也没有很难理解的。我们首先第一步枚举要消的元是哪个,然后将其系数置为\(1\),再将剩余方程中这个元的......
  • Tower Defense (分块+差分的差分+优化空间方法, 主席树做法待补)
    题目大意:   思路:这题难点在于每一秒会恢复值而且(mi+ri,ci)有一个阈值. 发现一个点被清理后,他的恢复有3个状态,一次恢复ri的值,当t<ci/ri,恢复ci%ri......
  • k8s将节点容器运行时从Docker迁移到Containerd
    1.执行drain操作kubectldraink8s-node01--ignore-daemonsets#2.对应节点上关闭docker#注意,是要迁移的节点systemctlstopkubeletsystemctlstopdocker.soc......
  • 线性空间
    参考资料:《线性代数》第三章https://www.acwing.com/video/2274/《进阶指南》定义称\((a_1,a_2,...,a_k)\)为\(k\)维向量\(\bold{a}\),其中\(a_i\in\R\)称......
  • 快速启动postgresql
    文档说明:只记录关键地方;试验环境:linuxdebian11postgresqlcontainerversion:"3"services:postgresql-server:image:postgres:15-alpinec......
  • java空间(Java堆空间)
    2017年Java开发有什么发展空间? 现在人们愈发相信,在今后的十年、二十年之内,Java都将是IT行业最炙手可热的技术,Java软件工程师将持续成为最热门的岗位之一,历史也不断的证明,JA......