Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»Databases»PostgreSQL»How to Find PostgreSQL Database Size

    How to Find PostgreSQL Database Size

    By RahulJuly 30, 20212 Mins Read

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

    Advertisement

    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

    Related Posts

    How to Install Postgres on MacOS

    How To Install PostgreSQL on MacOS

    How to Allow Remote Connections in Postgres

    How To Configure PostgreSQL to Allow Remote Connections

    Check the PostgreSQL Version

    How to Check the PostgreSQL Version

    View 1 Comment

    1 Comment

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

      Good Work.Please keep it up.

      Reply

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • Implementing a Linux Server Security Audit: Best Practices and Tools
    • cp Command in Linux (Copy Files Like a Pro)
    • 15 Practical Examples of dd Command in Linux
    • dd Command in Linux (Syntax, Options and Use Cases)
    • Iptables: Common Firewall Rules and Commands
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

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