Next, we conjugated them with pg_database_size() and AS SIZE to get the size of all databases. In this example, we utilized the pg_database.datname, with the SELECT query to fetch/collect all the databases available in the server. Pg_database_size(pg_database.datname) AS size Let’s execute the below statement to find the size of all the databases: SELECT pg_database.datname, This is how the pg_size_pretty() function assists us in formatting the database size.Įxample #3: How to Fetch the Size of All Databases in Postgres? Let’s use the pg_size_pretty() function to convert the resultant database size into human-readable format: SELECT pg_size_pretty(pg_database_size('example')) The database size in the above-given example is not easily readable. The output shows that the pg_database_size() function successfully returned the size of the selected database.Įxample #2: How to Use the pg_size_pretty() Function With the pg_database_size() Function? Let’s execute the below-given command to see the total size of the selected database: SELECT pg_database_size('example') We already have a database named “example”. The syntax of the pg_database_size() function will be as follows: pg_database_size('database_name') Įxample #1: How to Use the pg_database_size() function in PostgreSQL? Use the pg_database_size() function to get the Database size. How to Find the Database Size Using pg_database_size? This post will present a thorough understanding of pg_database_size(), pg_relation_size(), and pg_size_pretty() functions with examples. The pg_size_pretty() function can be used with the collaboration of the pg_database_size(), pg_relation_size() to present the database/table size in a human-readable format. In PostgreSQL, built-in functions like pg_database_size(), and pg_relation_size() are used to get the database and table size respectively.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |