Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonathanalves/0d0856482511fef097b3ad17402dc410 to your computer and use it in GitHub Desktop.
Save jonathanalves/0d0856482511fef097b3ad17402dc410 to your computer and use it in GitHub Desktop.
Postgres list all constraints
-- http://tatiyants.com/pev/
EXPLAIN (COSTS OFF)
EXPLAIN (ANALYZE, COSTS, VERBOSE, BUFFERS, FORMAT JSON)
-- realizar a analise da query lenta
explain (analyze,buffers,timing) DELETE FROM indicador_pessoal_versao where id = 'c5df0553-612c-4a89-9d48-131890efff92'
-- https://www.cybertec-postgresql.com/en/avoid-or-for-better-performance/
--https://stackoverflow.com/questions/21968595/postgres-slow-query-slow-index-scan
-- CASO HAJA TRIGGER OU ALGUMA REFERENCIA LENTA, BASTA IDENTIFICAR À QUAL TABELA PERTENCE E CRIAR O INDICE
SELECT
tc.constraint_name, tc.table_name, kcu.column_name,
ccu.table_name AS foreign_table_name,
ccu.column_name AS foreign_column_name
FROM
information_schema.table_constraints AS tc
JOIN information_schema.key_column_usage AS kcu
ON tc.constraint_name = kcu.constraint_name
JOIN information_schema.constraint_column_usage AS ccu
ON ccu.constraint_name = tc.constraint_name
WHERE constraint_type = 'FOREIGN KEY' or tc.constraint_name = 'constraint_name'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment