This file contains hidden or 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
WITH inactive_connections AS ( | |
SELECT | |
pid, | |
rank() over (partition by client_addr order by backend_start ASC) as rank | |
FROM | |
pg_stat_activity | |
WHERE | |
-- Exclude the thread owned connection (ie no auto-kill) | |
pid <> pg_backend_pid( ) | |
AND |
This file contains hidden or 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
SELECT | |
relname AS "relation", | |
pg_size_pretty ( | |
pg_total_relation_size (C .oid) | |
) AS "total_size" | |
FROM | |
pg_class C | |
LEFT JOIN pg_namespace N ON (N.oid = C .relnamespace) | |
WHERE | |
nspname NOT IN ( |
This file contains hidden or 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
SELECT pg_database.datname as "database_name", pg_size_pretty(pg_database_size(pg_database.datname)) AS size_in_mb FROM pg_database ORDER by size_in_mb DESC; |
This file contains hidden or 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
SELECT table_name AS "Table", | |
ROUND(((data_length + index_length) / 1024 / 1024), 2) AS "Size (MB)" | |
FROM information_schema.TABLES | |
WHERE table_schema = "database_name" | |
ORDER BY (data_length + index_length) DESC; |
This file contains hidden or 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
SELECT table_schema AS "Database", | |
ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS "Size (MB)" | |
FROM information_schema.TABLES | |
GROUP BY table_schema; |
This file contains hidden or 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
ALTER DATABASE `<DB NAME>` CHARACTER SET = utf8mb4 COLLATE utf8mb4_unicode_ci; | |
SET foreign_key_checks = 0; | |
ALTER TABLE `<TABLE NAME>` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; | |
ALTER TABLE `<TABLE NAME>` CHANGE <COLUMN NAME> <COLUMN NAME> LONGTEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL; | |
SET foreign_key_checks = 1; |
This file contains hidden or 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
print boto3.client("sts").get_caller_identity()["Account"] |