Dav*_*ave 3 postgresql disk-space temporary-tables
我在 Ubuntu 14.04 上使用 Postgres 9.5.4。我的 Postgres 数据位于单独的磁盘分区上,该分区已满。
myuser@myproject:~$ df -h /mnt/volume-nyc1-01/
Filesystem Size Used Avail Use% Mounted on
/dev/sda 99G 93G 413M 100% /mnt/volume-nyc1-01
Run Code Online (Sandbox Code Playgroud)
我想从分区中删除一些数据,但这变得很有挑战性。特别是,当我运行一些查询时,我得到这样的结果
myproject_production=> select count(*) FROM my_object_times rt1, my_object_times rt2 where rt1.my_object_id = rt2.my_object_id and rt1.name = rt2.name and rt1.time_in_ms = rt2.time_in_ms and rt1.id > rt2.id;;
ERROR: could not write block 52782 of temporary file: No space left on device
Run Code Online (Sandbox Code Playgroud)
我想释放一些临时空间,以便我可以运行查询并确定需要删除哪些数据。我的另一个分区上还有一些其他可用空间。如何将 pgsql_tmp 变量指向那里,以便我可以运行我需要的查询?
编辑:
由于符号链接选项似乎是侵入性最小的,所以我尝试了一下,设置如下
myuser@myproject:~$ sudo ls -al /mnt/volume-nyc1-01/postgresql/9.5/main/base/pgsql_tmp
lrwxrwxrwx 1 root root 14 Apr 10 18:01 /mnt/volume-nyc1-01/postgresql/9.5/main/base/pgsql_tmp -> /opt/pgsql_tmp
myuser@myproject:~$ cd /opt
myuser@myproject:/opt$ df -h /
Filesystem Size Used Avail Use% Mounted on
/dev/disk/by-uuid/050e1e34-39e6-4072-a03e-ae0bf90ba13a 40G 24G 15G 62% /
Run Code Online (Sandbox Code Playgroud)
您可以看到我指向的分区上有超过 16GB 的可用空间,但我仍然收到错误
ERROR: could not write block 1862514 of temporary file: No space left on device
Run Code Online (Sandbox Code Playgroud)
小智 6
temp_tablespaces(字符串)
当 CREATE 命令未显式指定表空间时,此变量指定要在其中创建临时对象(临时表和临时表上的索引)的表空间。在这些表空间中还会创建用于对大型数据集进行排序等目的的临时文件。
为了能够使用它,您需要在该卷上创建一个表空间,在那里创建一个目录(由用户拥有postgres!),然后运行以下命令:
create tablespace temp_space LOCATION 'mnt/volume-nyc1-01/pg_temp';
Run Code Online (Sandbox Code Playgroud)
您需要授予该表空间必要的权限:
grant create on tablespace temp_space to public;
Run Code Online (Sandbox Code Playgroud)
之后你可以使用
alter system set temp_tablespaces=temp_space;
Run Code Online (Sandbox Code Playgroud)
(或者你可以在你的会话中改变它)
请注意,要使其alter system生效,您需要重新加载配置:
select pg_reload_conf();
Run Code Online (Sandbox Code Playgroud)
或者,只需将 更改$PGDATA/base/pgsql_tmp为指向其他分区上的目录的符号链接。
| 归档时间: |
|
| 查看次数: |
18751 次 |
| 最近记录: |