SELECT tbl.table_schema, tbl.table_name
FROM information_schema.tables tbl
WHERE table_type = 'BASE TABLE'
AND table_schema NOT IN ('pg_catalog', 'information_schema')
AND NOT EXISTS (
SELECT 1
FROM information_schema.key_column_usage kcu
WHERE kcu.table_name = tbl.table_name
AND kcu.table_schema = tbl.table_schema
)
WITH cles_abs AS (
SELECT tbl.table_schema, tbl.table_name
FROM information_schema.tables tbl
WHERE table_type = 'BASE TABLE'
AND table_schema NOT IN ('pg_catalog', 'information_schema')
AND NOT EXISTS (
SELECT 1
FROM information_schema.key_column_usage kcu
WHERE kcu.table_name = tbl.table_name
AND kcu.table_schema = tbl.table_schema
)
)
SELECT 'ALTER TABLE' || table_schema || '.' || table_name
|| ' ADD COLUMN id INT4 GENERATED ALWAYS AS IDENTITY PRIMARY KEY;'
FROM cles_abs
ORDER BY table_schema, table_name;
pg_dumpall | gzip -c > fichier_sauvegarde.sql.gz
pg_dumpall -p 5432 -s | psql -p 5433 2> erreurs.txt