Largest databases in PostgreSQL

In this tutorial, we will sort the databases by its size. Then, we will get top 5 largest databases of PostgreSQL server.

1. To get the databases in sorted order by its size(desc).

select datname, pg_size_pretty(pg_database_size(datname)) from pg_database order by pg_database_size(datname) desc;

Output:
datname | pg_size_pretty
————-+—————-
bank | 7056 kB
postgres | 7000 kB
emp | 6865 kB
account | 6865 kB
school | 6865 kB
company | 6865 kB
my_database | 6865 kB
template1 | 6865 kB
xyz | 6865 kB
template0 | 6865 kB
(10 rows)

2. To get top 5 largest databases of PostgreSQL server.

select datname, pg_size_pretty(pg_database_size(datname)) from pg_database order by pg_database_size(datname) desc limit 5;

Output:
datname | pg_size_pretty
———-+—————-
bank | 7056 kB
postgres | 7000 kB
emp | 6865 kB
account | 6865 kB
school | 6865 kB
(5 rows)

Related Posts

CheapSexCams
Responses are currently closed, but you can trackback from your own site.

Comments are closed.

Powered by k2schools
%d bloggers like this: