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 1rcvqI-002yWJ-UQ for pgsql-sql@arkaria.postgresql.org; Wed, 21 Feb 2024 23:17:35 +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 1rcvqH-00756Z-CV for pgsql-sql@arkaria.postgresql.org; Wed, 21 Feb 2024 23:17:33 +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 1rcvqH-00756F-3H for pgsql-sql@lists.postgresql.org; Wed, 21 Feb 2024 23:17:33 +0000 Received: from mail-lj1-x22b.google.com ([2a00:1450:4864:20::22b]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rcvq9-000L3O-Pz for pgsql-sql@lists.postgresql.org; Wed, 21 Feb 2024 23:17:32 +0000 Received: by mail-lj1-x22b.google.com with SMTP id 38308e7fff4ca-2d22fa5c822so57979501fa.2 for ; Wed, 21 Feb 2024 15:17:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708557445; x=1709162245; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=DoS0LVftSRiN/umCI/4pZUey6zV2FtxW9DYibT4XXTo=; b=FV6hb6ugewbfBfymKqcfpVtq7eY9sJ5Zm+rGm1YzmvYxDlV4pu8D38H+HPZ5c92RQz 3dBvryeJ1mz2XH+fDXHVUPGaYonopXxlqBa+tt1vdrhuE8w6En9UtxWOQ6KWIIpAlNqU ASPWy6jz7SozkRVbfsh4MuBrtNWFGra0LVtuXvEXIWGd99OkCTQ3qqHI6wOBy+PJq2vU Ig2K/itOVrpjjfen4FaFOLFdGnvoez8OgkA/qYul2LrFTaQx/Pb7pq62R/qWCTu3aAFE G3RMCx+v0s2/jKFUNQ2AK7Nw26ouAXt5JYYNJCHy6NE2gcrxONZtJY6eSQO9luCRRxpT WNag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708557445; x=1709162245; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=DoS0LVftSRiN/umCI/4pZUey6zV2FtxW9DYibT4XXTo=; b=eNfBx9lRnj7/VzqL43cyKndfsRUWyTLzYADcsLjkHqo3UDgeC2BWdldS8EExOkj26G buRCc/hfcm7QjTaTYJ9llzjHKQCO8V6dhUzyzxb1LdON29UyK3NtOaOL5bVmty09SxZG 71bUUqdpE8Ad1G8GmY2WvW6qAyZzM1dk2UKRPLZOof207CrCUI4Defnai3KU3P/UkGGa vAwF1ve0hhj8nP3mXXApJQmOabeVoGfdmjK3DWRE28DCv7UaX8uY5OmcWBEPkpSlbBWo //A32Rqv9k9GX3QaScAna5KAKJJo9So1JGOapbrG1taehdGHJHgtE1mF04DyalS9oisQ oYmw== X-Forwarded-Encrypted: i=1; AJvYcCW182lcKc7NarUUrdOuPCpNZtk8RH4jSJyq9EUZxhH7AfmrsWzJlvUNl739OLBm6k3RQmzB+fmGNpNEyuIdDmDtr1KYfCiaTFbr7HF9N70= X-Gm-Message-State: AOJu0Yzczqza55SRBO/PEgLPBdiuw4lNN2oDBEX/oY+R4EBroJjrjMVh VJ/WNBRnHC8haqKfFxqXtfqx0H8aNWaBrPMCB5Am7bZ1sK8tqV4a72XeEAGE1lJTcYyO2BmveVZ pcGcLLReR0cQTqZ3FHHc8Hhy81Vw= X-Google-Smtp-Source: AGHT+IFfLve9FRzMGGtyFqdFMRNQk9mkAN20qKy4vZbiGvVm7pgB+YWqpqw3kkXg/mxCN8jS2e2BGmwLisaRH+/Jj8I= X-Received: by 2002:a2e:8092:0:b0:2d2:39d8:3596 with SMTP id i18-20020a2e8092000000b002d239d83596mr8024558ljg.16.1708557445053; Wed, 21 Feb 2024 15:17:25 -0800 (PST) MIME-Version: 1.0 References: <174178.1708553636@sss.pgh.pa.us> In-Reply-To: <174178.1708553636@sss.pgh.pa.us> From: Nisarg Patel Date: Wed, 21 Feb 2024 18:17:15 -0500 Message-ID: Subject: Re: How to find all current sequence IDs To: Tom Lane Cc: "Campbell, Lance" , pgsql-sql@lists.postgresql.org Content-Type: multipart/alternative; boundary="0000000000009742890611ec87fa" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000009742890611ec87fa Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable This has worked for me in the past: select schemaname, sequencename, last_value from pg_sequences; Thank you, Nisarg On Wed, Feb 21, 2024, 5:14=E2=80=AFPM Tom Lane wrote: > "Campbell, Lance" writes: > > Is there a way to get a list of all sequences, the schema it is used in= , > and the current sequence number in use? > > Try something like > > select relname, relnamespace::regnamespace, pg_sequence_last_value(oid) > from pg_class where relkind =3D 'S'; > > regards, tom lane > > > --0000000000009742890611ec87fa Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
This has worked for me in the past:
select schemaname, sequencename, last_value
f= rom pg_sequences;

Thank = you,
Nisarg

On Wed, Feb 21, 2024, 5:14=E2= =80=AFPM Tom Lane <tgl@sss.pgh.pa.u= s> wrote:
"Campbell, La= nce" <lance@illinois.edu> writes:
> Is there a way to get a list of all sequences, the schema it is used i= n, and the current sequence number in use?

Try something like

select relname, relnamespace::regnamespace, pg_sequence_last_value(oid)
from pg_class where relkind =3D 'S';

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 regards, tom lane


--0000000000009742890611ec87fa--