本文信息基于PG13.1。
从PG9.6开始支持并行查询。PG11开始支持CREATE TABLE … AS、SELECT INTO以及CREATE MATERIALIZED VIEW的并行查询。
先说结论:
换用create table as 或者select into或者导入导出。
首先跟踪如下查询语句的执行计划:
select count(*) from test t1,test1 t2 where t1.id = t2.id ;

可以看到走了两个Workers。
下边看一下insert into select:

可以看到并没有Workers的指示,没有启用并行查询。
即使开启强制并行,也无法走并行查询。

原因在官方文档有写:
The query writes any data or locks any database rows. If a query contains a data-modifying operation either at the top level or within a CTE, no parallel plans for that query will be generated. As an exception, the commands CREATE TABLE … AS, SELECT INTO, and CREATE MATERIALIZED VIEW which create a new table and populate it can use a parallel plan.
解决方案有如下三种:
1.select into

2.create table as

3.或者通过导入导出的方式,例如:

一些场景下也会比非并行快。