integer out of range and remaining disk space too small to convert id to bigint等解决方法

integer out of range and remaining disk space too small to convert id to bigint and other solutions

当我 insert 我得到 integer out of range 因为我的 id/primary 密钥被错误地创建为 int 而不是 bigintbigserial.我试过了:

ALTER TABLE tbl ALTER COLUMN id TYPE BIGINT;

但是我收到以下错误,因为我的可用磁盘 space 不够大。

ERROR: could not extend file "base/16401/3275205": No space left on device HINT: Check free disk space. SQL state: 53100

我现在无法增加磁盘 space,由于令人沮丧的原因,我不会深入探讨。

我也尝试重新使用 ID(我从这个 table 中删除了很多记录,所以有很大的差距)通过这样做来开始我的 seqhttps://dba.stackexchange.com/questions/111823/compacting-a-sequence-in-postgresql

但是对于解决方案#1 link: 我假设我没有磁盘 space。 table 是 117GB,我在 ...data/base 中有大约 24GB 可用。我确实有 150GB 可用空间用于存储我的临时文件(不同的装载),这不是默认配置,但这样做是为了在 ...data/base 中节省 space 用于数据库存储。如果我可以在临时文件位置创建 table,那可能会起作用,但我不知道该怎么做。

对于解决方案 #2 link: 当我到达 update 部分时,我在 pgAdmin4:

中得到了这个
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>500 Internal Server Error</title>
<h1>Internal Server Error</h1>
<p>The server encountered an internal error and was unable to complete your request.  Either the server is overloaded or there is an error in the application.</p>

但是当我 运行:

时查询仍然是 运行ning

select pid,query,state,wait_event,* from pg_stat_activity where state <> 'idle'

我没有得到失败的 update 查询的服务器日志。

我最终杀死了那个更新查询,认为它无论如何最终都会失败。 (我再次 运行 宁此,并会让它 运行 上面 html 错误,除非其他人有更好的主意。)

对于解决方案 #3 link: 我有16GM的RAM,所以不够用。

下一个: How to reset sequence in postgres and fill id column with new data?

我试过这个:

UPDATE table SET id = DEFAULT;
ALTER SEQUENCE seq RESTART;
UPDATE table SET id = DEFAULT;

ERROR: integer out of range

这会在您尝试插入时创建一个重复键:

ALTER SEQUENCE seq RESTART WITH 1;
UPDATE t SET idcolumn=nextval('seq');

还有什么我可以尝试的吗?

PostgreSQL 9.6

Scott Marlowe 和 Vao Tsun 的评论有效:

在 (linux) 服务器上打开一个终端

导航到想要新名称space的位置

创建一个目录:mkdir dirname

将所有权授予 postgres:chown postgres:postgres dirname

创建 table: CREATE TABLESPACE new_tbl_space LOCATION '/path/dirname'

将 table 放入 tablespace: alter table tbl set tablespace '/path/dirname'

做占用这么多磁盘的东西space:ALTER TABLE tbl ALTER COLUMN id TYPE BIGINT;

将 tablespace 改回:alter table tbl set tablespace pg_default

删除 tablespace:我在 Tablespaces node/object

中的 pgadmin4 中执行了该操作

(那是凭记忆。如果我遗漏了什么,请告诉我。)

编辑:这具有重写整个 table 的副作用,就像完全真空释放任何死磁盘 space。