Skip to content

Chore/int to bigint investigations #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions administration/int-bigint-investigations/explore_amount_free.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- Credit: https://www.reddit.com/r/PostgreSQL/comments/xq7334/comment/iq8ln9o/
SELECT
sequencename,
max_value,
last_value,
(max_value - last_value) AS remaining,
((max_value - last_value) * 100.0 / max_value) AS pct_free
FROM
pg_sequences
ORDER BY
pct_free ASC;
24 changes: 24 additions & 0 deletions administration/int-bigint-investigations/explore_int_pk_tables.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

-- pg_constraint docs
-- https://www.postgresql.org/docs/current/catalog-pg-constraint.html
-- contype char
-- c = check constraint, f = foreign key constraint, n = not-null constraint (domains only), p = primary key constraint, u = unique constraint, t = constraint trigger, x = exclusion constraint

SELECT
n.nspname AS table_schema,
c.relname AS table_name,
a.attname AS column_name,
pg_catalog.format_type(a.atttypid, a.atttypmod) AS data_type,
c.reltuples::numeric AS estimate
FROM
pg_catalog.pg_constraint con
JOIN pg_catalog.pg_class c ON con.conrelid = c.oid
JOIN pg_catalog.pg_namespace n ON c.relnamespace = n.oid
JOIN pg_catalog.pg_attribute a ON a.attnum = ANY (con.conkey)
AND a.attrelid = c.oid
WHERE
con.contype = 'p' -- Primary key constraint
AND n.nspname NOT IN ('pg_catalog', 'information_schema') -- Exclude system schemas
AND pg_catalog.format_type(a.atttypid, a.atttypmod) = 'integer'::text
ORDER BY
5 DESC;