postgre.rst
changeset 1710 601c31753686
parent 1709 f34c6bc973cb
child 1711 379096db1a5b
equal deleted inserted replaced
1709:f34c6bc973cb 1710:601c31753686
    68 ===================
    68 ===================
    69 ::
    69 ::
    70 
    70 
    71   set search_path to NAME;
    71   set search_path to NAME;
    72 
    72 
       
    73 Database, table, index size.
       
    74 ============================
       
    75 
       
    76 Database size::
       
    77 
       
    78   SELECT pg_database_size('geekdb');  -- in bytes
       
    79   SELECT pg_size_pretty(pg_database_size('dbname'));
       
    80 
       
    81 List of databases sizes::
       
    82 
       
    83   \l+
       
    84 
       
    85 Table total size (with indexes)::
       
    86 
       
    87   SELECT pg_size_pretty(pg_total_relation_size('schemaname.tablename'));
       
    88 
       
    89 Sole table size (without indexes and other)::
       
    90 
       
    91   SELECT pg_size_pretty(pg_relation_size('schemaname.tablename'));
       
    92 
       
    93 Largest table in the PostgreSQL database::
       
    94 
       
    95   SELECT relname, relpages FROM pg_class ORDER BY relpages DESC;
       
    96 
    73 Using psql client.
    97 Using psql client.
    74 ==================
    98 ==================
    75 
    99 
    76 Using password file ``~/.pgpass``::
   100 Using password file ``~/.pgpass``::
    77 
   101 
    82 
   106 
    83 Connect by::
   107 Connect by::
    84 
   108 
    85   $ psql -U $USER -h $HOST  $SCHEMA
   109   $ psql -U $USER -h $HOST  $SCHEMA
    86 
   110 
       
   111 How to view execution plan::
       
   112 
       
   113   EXPLAIN query;
       
   114   EXPLAIN ANALYZE query;
       
   115 
       
   116 How to redirect the output of query to a file::
       
   117 
       
   118   \o output_file
       
   119   SELECT * FROM pg_class;
       
   120