PostgreSQL-临时表空间与配置表

虽然我给数据库创建了表空间,但是操作中仍遇到了些问题,需要创建临时表空间。

配置表

首先了解下 postgres 的配置表,手动修改各种配置。

打开即可看到各种配置,包括临时表空间。

临时表空间

1. postgres 有默认的临时表空间,可手动修改

2. postgres 的临时表空间用来存储临时表或者临时表的索引,而且某些sql语句也会产生临时文件,如排序、聚合等,也需要临时表空间

3. 即使设置了表空间,临时表和临时文件也不会自动存储到表空间,仍存储在默认的临时表空间

4. 修改临时表空间需要配置 temp_tablespaces 参数,postgres 允许设置多个临时表空间,使用逗号隔开

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

修改临时表空间首先要创建表空间  【方法就是单纯创建表空间的方法】

$ mkdir -p /data/pg_data/temp_tsp
$ chown -R postgres:postgres /data/pg_data/temp_tsp
postgres=# CREATE TABLESPACE temp01 LOCATION '/data/pg_data/temp_tsp';
CREATE TABLESPACE

设置临时表空间 -- 会话级生效

[root@localhost ~]# su postgres
bash-4.2$ psql
could not change directory to "/root"
psql (9.2.24)
Type "help" for help.

postgres=# set temp_tablespaces = 'zns_road';
SET

查看临时表空间

postgres=# show temp_tablespaces ;
 temp_tablespaces 
------------------
 zns_road
(1 row)

设置成功;

关闭会话后,重新查看

postgres=# show temp_tablespaces;
 temp_tablespaces 
------------------
 
(1 row)

不存在了。

修改配置文件 -- 永久生效

修改完毕后执行如下命令,修改才能生效。

pg_ctl reload

如果报错,尝试如下操作

bash-4.2$ ./pg_ctl -D /var/lib/pgsql/data reload
server signaled

详情请参考下面链接。

参考资料:

https://blog.csdn.net/pg_hgdb/article/details/78712694  使用pg_ctl启动数据库时报错

https://blog.csdn.net/jinshi366/article/details/80017541  pg_ctl: no database directory specified and environment variable PGDATA unset , centos 7 postgreSQL

https://blog.csdn.net/dracotianlong/article/details/7828515  pg_ctl -- 启动、停止、重启 PostgreSQL

猜你喜欢

转载自www.cnblogs.com/yanshw/p/11387939.html