Created
April 2, 2024 08:38
-
-
Save CHERTS/f97306041c2ed3e993045849d6557ef3 to your computer and use it in GitHub Desktop.
PostgreSQL run analyze all table (using pl/pgsql script)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DO $$ | |
DECLARE | |
tab RECORD; | |
schemaName VARCHAR := 'public'; | |
BEGIN | |
for tab in (SELECT t.relname::varchar AS table_name | |
FROM pg_class t | |
JOIN pg_namespace n ON n.oid = t.relnamespace | |
WHERE t.relkind = 'r' and n.nspname::varchar = schemaName | |
ORDER BY 1) | |
LOOP | |
RAISE NOTICE 'ANALYZE %.%', schemaName, tab.table_name; | |
EXECUTE format('ANALYZE %I.%I', schemaName, tab.table_name); | |
end loop; | |
end | |
$$; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment