PgStatShared_HashEntry *ps;
    uint64      not_freed_count = 0;
 
-   dshash_seq_init(&hstat, pgStatLocal.shared_hash, false);
+   dshash_seq_init(&hstat, pgStatLocal.shared_hash, true);
    while ((ps = dshash_seq_next(&hstat)) != NULL)
    {
        if (ps->dropped)
 
 $node->start;
 
 # no stats present due to invalid stats file
-$sect = "invalid";
+$sect = "invalid_overwrite";
+is(have_stats('database', $dboid, 0), 'f', "$sect: db stats do not exist");
+is(have_stats('function', $dboid, $funcoid),
+   'f', "$sect: function stats do not exist");
+is(have_stats('relation', $dboid, $tableoid),
+   'f', "$sect: relation stats do not exist");
+
+
+## check invalid stats file starting with valid contents, but followed by
+## invalid content is handled.
+
+trigger_funcrel_stat();
+$node->stop;
+append_file($og_stats, "XYZ");
+$node->start;
+
+$sect = "invalid_append";
 is(have_stats('database', $dboid, 0), 'f', "$sect: db stats do not exist");
 is(have_stats('function', $dboid, $funcoid),
    'f', "$sect: function stats do not exist");
 {
    my ($filename, $str) = @_;
    open my $fh, ">", $filename
-     or die "could not write \"$filename\": $!";
+     or die "could not overwrite \"$filename\": $!";
+   print $fh $str;
+   close $fh;
+   return;
+}
+
+sub append_file
+{
+   my ($filename, $str) = @_;
+   open my $fh, ">>", $filename
+     or die "could not append to \"$filename\": $!";
    print $fh $str;
    close $fh;
    return;