# Copyright (c) 2026, PostgreSQL Global Development Group

# Test that unlogged sequences created on a primary can be read after
# promotion of a standby that replayed their init fork.

use strict;
use warnings FATAL => 'all';
use PostgreSQL::Test::Cluster;
use PostgreSQL::Test::Utils;
use Test::More;

my $node_primary = PostgreSQL::Test::Cluster->new('primary');
$node_primary->init(allows_streaming => 1);
$node_primary->start;

my $backup_name = 'my_backup';
$node_primary->backup($backup_name);

my $node_standby = PostgreSQL::Test::Cluster->new('standby');
$node_standby->init_from_backup($node_primary, $backup_name,
	has_streaming => 1);
$node_standby->start;

# Create the unlogged sequence after the standby has started, so its init fork
# is generated by WAL replay on the standby.
$node_primary->safe_psql('postgres', "CREATE UNLOGGED SEQUENCE ulseq");
$node_primary->wait_for_replay_catchup($node_standby);

$node_standby->promote;

is($node_standby->safe_psql('postgres', "SELECT nextval('ulseq')"),
	1, 'unlogged sequence can be read after standby promotion');

done_testing();
