CB Response: How to save a table from Postgres as CSV
search cancel

CB Response: How to save a table from Postgres as CSV

book

Article ID: 290601

calendar_today

Updated On:

Products

Carbon Black EDR (formerly Cb Response)

Issue/Introduction

Export a Postgres table to CSV 

Environment

  • CB Response Server: All Versions

Resolution

  1. Open a connection to the Response back-end as root or a user with sudo rights
  2. Export the table to CSV, substitute table_name with the name of the table to be exported
    • sudo psql cb -p 5002 -c "\copy table_name to 'table_name.csv' with CSV HEADER"

       

Additional Information

  • File will be saved in current working directory unless the path is specified in the name section
  • A list of tables can be shown using the \dt command
    • sudo psql cb -p 5002 -c '\dt'
  • Using 'with CSV HEADER' will include the column names in the export
  • Specific fields can be specified in the command by substituting the table name with a select query
    • sudo psql cb -p 5002 -c "\copy (select field1, field2 from table_name) to 'table_name.csv' with CSV HEADER"