博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PostgreSQL和Greenplum的临时表空间介绍
阅读量:3522 次
发布时间:2019-05-20

本文共 5513 字,大约阅读时间需要 18 分钟。

PostgreSQL的临时表空间,通过参数temp_tablespaces 进行配置,PostgreSQL允许用户配置多个临时表空间。

配置多个临时表空间时,使用逗号隔开。

如果没有配置temp_tablespaces 参数,临时表空间对应的是默认的表空间。

PostgreSQL的临时表空间用来存储临时表或临时表的索引,以及执行SQL时可能产生的临时文件例如排序,聚合,哈希等。

为了提高性能,一般建议将临时表空间放在SSD或者IOPS,以及吞吐量较高的分区中。

例子:

当前未配置temp_tablespaces,使用默认表空间。

postgres=# \l+ postgres                                                                List of databases       Name   |  Owner   | Encoding | Collate | Ctype | Access privileges |  Size   | Tablespace |                Description                     ----------+----------+----------+---------+-------+-------------------+---------+------------+--------------------------------------------     postgres | postgres | UTF8     | C       | C     |                   | 7456 kB | pg_default | default administrative connection database    (1 row)        postgres=# show temp_tablespaces ;     temp_tablespaces     ------------------         (1 row)    postgres=# create temp table tmp1 (id int);    CREATE TABLE    postgres=# insert into tmp1 select generate_series(1,1000);    INSERT 0 1000

临时表放在默认表空间中。

postgres=# select pg_relation_filepath('tmp1');     pg_relation_filepath     ----------------------     base/13241/t2_73746    (1 row)

执行一个大的排序,临时文件放在默认表空间中。

postgres=# select * from generate_series(1,10000000000) order by 1;

查看临时文件目录

cd $PGDATA/base/pgsql_tmp    $ ll    -rw------- 1 digoal users 1.0G Mar 26 15:58 pgsql_tmp30315.0    -rw------- 1 digoal users 1.0G Mar 26 15:58 pgsql_tmp30315.1    ....

新建一个表空间,并将所有用户的temp_tablespaces参数设置为这个新建的表空间。

mkdir /disk1/digoal/tmptbs1    postgres=# create tablespace tmptbs location '/disk1/digoal/tmptbs';    CREATE TABLESPACE    postgres=# alter role all set temp_tablespaces='tmptbs';    ALTER ROLE

重新测试,现在临时文件都会放到新建的表空间下面。

psql    postgres=# select * from generate_series(1,10000000000) order by 1;        cd /disk1/digoal/tmptbs/PG_9.5_201510051/pgsql_tmp    total 528M    -rw------- 1 digoal users 513M Mar 26 16:05 pgsql_tmp31527.0        postgres=# create temp table t1(id int);    CREATE TABLE    postgres=# insert into t1 select generate_series(1,10000);    INSERT 0 10000    postgres=# select pg_relation_filepath('t1');                  pg_relation_filepath                   -------------------------------------------------     pg_tblspc/73749/PG_9.5_201510051/13241/t3_73750    (1 row)

下面是Greenplum的临时表空间,介绍:

关于的使用

Greenplum没有temp_tablespaces这个参数,那么临时文件应该放哪里呢?

Greenplum将只有filespace的说法,并且临时文件是全局管理的,也就是说整个GP集群的临时文件是放在一个地方(filespace)的。

在Greenplum中不同的用户不能使用不同的临时文件目录。

默认情况下临时文件是放在默认的表空间下面

临时文件(例如排序,哈希,产生的work file)

/
/
/pgsql_tmp

临时表

/
/
/
You can move temporary or transaction files to a specific filespace to improve database performance when    running queries, creating backups, and to store data more sequentially.        The dedicated filespace for temporary and transaction files is tracked in two separate flat files called    gp_temporary_files_filespace and gp_transaction_files_filespace.     These are located in the pg_system directory on each primary and mirror segment, and on master and standby.     You must be a superuser to move temporary or transaction files.     Only the gpfilespace utility can write to this file.        Unless otherwise specified, temporary and transaction files are stored together with all user data.     The default location of temporary files, 
/
/
/pgsql_tmp is changed when you use gpfilespace --movetempfiles for the first time. Also note the following information about temporary or transaction files: • You can dedicate only one filespace for temporary or transaction files, although you can use the same filespace to store other types of files. • You cannot drop a filespace if it used by temporary files. • You must create the filespace in advance.

如果要修改Greenplum临时文件的存放地,操作如下:

首先要创建filespace, 然后确保没有活跃会话,使用gpfilespace --movetempfilespace filespace_name命令迁移临时文件目录。

To move temporary files using gpfilespace      1. Check that the filespace exists and is different from the filespace used to store all other user data.    2. Issue smart shutdown to bring the Greenplum Database offline.       If any connections are still in progess, the gpfilespace --movetempfiles utility will fail.    3. Bring Greenplum Database online with no active session and run the following command:       gpfilespace --movetempfilespace filespace_name       The location of the temporary files is stored in the segment configuration shared memory       (PMModuleState) and used whenever temporary files are created, opened, or dropped.
To move transaction files using gpfilespace    1. Check that the filespace exists and is different from the filespace used to store all other user data.    2. Issue smart shutdown to bring the Greenplum Database offline.       If any connections are still in progess,the gpfilespace --movetransfiles utility will fail.    3. Bring Greenplum Database online with no active session and run the following command:       gpfilespace --movetransfilespace filespace_name       The location of the transaction files is stored in the segment configuration shared memory       (PMModuleState) and used whenever transaction files are created, opened, or dropped.        Creating a Tablespace      After you create a filespace, use the CREATE TABLESPACE command to define a tablespace that uses that      filespace.       For example:        =# CREATE TABLESPACE fastspace FILESPACE fastdisk;

转载地址:http://gthqj.baihongyu.com/

你可能感兴趣的文章
【STM32CubeMX+FreeRTOS 】29,prtinf卡死;4任务只运行了3个;W5500联网失败(堆栈不能太大或者太小)
查看>>
【STM32+FreeRTOS +W5500移植要点】30,RTOS中断;从TIM2,主TIM3;RTOS主要用在LCD中;RT-Thread;标志重定义问题 2019年01月22日
查看>>
【STM32+FPGA+FSMC】31,FSMC熟练掌握;KEIL5生成bin文件;SDRAM的使用;IAP检验码 2019年04月10日
查看>>
【IC1】【转 非常好】运算放大器使用的六个经验
查看>>
【IC-ADC 3】ADC的选型
查看>>
2019年03月18日 查看数据手册的注意点,极限参数、电气参数、推荐参数
查看>>
HiKey960/970用户手册;HiKey960 Development Board User Manual
查看>>
【IC8】作为一名硬件工程师,需要哪些知识?
查看>>
【书籍推荐】FPGA,xilinx
查看>>
N9-SQL注入(union注入)
查看>>
N10-sql注入(information_schema注入)
查看>>
N1-Kali虚拟机中SQLmap
查看>>
N11-sql注入(http头注入)
查看>>
N2-sqlmap初使用
查看>>
N12-sql盲注原理以及boolean盲注案例实现
查看>>
N13-sqli盲注 基于时间型
查看>>
N1 技术心得 2019-6-26
查看>>
N1-环境配置
查看>>
N2-审计方法与步骤
查看>>
N3-常见的INI配置
查看>>