This kind of behavior will occur if all of the below settings matches:
1. User set the GUC on the database level:
# alter database postgres set optimizer to off;
2 the default DB was set to the database in #1
# export PGDATABASE=postgres;
To confirm that, we can run either one of the below commands:
postgres=# \drds
List of settings
Role | Database | Settings
------+----------+---------------
| postgres | optimizer=off
(1 row)
-- or below query which do the same thing as above one:
SELECT rolname AS "Role", datname AS "Database",
pg_catalog.array_to_string(setconfig, E'\n') AS "Settings"
FROM pg_catalog.pg_db_role_setting s
LEFT JOIN pg_catalog.pg_database d ON d.oid = setdatabase
LEFT JOIN pg_catalog.pg_roles r ON r.oid = setrole
ORDER BY 1, 2;
Role | Database | Settings
------+----------+---------------
| postgres | optimizer=off
(1 row)
To fix this, we can reset the GUC on the database level:
# alter database <DB> reset <GUC>;
-- for example:
# alter database postgres reset optimizer;
# gpconfig -s optimizer;
Values on all segments are consistent
GUC : optimizer
Master value: on
Segment value: on