Goal Do not cause a potential performance bottleneck by having a shared resource. By having a shared sequence it is not possible to change properties of sequences of different tables independently (for instance the owner column or step), i.e., it increases coupling between tables. By having a shared sequence it is impossible to specify the owner (table column) to the sequence generator.
Notes In case of the string_agg function, the line break (br) tag is used as a part of the separator for the better readability in case the query result is displayed in a web browser.
Type Problem detection (Each row in the result could represent a flaw in the design)
Reliability Medium (Medium number of false-positive results)
License MIT License
Fixing Suggestion Use for each table a separate sequence generator.
Data Source INFORMATION_SCHEMA only
SQL Query
WITH serial_columns AS (SELECT c.table_schema, t.table_type, c.table_name , c.column_name, coalesce(c.column_default, d.domain_default) AS column_default
FROM information_schema.columns c LEFT JOIN information_schema.domains d USING (domain_schema, domain_name)
INNER JOIN information_schema.schemata s ON c.table_schema=s.schema_name
INNER JOIN information_schema.tables t USING (table_schema, table_name)
WHERE coalesce (c.column_default, d.domain_default) LIKE 'nextval%'
AND (c.table_schema = 'public'
OR s.schema_owner<>'postgres')),
sequences AS (SELECT sc.table_schema, sc.table_type, sc.table_name , sc.column_name, s.sequence_schema, s.sequence_name
FROM serial_columns AS sc, information_schema.sequences AS s
WHERE column_default ILIKE '%' || 'nextval(''' || s.sequence_name || '''::regclass)' || '%' OR
column_default='nextval(''' || s.sequence_schema || '.' || s.sequence_name || '''::regclass)')
SELECT sequence_schema, sequence_name, Count(*) AS number_of_uses, string_agg(table_type || ': ' || table_schema || '.' || table_name || '.' || column_name, ';
' ORDER BY table_schema, table_name) AS columns FROM sequences GROUP BY sequence_schema, sequence_name HAVING Count(*)>1 ORDER BY sequence_schema, sequence_name;
Collections

This query belongs to the following collections:

NameDescription
Find problems automaticallyQueries, that results point to problems in the database. Each query in the collection produces an initial assessment. However, a human reviewer has the final say as to whether there is a problem or not .
Categories

This query is classified under the following categories:

NameDescription
Comfortability of data managementQueries of this category provide information about the means that have been used to make the use or management of database more comfortable and thus, more efficient.
Default valueQueries of this catergory provide information about the use of default values.
PerformanceQueries of this category provide information about indexes in a database.
Sequence generatorsQueries of this category provide information about sequence generators and their usage.