Skip to main content
100%

List schema and tables from all databases in PostgreSQL cluster

✓ Published0🌍 Public
TThomasG77
Last edited Mar 26, 2023
Created on Mar 26, 2023

This example shows a two-step pipeline that first lists every database in a PostgreSQL cluster and then aggregates all user-defined schemas and tables from each database into a single CSV file. The first `psql` query retrieves database names, excluding `template0`, and writes them to `databases.txt`. A shell loop then runs a second `psql` query against each database, selecting `schemaname` and `tablename` while filtering out system schemas, and appends results with the database name to `all_tables.txt`. The code uses the PostgreSQL command-line client with `-t --csv` flags to output tab-separated CSV data.

AI-generated description

Similar vizzes