Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    Home»Databases»PostgreSQL»How to Find PostgreSQL Database Size

    How to Find PostgreSQL Database Size

    RahulBy RahulJanuary 20, 20152 Mins ReadUpdated:July 30, 2021

    This tutorial will help you to determine database size and table size in the PostgreSQL server.

    First login to your server using the command line and connect to the PostgreSQL server. Now you can use the following commands to determine the sizes of databases and tables in PostgreSQL.

    1. Check PostgreSQL Database Size (Query)

    Use the following commands to determine PostgreSQL database size using a query. First, open a shell and connect to the Postgres terminal.

    sudo -u postgres psql 
    

    Then use inbuild function pg_database_size() to find database size in PostgreSQL server.

    postgres=# SELECT pg_database_size('mydb');
    

    Check PostgreSQL Database Size

    You can also use pg_size_pretty() function along with above to determine database size in human readable format like KB, MB, and GB etc.

    postgres=# SELECT pg_size_pretty(pg_database_size('mydb'));
    

    Check Postgres Database Size in MB, GB

    2. Check PostgreSQL Database Size with pgAdmin

    The pgAdmin users can also determine the size from the interface.

    First login to the pgAdmin3 interface. Select your database and open statics tab. Here you can find the Size of your database as shown in below image:

    pgAdmin calculate postgres database size

    3. How to Find Table Size in PostgreSQL

    Connect to the target database first with the following command:

    postgres=# \c mydb;
    

    Now calculate the table size in Postgres server using pg_total_relation_size() inbuilt function with human readable format.

    mydb=# SELECT pg_size_pretty(pg_total_relation_size('employee'));
    

    Calculate table size in postgresql

    Concusion

    This tutorial helps you to find database size in the PostgreSQL server. Also, provide you details to calculate table size in a database.

    postgres PostgreSQL psql
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp
    Previous ArticleHow To List Databases and Tables in PostgreSQL
    Next Article bash scp: command not found

    Related Posts

    How To Configure PostgreSQL to Allow Remote Connections

    3 Mins Read

    How to Check the PostgreSQL Version

    Updated:August 6, 20212 Mins Read

    How to Install pgAdmin4 on Ubuntu 20.04

    Updated:April 9, 20214 Mins Read

    How to Install PostgreSQL and pgAdmin4 in Ubuntu 20.04

    Updated:July 1, 20215 Mins Read

    How To Install PostgreSQL Server on CentOS 8

    Updated:April 20, 20224 Mins Read

    How to Install PostgreSQL 11 on Debian 10 (Buster)

    Updated:July 25, 20192 Mins Read

    1 Comment

    1. techguy on May 26, 2021 10:25 am

      Good Work.Please keep it up.

      Reply

    Leave A Reply Cancel Reply

    Recent Posts
    • How to Install JAVA on Ubuntu 22.04
    • Switching Display Manager in Ubuntu – GDM, LightDM & SDDM
    • Changing the Login Screen Background in Ubuntu 22.04 & 20.04
    • How To Install PHP (8.1, 7.4 or 5.6) on Ubuntu 22.04
    • (Resolved) Please install all available updates for your release before upgrading
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.