Analyze on functional indexes cannot be interrupted very easily.
Example:
create language plperl;
create table foo1 as select x::text from generate_series(1,1000) foo (x);
create table foo2 as select reverse(x) from foo1;
--use a fast version to set up the demo, as we are impatient
CREATE or replace FUNCTION slow_reverse(text) RETURNS text
LANGUAGE plperl IMMUTABLE STRICT COST 1000000
AS $_X$
return reverse($_[0]);
$_X$;
create index on foo2 (slow_reverse(reverse));
analyze foo2;
--put the slow version in place.
CREATE or replace FUNCTION slow_reverse(text) RETURNS text
LANGUAGE plperl IMMUTABLE STRICT COST 1000000
AS $_X$
my $foo; foreach (1..1e6) {$foo+=sqrt($_)};
return reverse($_[0]);
$_X$;
-- now spring the trap
analyze foo2;
Ctrl-C (or pg_ctl stop -mf) hangs for a long time.
The attached patch fixes it, but don't vouch for its safety.
I believe I've seen a real-world example of this causing refusal of a fast shutdown to shutdown fast.
Cheers,
Jeff