To export table data as JSON files make sure psql
is installed. It can be found here.
Afterwards, connect to the database e.g. psql -h <ip> -U <db-user> -d <db-name>
and enter the password for the selected user.
Useful psql commands:
\l
- list all available databases\c
- switch to a database\d
- list all tables in the database
Use the following commands to export table data as JSON to a file:
\t
- turn on tuples mode\a
- unalign output format\o <filename>
- output file nameSELECT array_to_json(array_agg(row_to_json(u))) FROM <dbname> u;
- SQL function to export as JSON to the output file