Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What determines the sort order for list of table details in pgmetrics output? #36

Closed
csatnic-av opened this issue Oct 8, 2020 · 2 comments

Comments

@csatnic-av
Copy link

Version used: pgmetrics_1.9.2_linux_amd64
Command line parameters: pgmetrics -h HOST -U USER -w DB

I'm executing pgmetrics against two separate environments that run the same database with the same schema. I wanted to see a side-by-side comparison of the results. The bulk of the pgmetrics output is the detailed information listed about the tables in the database being inspected but the sort order for the tables varies wildly between the two environments.

What determines the sort order of the tables when pgmetrics exports that data? Can that sort order be controlled via any parameter so I can get both environments to list table details in the same order? I was not able to find any parameters that might control that.

Thank you.

@mdevan
Copy link
Contributor

mdevan commented Oct 9, 2020

They're sorted by OID, which can vary between databases.

If you only want to compare tables, you can do this though:

# get pgmetrics output into "db.json"
pgmetrics -fjson -h HOST -U USER -w DB -odb.json

# extract list of tables
jq '.tables' db.json > tables.json

# extract list of tables, sorted by "name" field
jq '.tables' db.json | jq 'sort_by(.name)' > tables.json

# extract list of tables, sorted by schema_name, then name
jq '.tables' db.json | jq 'sort_by(.schema_name + .name)' > tables.json

jq is the jq utility that you should be able to install with apt/yum.

Does this help?

@csatnic-av
Copy link
Author

Yes ... thank you for the explanation and the workaround suggestion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants