Skip to content

Instantly share code, notes, and snippets.

@johanek
Last active August 28, 2017 10:59
Show Gist options
  • Save johanek/6447285 to your computer and use it in GitHub Desktop.
Save johanek/6447285 to your computer and use it in GitHub Desktop.
Useful postgres commands
Example of getting size of fields:
SELECT id, length(raw), length(cooked) FROM posts ORDER BY length(cooked) DESC limit 100;
Truncate table:
truncate table <table>;
Show size of tables:
\dt+
Terminate all connections to a DB:
SELECT pg_terminate_backend(pg_stat_activity.pid)
FROM pg_stat_activity
WHERE pg_stat_activity.datname = 'TARGET_DB';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment