How to retrieve Postgresql Sequence-cache value from Postgresql Catalog tables?
NickName:Ravikumar S Ask DateTime:2013-08-07T00:07:34

How to retrieve Postgresql Sequence-cache value from Postgresql Catalog tables?

I have used this below query to get the complete information of Sequence objects from the Postgresql catalog table

select s.sequence_name, s.start_value, s.minimum_value, s.maximum_value, s.increment, s.cycle_option 
from information_schema.sequences s 
 where s.sequence_schema='schema1' 

One more attribute value am not able to get is "Cache" value.

Am using Postgresql 9.2

Here is the DDL syntax for the sequence with cache,

ALTER SEQUENCE [ IF EXISTS ] name [ INCREMENT [ BY ] increment ]

[ MINVALUE minvalue | NO MINVALUE ] [ MAXVALUE maxvalue | NO MAXVALUE ]

[ START [ WITH ] start ]

[ RESTART [ [ WITH ] restart ] ]

[ CACHE cache ] [ [ NO ] CYCLE ]

[ OWNED BY { table_name.column_name | NONE } ]

Is there any Postgres functions to get this Sequence cache value ?

Thanks,

Ravi

Copyright Notice:Content Author:「Ravikumar S」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/18085197/how-to-retrieve-postgresql-sequence-cache-value-from-postgresql-catalog-tables

Answers
Daniel Vérité 2013-08-06T17:07:39

With PostgreSQL 10 or newer, the cache size can be obtained from the system view pg_sequences or the system table pg_sequence:\nSELECT cache_size FROM pg_catalog.pg_sequences\n WHERE schemaname='public' and sequencename='s';\n\nor alternatively\nSELECT seqcache FROM pg_catalog.pg_sequence\n WHERE seqrelid = 'public.s'::regclass;\n\nOmit the schema qualification (public or more generally the name of the schema) in the 2nd query to use automatically search_path instead of a fixed schema.\nWith versions older than v10, you may query the sequence itself as if it was a table.\nFor example:\nCREATE SEQUENCE s CACHE 10;\nSELECT cache_value FROM s;\n\nResult:\n cache_value \n-------------\n 10\n\nOr\n\\x\nSELECT * FROM s;\n\nResult:\n\n-[ RECORD 1 ]-+--------------------\nsequence_name | s\nlast_value | 1\nstart_value | 1\nincrement_by | 1\nmax_value | 9223372036854775807\nmin_value | 1\ncache_value | 10\nlog_cnt | 0\nis_cycled | f\nis_called | f\n",


More about “How to retrieve Postgresql Sequence-cache value from Postgresql Catalog tables?” related questions

How to retrieve Postgresql Sequence-cache value from Postgresql Catalog tables?

I have used this below query to get the complete information of Sequence objects from the Postgresql catalog table select s.sequence_name, s.start_value, s.minimum_value, s.maximum_value, s.increm...

Show Detail

How to retrieve Index-Fillfactor from Postgresql Catalog tables?

Am trying to load Postgres attributes from its catalog tables. I have created a Postgres table and few set of indexes(unique index, clustered index). With the below query I could the Name of the i...

Show Detail

Retrieve tables name from several databases in Postgresql?

I have two databases new_site,old_site I'm connecting to the database server via Postgres user and have full permission and I connect to new_site db. I need to get tables names for old_site so I tr...

Show Detail

PostgreSQL Revoking Permissions from pg_catalog tables

Is there a way I can revoke permissions from a user to the catalog objects (i.e. information_schema) and PostgreSQL tables (i.e. pg_catalog)? I've tried several things and scoured the net. I'm not ...

Show Detail

Using GORM to retrieve tables names from Postgresql

Looking to retrieve table names from my postgresql database. Now, I know in Go you can use sql and the pq driver, but I'm using GORM for doing queries in my REST API. The table_name type in Postgr...

Show Detail

Postgresql How to update catalog statistics

how to update the catalog statistics in postgresql to check the query performance.I searched on google but I did not find anything on internet regarding update catalog statistics

Show Detail

postgresql - Retrieve partial index WHERE expression

How would I run a query (on PostgreSQL internal tables) to retrieve the conditional expression for the partial index (roles_user_group_role_idx below in this case). # \d roles ...

Show Detail

SQL access comments in postgreSQL

I have been trying to find a SQL approach to retrieve comments of my schemas and other database objects in PostgreSQL. I have seen the following questions in stackoverflow: How to retrieve the com...

Show Detail

pyflink JDBC Postgresql Catalog throwing errors for data type UUID , How to handle the uuid datatype in Flink Table API?

Apache Flink 1.11.0 Python Table API Catalog : postgresql Reading and writing data from postgresql Catalog tables which coantain UUID data type columns through Table API throwing UUID data type

Show Detail

Retrieve a progress of index creation process in PostgreSQL

Consider long-running query in PostgreSQL of index creation, smth like that: CREATE INDEX some_idx ON some_table USING btree (some_varchar_column COLLATE pg_catalog."default"); The

Show Detail