This page is read only. You can view the source, but not change it. Ask your administrator if you think this is wrong. ===== Postgresql ===== ==== Basics ==== * List databases: <code> \l </code> * Connect to database: <code> \c database </code> * Show tables: <code> \dt </code> ==== Show size of databases ==== <code> #!/bin/bash echo 'Database,Size (MB)' > /root/database_sizes.csv for database in $(sudo -u postgres psql -c 'SELECT datname FROM pg_database;'|grep -v '\---'|grep -v rows|grep -v datname); do #sudo -u postgres psql -c "SELECT pg_size_pretty( pg_database_size('$i') );" |grep -v '\---'|grep -v row|grep -v pg_size size=$(sudo -u postgres psql -c "SELECT pg_database_size('$database')/1024/1024 ;" |grep -v '\---'|grep -v row|grep -v column|sed 's/[[:blank:]]//g') echo $database echo $size echo "$database,$size" >> /root/database_sizes.csv done </code>