Postgres command basics
search cancel

Postgres command basics

book

Article ID: 286187

calendar_today

Updated On:

Products

Carbon Black EDR

Issue/Introduction

Helpful tips on how to utilize Postgres basics when troubleshooting an EDR server

Environment

  • Carbon Black EDR Server: Supported Versions

Resolution

  1. Logging into Postgres Command Line
    psql -p 5002 cb
  2. Output via Terminal
    psql -p 5002 cb -c "<command>"
CommandUse
\dtList of Available Tables
\dt+List of Available Tables and Sizes
\d <tablename>

Columns, Types (ints, timestamp, etc), Nullable and Default entries. Also includes Indexes, References and Triggers

\xPretty output. Makes the output much easier to read
\qQuit out of the Postgres Command Line
\copyCopy table information to csv format. \copy <table> TO 'path_and_filename.csv' WITH CSV HEADER"
\lLists Databases
\dfLists Functions
\diLists Indexes
\dnLists Schema's
\dvLists Views
\duLists Users
 
Advanced CommandsUse
select * from pg_indexes where tablename='<table>' and schemaname='public';Outputs Table Index Definition
select * from pg_size_pretty(pg_total_relation_size('<table'));Outputs true table size
select * from pg_size_pretty(pg_database_size('cb'));Outputs full Postgres database size

Additional Information