Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1s1yI1-00GQNS-7m for pgsql-hackers@arkaria.postgresql.org; Wed, 01 May 2024 00:57:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1s1yHy-009e6R-0X for pgsql-hackers@arkaria.postgresql.org; Wed, 01 May 2024 00:57:38 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1s1yHx-009e6J-Md for pgsql-hackers@lists.postgresql.org; Wed, 01 May 2024 00:57:38 +0000 Received: from mail-il1-x136.google.com ([2607:f8b0:4864:20::136]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1s1yHt-000r2h-PX for pgsql-hackers@postgresql.org; Wed, 01 May 2024 00:57:37 +0000 Received: by mail-il1-x136.google.com with SMTP id e9e14a558f8ab-36c5fa79a6eso3825775ab.1 for ; Tue, 30 Apr 2024 17:57:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714525053; x=1715129853; darn=postgresql.org; h=content-disposition:mime-version:message-id:subject:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=hUUYB1FZLFFR2PAjP4Frz5zOYIebLylriUYqzkIRvnw=; b=l0WxBhBMS27ugMpLAOePl5rGVu+ja5fM6Q5znAB7GBAk7spGmpcZMktgIHz5uj2N1K S7L+WJUenwg4dijrEzQS0x11LvPRs0EYO1QJF1+25ATigfeKjyKKT73+SeGJtS9Q/Mir VfCmBl8G4+Gw5KCmsuIsGA6FUddz7CmHyOyUjbZGvYVAQCr5zLKhgzdmBKy2we6hM25A CKTpICOu+kkHjQFHpJMnNFKGpg2IjuXjkMdmYFDrFYSa674ju3hU8cqHFp91lrrU8pRa tnSkyvFSvnfQW0EYKEZSHSuYXdiyv2+vikAtt4S4xmM6N07yVl6VSHzxyMjf1TF+/IXm jPxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714525053; x=1715129853; h=content-disposition:mime-version:message-id:subject:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=hUUYB1FZLFFR2PAjP4Frz5zOYIebLylriUYqzkIRvnw=; b=AiCw7XvB5E4TA3swcRaMgKSiIW1DiABCoC7+tC7kk6xsxcL6YFK9OR7tSzgMS2NuKG LVpfs6MUfFPteIUBAw5KnO6YdrkfXVRqZrW+18UTKJw+p2Iu0hEoYP96/MdD/ScFVGGn IJoHEHZITEDW0i3Wx+de9qTJkU0/+YajxijqBsCfrn6GWWDsvi0oCNDXp6Kc21lbqd+H CJwJILrPhO6i9KBTwXKanp60ptkc6Jss0srYYSCPzVYqdMYtLzyX8QV8sGCNp65TIrHp ehieCVlFcIdCUOA4oXtg4L2NIBk3myhwSb4LEZq3h7zA5yirvz5awpbJNC6YOJDRvRdd t0fg== X-Gm-Message-State: AOJu0YwFuLF1Cv7/nl02WOcB1O20NYu4r8ALuAsRTFOBSF+/SFtCc2J0 UeN2LQ894KLgJiFz4dcr1Nq7DUOYxg8JD2GUAgjlkmwO9tYz2pki33hAhA== X-Google-Smtp-Source: AGHT+IHpiVRM3Nyf3BbOD1AVrYYiNlIK782orxhu6sXyS2/SmsyguajlDjrREPRmAXvasYdmbiLgqg== X-Received: by 2002:a05:6e02:17c9:b0:36c:3249:bfe8 with SMTP id z9-20020a056e0217c900b0036c3249bfe8mr1487147ilu.32.1714525052831; Tue, 30 Apr 2024 17:57:32 -0700 (PDT) Received: from nathanxps13 (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id t9-20020a92d149000000b00369ed8bb1ffsm5964495ilg.7.2024.04.30.17.57.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 17:57:32 -0700 (PDT) Date: Tue, 30 Apr 2024 19:57:30 -0500 From: Nathan Bossart To: pgsql-hackers@postgresql.org Subject: pg_sequence_last_value() for unlogged sequences on standbys Message-ID: <20240501005730.GA594666@nathanxps13> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk If you create an unlogged sequence on a primary, pg_sequence_last_value() for that sequence on a standby will error like so: postgres=# select pg_sequence_last_value('test'::regclass); ERROR: could not open file "base/5/16388": No such file or directory This function is used by the pg_sequences system view, which fails with the same error on standbys. The two options I see are: * Return a better ERROR and adjust pg_sequences to avoid calling this function for unlogged sequences on standbys. * Return NULL from pg_sequence_last_value() if called for an unlogged sequence on a standby. As pointed out a few years ago [0], this function is undocumented, so there's no stated contract to uphold. I lean towards just returning NULL because that's what we'll have to put in the relevant pg_sequences field anyway, but I can see an argument for fixing the ERROR to align with what you see when you try to access unlogged relations on a standby (i.e., "cannot access temporary or unlogged relations during recovery"). Thoughts? [0] https://postgr.es/m/CAAaqYe8JL8Et2DoO0RRjGaMvy7-C6eDH-2wHXK-gp3dOssvBkQ%40mail.gmail.com -- Nathan Bossart Amazon Web Services: https://aws.amazon.com