-
Notifications
You must be signed in to change notification settings - Fork 248
Refine Inspect queries and add CSVQ support for rule parsing #3595
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
base: develop
Are you sure you want to change the base?
Conversation
80c020e
to
e266458
Compare
@@ -20,8 +20,7 @@ WITH table_opts AS ( | |||
table_opts | |||
) | |||
SELECT | |||
vacuum_settings.nspname AS schema, | |||
vacuum_settings.relname AS table, | |||
vacuum_settings.nspname || '.' || vacuum_settings.relname AS name, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vacuum_settings.nspname || '.' || vacuum_settings.relname AS name, | |
format("%I.%I", vacuum_settings.nspname, vacuum_settings.relname) AS name, |
Since .
is a legal character in schema, we should probably escape it to be unambiguous.
@@ -1,5 +1,5 @@ | |||
SELECT | |||
schemaname || '.' || relname AS table, | |||
schemaname || '.' || relname AS name, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
@@ -1,6 +1,5 @@ | |||
SELECT | |||
n.nspname AS schema, | |||
c.relname AS name, | |||
n.nspname || '.' || c.relname AS name, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
inspectTotalIndexSizeCmd = &cobra.Command{ | ||
Use: "total-index-size", | ||
Short: "Show total size of all indexes", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return total_index_size.Run(cmd.Context(), flags.DbConfig, afero.NewOsFs()) | ||
}, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better hide deprecated commands instead so it doesn't break existing users.
@@ -38,12 +38,12 @@ WITH constants AS ( | |||
JOIN pg_class c2 ON c2.oid = i.indexrelid | |||
) | |||
SELECT | |||
type, schemaname, object_name, bloat, pg_size_pretty(raw_waste) as waste | |||
type, name, bloat, pg_size_pretty(raw_waste) as waste | |||
FROM | |||
(SELECT | |||
'table' as type, | |||
schemaname, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this line seems redundant now
out, _ = filepath.Abs(out) | ||
// print the actual save location | ||
if !filepath.IsAbs(dateDir) { | ||
dateDir, _ = filepath.Abs(dateDir) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's throw the error instead of failing silently
array_to_string(rolconfig, ',', '*') as custom_config | ||
FROM | ||
pg_roles | ||
ORDER BY 3 DESC |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why order by connection_limit instead of role_name?
COALESCE(rc.seq_scans, 0) AS seq_scans | ||
FROM ( | ||
SELECT | ||
n.nspname || '.' || c.relname AS name, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
@@ -30,7 +29,7 @@ func Run(ctx context.Context, config pgconn.Config, fsys afero.Fs, options ...fu | |||
return err | |||
} | |||
defer conn.Close(context.Background()) | |||
rows, err := conn.Query(ctx, TotalTableSizesQuery, reset.LikeEscapeSchema(utils.PgSchemas)) | |||
rows, err := conn.Query(ctx, TotalTableSizesQuery, reset.LikeEscapeSchema(utils.InternalSchemas)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are we sure that users are not interested in the size of managed schemas, like auth.users
table for eg?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe for auth, yep. For others, less so because they are managed and should not be touched (so they may cause issues but nothing the user can resolve)
query = "SELECT LISTAGG(index, ',') AS match FROM `unused_indexes.csv`" | ||
pass = "✔" | ||
fail = "There is at least one unused index" | ||
name = "No unused indexes" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
query = "SELECT LISTAGG(index, ',') AS match FROM `unused_indexes.csv`" | |
pass = "✔" | |
fail = "There is at least one unused index" | |
name = "No unused indexes" | |
query = "SELECT LISTAGG(index, ',') AS match FROM `unused_indexes.csv`" | |
pass = "✔" | |
fail = "There is at least one unused index" | |
name = "No unused indexes" |
could use more consistent formatting
What kind of change does this PR introduce?
Feature
What is the current behavior?
Currently, inspect reports are quite modular and provide output where column titles can vary
What is the new behavior?
Refined queries to output in a similar format and reduced/combined work to minimise the number of output files produced (or commands needed)
Additional context
CSVQ has been added as a library to provide a table printout of some rules that are/are not met by the CSV files produced by
report